diff options
Diffstat (limited to 'tests/unit/Data')
-rw-r--r-- | tests/unit/Data/SqlMap/AllTests.php | 60 | ||||
-rw-r--r-- | tests/unit/Data/SqlMap/DynamicParameterTest.php | 216 | ||||
-rw-r--r-- | tests/unit/Data/TDbDataReaderTest.php | 356 |
3 files changed, 316 insertions, 316 deletions
diff --git a/tests/unit/Data/SqlMap/AllTests.php b/tests/unit/Data/SqlMap/AllTests.php index 66f02608..2f820f83 100644 --- a/tests/unit/Data/SqlMap/AllTests.php +++ b/tests/unit/Data/SqlMap/AllTests.php @@ -1,30 +1,30 @@ -<?php
-require_once dirname(__FILE__).'/../../phpunit.php';
-
-if(!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Data_SqlMap_AllTests::main');
-}
-
-require_once 'DynamicParameterTest.php';
-require_once 'DataMapper/AllTests.php';
-
-class Data_SqlMap_AllTests {
-
- public static function main() {
- PHPUnit_TextUI_TestRunner::run(self::suite());
- }
-
- public static function suite() {
- $suite = new PHPUnit_Framework_TestSuite('System.Data.SqlMap');
-
- $suite->addTestSuite('DynamicParameterTest');
- $suite -> addTest( Data_SqlMap_DataMapper_AllTests::suite() );
-
- return $suite;
- }
-}
-
-if(PHPUnit_MAIN_METHOD == 'Data_SqlMap_AllTests::main') {
- Data_SqlMap_AllTests::main();
-}
-?>
+<?php +require_once dirname(__FILE__).'/../../phpunit.php'; + +if(!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Data_SqlMap_AllTests::main'); +} + +require_once 'DynamicParameterTest.php'; +require_once 'DataMapper/AllTests.php'; + +class Data_SqlMap_AllTests { + + public static function main() { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() { + $suite = new PHPUnit_Framework_TestSuite('System.Data.SqlMap'); + + $suite->addTestSuite('DynamicParameterTest'); + $suite -> addTest( Data_SqlMap_DataMapper_AllTests::suite() ); + + return $suite; + } +} + +if(PHPUnit_MAIN_METHOD == 'Data_SqlMap_AllTests::main') { + Data_SqlMap_AllTests::main(); +} +?> diff --git a/tests/unit/Data/SqlMap/DynamicParameterTest.php b/tests/unit/Data/SqlMap/DynamicParameterTest.php index f9b39b96..0bd5334e 100644 --- a/tests/unit/Data/SqlMap/DynamicParameterTest.php +++ b/tests/unit/Data/SqlMap/DynamicParameterTest.php @@ -1,109 +1,109 @@ -<?php
-require_once dirname(__FILE__).'/../../phpunit.php';
-
-Prado::using('System.Data.*');
-Prado::using('System.Data.SqlMap.*');
-
-/**
- * @package System.Data.SqlMap
- */
-class DynamicParameterTest extends PHPUnit_Framework_TestCase
-{
-
- protected function getMysqlSqlMapManager()
- {
- static $conn;
- static $sqlMapManager;
-
- if(Prado::getApplication() === null)
- Prado::setApplication(new TApplication(dirname(__FILE__).'/app'));
-
- if($conn === null)
- $conn = new TDbConnection('mysql:host=localhost;dbname=prado_system_data_sqlmap', 'prado_unitest', 'prado_system_data_sqlmap_unitest');
-
- $conn->setActive(true);
-
- if($sqlMapManager === null)
- {
- $sqlMapManager = new TSqlMapManager($conn);
- $sqlMapManager->configureXml( dirname(__FILE__) . '/DynamicParameterTestMap.xml');
- }
-
- return $sqlMapManager;
- }
-
- public function testMysqlSelectStaticSql()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $value = $gateway->queryForObject('SelectStaticSql1');
- self::assertEquals('staticsql1', $value);
-
- $value = $gateway->queryForObject('SelectStaticSql2');
- self::assertEquals('staticsql2', $value);
- }
-
- public function testMysqlSelectDynamicTable()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $value = $gateway->queryForObject('SelectDynamicTable', 'dynamicparametertest1');
- self::assertEquals('dynamictableparametertest1', $value);
-
- $value = $gateway->queryForObject('SelectDynamicTable', 'dynamicparametertest2');
- self::assertEquals('dynamictableparametertest2', $value);
- }
-
- public function testMysqlSelectDynamicComplex()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $aParams = array(
- 'tablename' => 'dynamicparametertest1',
- 'testname' => 'dynamictable'
- );
- $value = $gateway->queryForObject('SelectDynamicComplex', $aParams);
- self::assertEquals('#dynamictableparametertest1$', $value);
-
- $aParams = array(
- 'tablename' => 'dynamicparametertest2',
- 'testname' => 'dynamictable'
- );
- $value = $gateway->queryForObject('SelectDynamicComplex', $aParams);
- self::assertEquals('#dynamictableparametertest2$', $value);
- }
-
- public function testMysqlSelectNoDynamic()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $value = $gateway->queryForObject('SelectNoDynamic', 'dynamictable');
- self::assertEquals('dynamictableparametertest1', $value);
-
- $value = $gateway->queryForObject('SelectNoDynamic', 'staticsql');
- self::assertEquals('staticsql1', $value);
- }
-
- /**
- * Issue#209 test
- */
- public function testMysqlInlineEscapeParam()
- {
- $mapper = $this->getMysqlSqlMapManager();
- $gateway = $mapper->getSqlmapGateway();
-
- $value = $gateway->queryForObject('SelectInlineEscapeParam', "'1234567*123$456789$012345' AS foobar");
- self::assertEquals('1234567*123$456789$012345', $value);
-
- $value = $gateway->queryForObject('SelectInlineEscapeParam', '"1234567*123$456789$012345" AS foobar');
- self::assertEquals('1234567*123$456789$012345', $value);
-
- }
-
-}
-
+<?php +require_once dirname(__FILE__).'/../../phpunit.php'; + +Prado::using('System.Data.*'); +Prado::using('System.Data.SqlMap.*'); + +/** + * @package System.Data.SqlMap + */ +class DynamicParameterTest extends PHPUnit_Framework_TestCase +{ + + protected function getMysqlSqlMapManager() + { + static $conn; + static $sqlMapManager; + + if(Prado::getApplication() === null) + Prado::setApplication(new TApplication(dirname(__FILE__).'/app')); + + if($conn === null) + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_system_data_sqlmap', 'prado_unitest', 'prado_system_data_sqlmap_unitest'); + + $conn->setActive(true); + + if($sqlMapManager === null) + { + $sqlMapManager = new TSqlMapManager($conn); + $sqlMapManager->configureXml( dirname(__FILE__) . '/DynamicParameterTestMap.xml'); + } + + return $sqlMapManager; + } + + public function testMysqlSelectStaticSql() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $value = $gateway->queryForObject('SelectStaticSql1'); + self::assertEquals('staticsql1', $value); + + $value = $gateway->queryForObject('SelectStaticSql2'); + self::assertEquals('staticsql2', $value); + } + + public function testMysqlSelectDynamicTable() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $value = $gateway->queryForObject('SelectDynamicTable', 'dynamicparametertest1'); + self::assertEquals('dynamictableparametertest1', $value); + + $value = $gateway->queryForObject('SelectDynamicTable', 'dynamicparametertest2'); + self::assertEquals('dynamictableparametertest2', $value); + } + + public function testMysqlSelectDynamicComplex() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $aParams = array( + 'tablename' => 'dynamicparametertest1', + 'testname' => 'dynamictable' + ); + $value = $gateway->queryForObject('SelectDynamicComplex', $aParams); + self::assertEquals('#dynamictableparametertest1$', $value); + + $aParams = array( + 'tablename' => 'dynamicparametertest2', + 'testname' => 'dynamictable' + ); + $value = $gateway->queryForObject('SelectDynamicComplex', $aParams); + self::assertEquals('#dynamictableparametertest2$', $value); + } + + public function testMysqlSelectNoDynamic() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $value = $gateway->queryForObject('SelectNoDynamic', 'dynamictable'); + self::assertEquals('dynamictableparametertest1', $value); + + $value = $gateway->queryForObject('SelectNoDynamic', 'staticsql'); + self::assertEquals('staticsql1', $value); + } + + /** + * Issue#209 test + */ + public function testMysqlInlineEscapeParam() + { + $mapper = $this->getMysqlSqlMapManager(); + $gateway = $mapper->getSqlmapGateway(); + + $value = $gateway->queryForObject('SelectInlineEscapeParam', "'1234567*123$456789$012345' AS foobar"); + self::assertEquals('1234567*123$456789$012345', $value); + + $value = $gateway->queryForObject('SelectInlineEscapeParam', '"1234567*123$456789$012345" AS foobar'); + self::assertEquals('1234567*123$456789$012345', $value); + + } + +} + ?>
\ No newline at end of file diff --git a/tests/unit/Data/TDbDataReaderTest.php b/tests/unit/Data/TDbDataReaderTest.php index 68f9bfe8..9d61a330 100644 --- a/tests/unit/Data/TDbDataReaderTest.php +++ b/tests/unit/Data/TDbDataReaderTest.php @@ -1,179 +1,179 @@ -<?php
-
-require_once(dirname(__FILE__).'/../phpunit2.php');
-
-Prado::using('System.Data.*');
-
-define('TEST_DB_FILE',dirname(__FILE__).'/db/test.db');
-
-class FooRecord extends TComponent
-{
- public $id;
- private $_name;
- public $param;
-
- public function __construct($param)
- {
- $this->param=$param;
- }
-
- public function getName()
- {
- return $this->_name;
- }
-
- public function setName($value)
- {
- $this->_name=$value;
- }
-}
-
-/**
- * @package System.Data.PDO
- */
-class TDbDataReaderTest extends PHPUnit2_Framework_TestCase
-{
- private $_connection;
-
- public function setUp()
- {
- @unlink(TEST_DB_FILE);
- $this->_connection=new TDbConnection('sqlite:'.TEST_DB_FILE);
- $this->_connection->Active=true;
- $this->_connection->createCommand('CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(8))')->execute();
- $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name\')')->execute();
- $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name 2\')')->execute();
- }
-
- public function tearDown()
- {
- $this->_connection=null;
- }
-
- public function testRead()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $row=$reader->read();
- $this->assertTrue($row['id']==='1' && $row['name']==='my name');
- $row=$reader->read();
- $this->assertTrue($row['id']==='2' && $row['name']==='my name 2');
- $row=$reader->read();
- $this->assertFalse($row);
- }
-
- public function testReadColumn()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $this->assertEquals($reader->readColumn(0),'1');
- $this->assertEquals($reader->readColumn(1),'my name 2');
- $this->assertFalse($reader->readColumn(0));
- }
-
- public function testReadObject()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $object=$reader->readObject('FooRecord',array('object'));
- $this->assertEquals($object->id,'1');
- $this->assertEquals($object->Name,'my name');
- $this->assertEquals($object->param,'object');
- }
-
- public function testReadAll()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $rows=$reader->readAll();
- $this->assertEquals(count($rows),2);
- $row=$rows[0];
- $this->assertTrue($row['id']==='1' && $row['name']==='my name');
- $row=$rows[1];
- $this->assertTrue($row['id']==='2' && $row['name']==='my name 2');
-
- $reader=$this->_connection->createCommand('SELECT * FROM foo WHERE id=3')->query();
- $rows=$reader->readAll();
- $this->assertEquals($rows,array());
- }
-
- public function testClose()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $row=$reader->read();
- $this->assertFalse($reader->IsClosed);
- $reader->close();
- $this->assertTrue($reader->IsClosed);
- try
- {
- $reader->read();
- $this->fail('Expected exception is not raised');
- }
- catch(Exception $e)
- {
- }
- }
-
- public function testRowCount()
- {
- // unable to test because SQLite doesn't support row count
- }
-
- public function testColumnCount()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $this->assertEquals($reader->ColumnCount,2);
-
- $reader=$this->_connection->createCommand('SELECT * FROM foo WHERE id=11')->query();
- $this->assertEquals($reader->ColumnCount,2);
- }
-
- public function testForeach()
- {
- $ids=array();
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- foreach($reader as $row)
- $ids[]=$row['id'];
- $this->assertEquals(count($ids),2);
- $this->assertTrue($ids[0]==='1' && $ids[1]==='2');
-
- try
- {
- foreach($reader as $row)
- $ids[]=$row['id'];
- $this->fail('Expected exception is not raised');
- }
- catch(TDbException $e)
- {
- }
- }
-
- public function testFetchMode()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
-
- $reader->FetchMode=PDO::FETCH_NUM;
- $row=$reader->read();
- $this->assertFalse(isset($row['id']));
- $this->assertTrue(isset($row[0]));
-
- $reader->FetchMode=PDO::FETCH_ASSOC;
- $row=$reader->read();
- $this->assertTrue(isset($row['id']));
- $this->assertFalse(isset($row[0]));
- }
-
- public function testBindColumn()
- {
- $reader=$this->_connection->createCommand('SELECT * FROM foo')->query();
- $reader->bindColumn(1,$id);
- $reader->bindColumn(2,$name);
- $reader->read();
- $this->assertEquals($id,'1');
- $this->assertEquals($name,'my name');
- $reader->read();
- $this->assertEquals($id,'2');
- $this->assertEquals($name,'my name 2');
- $reader->read();
- $this->assertEquals($id,'2');
- $this->assertEquals($name,'my name 2');
- }
-}
-
+<?php + +require_once(dirname(__FILE__).'/../phpunit2.php'); + +Prado::using('System.Data.*'); + +define('TEST_DB_FILE',dirname(__FILE__).'/db/test.db'); + +class FooRecord extends TComponent +{ + public $id; + private $_name; + public $param; + + public function __construct($param) + { + $this->param=$param; + } + + public function getName() + { + return $this->_name; + } + + public function setName($value) + { + $this->_name=$value; + } +} + +/** + * @package System.Data.PDO + */ +class TDbDataReaderTest extends PHPUnit2_Framework_TestCase +{ + private $_connection; + + public function setUp() + { + @unlink(TEST_DB_FILE); + $this->_connection=new TDbConnection('sqlite:'.TEST_DB_FILE); + $this->_connection->Active=true; + $this->_connection->createCommand('CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(8))')->execute(); + $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name\')')->execute(); + $this->_connection->createCommand('INSERT INTO foo (name) VALUES (\'my name 2\')')->execute(); + } + + public function tearDown() + { + $this->_connection=null; + } + + public function testRead() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $row=$reader->read(); + $this->assertTrue($row['id']==='1' && $row['name']==='my name'); + $row=$reader->read(); + $this->assertTrue($row['id']==='2' && $row['name']==='my name 2'); + $row=$reader->read(); + $this->assertFalse($row); + } + + public function testReadColumn() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $this->assertEquals($reader->readColumn(0),'1'); + $this->assertEquals($reader->readColumn(1),'my name 2'); + $this->assertFalse($reader->readColumn(0)); + } + + public function testReadObject() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $object=$reader->readObject('FooRecord',array('object')); + $this->assertEquals($object->id,'1'); + $this->assertEquals($object->Name,'my name'); + $this->assertEquals($object->param,'object'); + } + + public function testReadAll() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $rows=$reader->readAll(); + $this->assertEquals(count($rows),2); + $row=$rows[0]; + $this->assertTrue($row['id']==='1' && $row['name']==='my name'); + $row=$rows[1]; + $this->assertTrue($row['id']==='2' && $row['name']==='my name 2'); + + $reader=$this->_connection->createCommand('SELECT * FROM foo WHERE id=3')->query(); + $rows=$reader->readAll(); + $this->assertEquals($rows,array()); + } + + public function testClose() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $row=$reader->read(); + $this->assertFalse($reader->IsClosed); + $reader->close(); + $this->assertTrue($reader->IsClosed); + try + { + $reader->read(); + $this->fail('Expected exception is not raised'); + } + catch(Exception $e) + { + } + } + + public function testRowCount() + { + // unable to test because SQLite doesn't support row count + } + + public function testColumnCount() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $this->assertEquals($reader->ColumnCount,2); + + $reader=$this->_connection->createCommand('SELECT * FROM foo WHERE id=11')->query(); + $this->assertEquals($reader->ColumnCount,2); + } + + public function testForeach() + { + $ids=array(); + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + foreach($reader as $row) + $ids[]=$row['id']; + $this->assertEquals(count($ids),2); + $this->assertTrue($ids[0]==='1' && $ids[1]==='2'); + + try + { + foreach($reader as $row) + $ids[]=$row['id']; + $this->fail('Expected exception is not raised'); + } + catch(TDbException $e) + { + } + } + + public function testFetchMode() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + + $reader->FetchMode=PDO::FETCH_NUM; + $row=$reader->read(); + $this->assertFalse(isset($row['id'])); + $this->assertTrue(isset($row[0])); + + $reader->FetchMode=PDO::FETCH_ASSOC; + $row=$reader->read(); + $this->assertTrue(isset($row['id'])); + $this->assertFalse(isset($row[0])); + } + + public function testBindColumn() + { + $reader=$this->_connection->createCommand('SELECT * FROM foo')->query(); + $reader->bindColumn(1,$id); + $reader->bindColumn(2,$name); + $reader->read(); + $this->assertEquals($id,'1'); + $this->assertEquals($name,'my name'); + $reader->read(); + $this->assertEquals($id,'2'); + $this->assertEquals($name,'my name 2'); + $reader->read(); + $this->assertEquals($id,'2'); + $this->assertEquals($name,'my name 2'); + } +} + ?>
\ No newline at end of file |