diff options
author | Simon Holywell <[email protected]> | 2013-08-28 16:59:21 +0100 |
---|---|---|
committer | Simon Holywell <[email protected]> | 2013-08-28 17:02:49 +0100 |
commit | baff6edcb568c829bc2f82754f023f317d4fd759 (patch) | |
tree | 0c71cffedbac44c7caf20afbd2a1b020ff388d17 /test | |
parent | 4e9f8928cfc1e72f2d2f7ded3c7187255e400255 (diff) | |
parent | 33c3937adce276d1bad6f92201f39da5ed78c1fd (diff) |
Add MS SQL `TOP` style syntax support
Diffstat (limited to 'test')
-rw-r--r-- | test/CacheTest.php | 8 | ||||
-rw-r--r-- | test/ConfigTest.php | 7 | ||||
-rw-r--r-- | test/IdiormResultSetTest.php | 4 | ||||
-rw-r--r-- | test/MulitpleConnectionTest.php | 6 | ||||
-rw-r--r-- | test/ORMTest.php | 4 | ||||
-rw-r--r-- | test/QueryBuilderMssqlTest.php | 32 | ||||
-rw-r--r-- | test/QueryBuilderTest.php | 4 | ||||
-rw-r--r-- | test/bootstrap.php | 22 |
8 files changed, 66 insertions, 21 deletions
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 7644181..c65c539 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() { @@ -118,6 +116,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase { 'logger' => null, 'caching' => false, 'return_result_sets' => false, + 'limit_clause_style' => 'limit', ); $this->assertEquals($expected, ORM::get_config()); } 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 @@ +<?php + +class QueryBuilderMssqlTest extends PHPUnit_Framework_TestCase { + + public function setUp() { + // Enable logging + ORM::configure('logging', true); + + // Set up the dummy database connection + $db = new MockMsSqlPDO('sqlite::memory:'); + ORM::set_db($db); + } + + public function tearDown() { + ORM::reset_config(); + ORM::reset_db(); + } + + public function testFindOne() { + ORM::for_table('widget')->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 6da0997..590f5e2 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 03ad785..41d9026 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -38,7 +38,7 @@ class MockDifferentPDOStatement extends MockPDOStatement { } * */ class MockPDO extends PDO { - + /** * Return a dummy PDO statement */ @@ -62,3 +62,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); + } + +} |