From 33c3937adce276d1bad6f92201f39da5ed78c1fd Mon Sep 17 00:00:00 2001 From: Sebastien Bariteau Date: Tue, 16 Apr 2013 14:08:40 +0100 Subject: Add support for T-SQL style TOP clauses --- test/CacheTest.php | 8 ++------ test/ConfigTest.php | 6 ++---- test/IdiormResultSetTest.php | 4 ++-- test/MulitpleConnectionTest.php | 6 ++---- test/ORMTest.php | 4 ++-- test/QueryBuilderMssqlTest.php | 32 ++++++++++++++++++++++++++++++++ test/QueryBuilderTest.php | 4 ++-- test/bootstrap.php | 22 +++++++++++++++++++++- 8 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 test/QueryBuilderMssqlTest.php (limited to 'test') diff --git a/test/CacheTest.php b/test/CacheTest.php index 8479d13..0f7b491 100644 --- a/test/CacheTest.php +++ b/test/CacheTest.php @@ -17,12 +17,8 @@ class CacheTest extends PHPUnit_Framework_TestCase { } public function tearDown() { - ORM::configure('logging', false); - ORM::configure('logging', false, self::ALTERNATE); - ORM::configure('caching', false); - ORM::configure('caching', false, self::ALTERNATE); - ORM::set_db(null); - ORM::set_db(null, self::ALTERNATE); + ORM::reset_config(); + ORM::reset_db(); } // Test caching. This is a bit of a hack. diff --git a/test/ConfigTest.php b/test/ConfigTest.php index 83194b4..787e2b1 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -14,10 +14,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { } public function tearDown() { - ORM::configure('logging', false); - ORM::set_db(null); - - ORM::configure('id_column', 'id'); + ORM::reset_config(); + ORM::reset_db(); } protected function setUpIdColumnOverrides() { diff --git a/test/IdiormResultSetTest.php b/test/IdiormResultSetTest.php index f41205a..c458d99 100644 --- a/test/IdiormResultSetTest.php +++ b/test/IdiormResultSetTest.php @@ -12,8 +12,8 @@ class IdiormResultSetTest extends PHPUnit_Framework_TestCase { } public function tearDown() { - ORM::configure('logging', false); - ORM::set_db(null); + ORM::reset_config(); + ORM::reset_db(); } public function testGet() { diff --git a/test/MulitpleConnectionTest.php b/test/MulitpleConnectionTest.php index 9df05d0..a58f3ca 100644 --- a/test/MulitpleConnectionTest.php +++ b/test/MulitpleConnectionTest.php @@ -15,10 +15,8 @@ class MultipleConnectionTest extends PHPUnit_Framework_TestCase { } public function tearDown() { - ORM::configure('logging', false); - ORM::configure('logging', false, self::ALTERNATE); - ORM::set_db(null); - ORM::set_db(null, self::ALTERNATE); + ORM::reset_config(); + ORM::reset_db(); } public function testMultiplePdoConnections() { diff --git a/test/ORMTest.php b/test/ORMTest.php index ced3cbd..ebd3d17 100644 --- a/test/ORMTest.php +++ b/test/ORMTest.php @@ -12,8 +12,8 @@ class ORMTest extends PHPUnit_Framework_TestCase { } public function tearDown() { - ORM::configure('logging', false); - ORM::set_db(null); + ORM::reset_config(); + ORM::reset_db(); } public function testStaticAtrributes() { diff --git a/test/QueryBuilderMssqlTest.php b/test/QueryBuilderMssqlTest.php new file mode 100644 index 0000000..be67b33 --- /dev/null +++ b/test/QueryBuilderMssqlTest.php @@ -0,0 +1,32 @@ +find_one(); + $expected = 'SELECT TOP 1 * FROM "widget"'; + $this->assertEquals($expected, ORM::get_last_query()); + } + + public function testLimit() { + ORM::for_table('widget')->limit(5)->find_many(); + $expected = 'SELECT TOP 5 * FROM "widget"'; + $this->assertEquals($expected, ORM::get_last_query()); + } + +} + diff --git a/test/QueryBuilderTest.php b/test/QueryBuilderTest.php index bd888c0..09390a5 100644 --- a/test/QueryBuilderTest.php +++ b/test/QueryBuilderTest.php @@ -12,8 +12,8 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase { } public function tearDown() { - ORM::configure('logging', false); - ORM::set_db(null); + ORM::reset_config(); + ORM::reset_db(); } public function testFindMany() { diff --git a/test/bootstrap.php b/test/bootstrap.php index ec13cc7..12e9ca0 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -35,7 +35,7 @@ class MockDifferentPDOStatement extends MockPDOStatement { } * */ class MockPDO extends PDO { - + /** * Return a dummy PDO statement */ @@ -59,3 +59,23 @@ class MockDifferentPDO extends MockPDO { return $this->last_query; } } + +class MockMsSqlPDO extends MockPDO { + + public $fake_driver = 'mssql'; + + /** + * If we are asking for the name of the driver, check if a fake one + * has been set. + */ + public function getAttribute($attribute) { + if ($attribute == self::ATTR_DRIVER_NAME) { + if (!is_null($this->fake_driver)) { + return $this->fake_driver; + } + } + + return parent::getAttribute($attribute); + } + +} \ No newline at end of file -- cgit v1.2.3