Browse Source

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.
tags/2.0.0-beta
Ivan Pomortsev 11 years ago
parent
commit
dd79325a0a
  1. 26
      tests/unit/framework/db/QueryBuilderTest.php

26
tests/unit/framework/db/QueryBuilderTest.php

@ -215,4 +215,30 @@ class QueryBuilderTest extends DatabaseTestCase
$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);
}
}

Loading…
Cancel
Save