-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathCaseWhenExpressionDBTest.class.php
More file actions
42 lines (37 loc) · 1.41 KB
/
CaseWhenExpressionDBTest.class.php
File metadata and controls
42 lines (37 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
class CaseWhenExpressionDBTest extends TestCaseDAO
{
/**
* @group caseWhen
*/
public function testCaseWhenExpression()
{
$dialect = $this->getDbByType('PgSQL')->getDialect();
$beautifulNameExpr = CaseWhenExpression::create(
Expression::isTrue('capital'),
SQLFunction::create('upper', 'name'),
SQLFunction::create('lower', 'name')
)
->addCase(Expression::eq('name', 'St. Peterburg'), 'ST. PETERBURG');
$orderExpr = CaseWhenExpression::create()
->addCase(Expression::isTrue('capital'), SQLFunction::create('upper', 'name'))
->addCase(Expression::eq('name', 'St. Peterburg'), 'ST. PETERBURG')
->addElse('name');
$criteria = Criteria::create(TestCity::dao())
->addProjection(Projection::property($beautifulNameExpr, 'beautifulName'))
->addOrder($orderExpr);
$expectation = 'SELECT CASE '
.'WHEN ("custom_table"."capital" IS TRUE) THEN upper("custom_table"."name") '
.'WHEN ("custom_table"."name" = \'St. Peterburg\') THEN \'ST. PETERBURG\' '
.'ELSE lower("custom_table"."name") '
.'END AS "beautifulName" '
.'FROM "custom_table" '
.'ORDER BY CASE '
.'WHEN ("custom_table"."capital" IS TRUE) THEN upper("custom_table"."name") '
.'WHEN ("custom_table"."name" = \'St. Peterburg\') THEN \'ST. PETERBURG\' '
.'ELSE "custom_table"."name" '
.'END';
$this->assertEquals($expectation, $criteria->toDialectString($dialect));
}
}
?>