summaryrefslogtreecommitdiff
path: root/demos/time-tracker/tests/unit/BaseTestCase.php
blob: 8ce3cca870e574438e6ae192a009cb2cfcdc268c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
		}
	}
}
?>