diff options
author | Igor Moiseev <[email protected]> | 2014-01-20 19:42:37 +0100 |
---|---|---|
committer | Simon Holywell <[email protected]> | 2014-04-26 13:45:46 +0100 |
commit | fd1fa806cf5ce18d0a6dcc4f8fb1bafb4a8005c7 (patch) | |
tree | 4c5e5d51dd4d50a129ce44dca159a95cc0af2be0 /test | |
parent | 7f8aa93e682afeeb0370fced694fcddd592f27f6 (diff) |
1. Adjustment of code to work with multiple raw_joins 2. Test multiple raw joins
Diffstat (limited to 'test')
-rw-r--r-- | test/QueryBuilderPsr1Test53.php | 10 | ||||
-rw-r--r-- | test/QueryBuilderTest.php | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/test/QueryBuilderPsr1Test53.php b/test/QueryBuilderPsr1Test53.php index 88c5a07..0aa8930 100644 --- a/test/QueryBuilderPsr1Test53.php +++ b/test/QueryBuilderPsr1Test53.php @@ -397,6 +397,16 @@ class QueryBuilderPsr1Test53 extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, ORM::getLastQuery()); } + public function testRawJoinAndRawWhereWithParameters() { + ORM::forTable('widget') + ->rawJoin('INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE ? AND `widget_handle`.category = ?)', array('widget_handle.widget_id', '=', 'widget.id'), 'widget_handle', array('%button%', 2)) + ->rawJoin('INNER JOIN ( SELECT * FROM `person` WHERE `person`.name LIKE ?)', array('person.id', '=', 'widget.person_id'), 'person', array('%Fred%')) + ->whereRaw('`id` > ? AND `id` < ?', array(5, 10)) + ->findMany(); + $expected = "SELECT * FROM `widget` INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE '%button%' AND `widget_handle`.category = '2') `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id` INNER JOIN ( SELECT * FROM `person` WHERE `person`.name LIKE '%Fred%') `person` ON `person`.`id` = `widget`.`person_id` WHERE `id` > '5' AND `id` < '10'"; + $this->assertEquals($expected, ORM::getLastQuery()); + } + public function testSelectWithDistinct() { ORM::forTable('widget')->distinct()->select('name')->findMany(); $expected = "SELECT DISTINCT `name` FROM `widget`"; diff --git a/test/QueryBuilderTest.php b/test/QueryBuilderTest.php index fc5b45e..3a4a997 100644 --- a/test/QueryBuilderTest.php +++ b/test/QueryBuilderTest.php @@ -397,6 +397,16 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, ORM::get_last_query()); } + public function testRawJoinAndRawWhereWithParameters() { + ORM::for_table('widget') + ->raw_join('INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE ? AND `widget_handle`.category = ?)', array('widget_handle.widget_id', '=', 'widget.id'), 'widget_handle', array('%button%', 2)) + ->raw_join('INNER JOIN ( SELECT * FROM `person` WHERE `person`.name LIKE ?)', array('person.id', '=', 'widget.person_id'), 'person', array('%Fred%')) + ->where_raw('`id` > ? AND `id` < ?', array(5, 10)) + ->find_many(); + $expected = "SELECT * FROM `widget` INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE '%button%' AND `widget_handle`.category = '2') `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id` INNER JOIN ( SELECT * FROM `person` WHERE `person`.name LIKE '%Fred%') `person` ON `person`.`id` = `widget`.`person_id` WHERE `id` > '5' AND `id` < '10'"; + $this->assertEquals($expected, ORM::get_last_query()); + } + public function testSelectWithDistinct() { ORM::for_table('widget')->distinct()->select('name')->find_many(); $expected = "SELECT DISTINCT `name` FROM `widget`"; |