summaryrefslogtreecommitdiff
path: root/tests/unit/SQLMap/TAdodbConnectionTestCase.php
blob: 7d566386f6a9d14b3fe8a0713b5b340190206d29 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

require_once dirname(__FILE__).'/../phpunit2.php';

require_once(dirname(__FILE__).'/common.php');

/**
 * @package System.DataAccess
 */
class TAdodbConnectionTestCase extends PHPUnit2_Framework_TestCase
{
	protected $db_file;

	function setup()
	{
		$file = dirname(__FILE__).'/resources/data.db';
		$this->db_file = dirname(__FILE__).'/resources/test.db';
		copy($file,$this->db_file);
		$provider = new TAdodb();
	}

	function getDsn()
	{
		return 'sqlite://'.urlencode(realpath($this->db_file));
	}

	function testProviderCreation()
	{
		$provider = new TAdodb();
		$connection = $provider->getConnection();
		$this->assertTrue($connection instanceof TAdodbConnection);
		try
		{
			$connection->open();
			$this->fail();
		}
		catch (TDbConnectionException $e)
		{
			$this->pass();
		}
	}



	function testAdodbSqliteConnection()
	{
		$connection = new TAdodbConnection($this->getDsn());
		$this->assertTrue($connection->open());
	
		$statement = "insert into person(per_id, per_first_name,
			per_last_name, per_birth_date, per_weight_kg, per_height_m)
			values(?, ?, ?, ?, ?, ?)";
		$sql = $connection->prepare($statement);
		$connection->execute($sql, 
					array(2,'mini','me','2000-01-01', 50.5, 145.5));

		$statement = "select * from person";
		$results = $connection->execute($statement);
		$this->assertEquals($results->RecordCount(), 2);
	
	}
}

?>