summaryrefslogtreecommitdiff
path: root/demos/time-tracker/tests/unit/BaseTestCase.php
diff options
context:
space:
mode:
Diffstat (limited to 'demos/time-tracker/tests/unit/BaseTestCase.php')
-rw-r--r--demos/time-tracker/tests/unit/BaseTestCase.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/demos/time-tracker/tests/unit/BaseTestCase.php b/demos/time-tracker/tests/unit/BaseTestCase.php
new file mode 100644
index 00000000..8ce3cca8
--- /dev/null
+++ b/demos/time-tracker/tests/unit/BaseTestCase.php
@@ -0,0 +1,35 @@
+<?php
+
+class BaseTestCase extends UnitTestCase
+{
+ protected $sqlmap;
+
+ function setup()
+ {
+ $app = Prado::getApplication();
+ $this->sqlmap = $app->getModule('daos')->getConnection();
+ }
+
+ function flushDatabase()
+ {
+ $conn = $this->sqlmap->openConnection();
+ $file = Prado::getPathOfNamespace('Application.App_Data.mysql-reset','.sql');
+ if(is_file($file))
+ $this->runScript($conn, $file);
+ else
+ throw new Exception('unable to find script file '.$file);
+ }
+
+ protected function runScript($connection, $script)
+ {
+ $sql = file_get_contents($script);
+ $lines = explode(';', $sql);
+ foreach($lines as $line)
+ {
+ $line = trim($line);
+ if(strlen($line) > 0)
+ $connection->execute($line);
+ }
+ }
+}
+?> \ No newline at end of file