Commit dd79325a by Ivan Pomortsev

Update QueryBuilderTest.php

Add test for UNION/UNION ALL function. It could be useful to use "phpunit --group=db --filter testBuildUnion" command for run it.
parent 7da3449d
...@@ -215,4 +215,30 @@ class QueryBuilderTest extends DatabaseTestCase ...@@ -215,4 +215,30 @@ class QueryBuilderTest extends DatabaseTestCase
$this->assertEquals($expectedQueryParams, $queryParams); $this->assertEquals($expectedQueryParams, $queryParams);
} }
*/ */
/*
This test contains three select queries connected with UNION and UNION ALL constructions.
It could be useful to use "phpunit --group=db --filter testBuildUnion" command for run it.
*/
public function testBuildUnion()
{
$expectedQuerySql = "SELECT `id` FROM `TotalExample` `t1` WHERE (w > 0) AND (x < 2) UNION ( SELECT `id` FROM `TotalTotalExample` `t2` WHERE w > 5 ) UNION ALL ( SELECT `id` FROM `TotalTotalExample` `t3` WHERE w = 3 )";
$query = new Query();
$secondQuery = new Query();
$secondQuery->select('id')
->from('TotalTotalExample t2')
->where('w > 5');
$thirdQuery = new Query();
$thirdQuery->select('id')
->from('TotalTotalExample t3')
->where('w = 3');
$query->select('id')
->from('TotalExample t1')
->where(['and', 'w > 0', 'x < 2'])
->union($secondQuery)
->union($thirdQuery, TRUE);
list($actualQuerySql, $queryParams) = $this->getQueryBuilder()->build($query);
$this->assertEquals($expectedQuerySql, $actualQuerySql);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment