diff options
author | Michal Čihař <michal@cihar.com> | 2016-10-03 15:56:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-03 15:56:59 +0200 |
commit | 26087604100d9ce14bf441982180adc8ddbd8a47 (patch) | |
tree | edc1f119e71b4efc1d4ea38b860c544fc586cd19 /tests/Components/CaseExpressionTest.php | |
parent | c66456f7dcc953a6246d9a5c5fa27bf0efb11a65 (diff) | |
parent | f15156756cdbb8c00c4f1d22fb198e6e4403986d (diff) | |
download | sql-parser-26087604100d9ce14bf441982180adc8ddbd8a47.zip sql-parser-26087604100d9ce14bf441982180adc8ddbd8a47.tar.gz sql-parser-26087604100d9ce14bf441982180adc8ddbd8a47.tar.bz2 |
Merge pull request #88 from devenbansod/fix_pma_12100
Add parsing of CASE Expressions
Diffstat (limited to 'tests/Components/CaseExpressionTest.php')
-rw-r--r-- | tests/Components/CaseExpressionTest.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/Components/CaseExpressionTest.php b/tests/Components/CaseExpressionTest.php new file mode 100644 index 0000000..8746909 --- /dev/null +++ b/tests/Components/CaseExpressionTest.php @@ -0,0 +1,88 @@ +<?php + +namespace SqlParser\Tests\Components; + +use SqlParser\Parser; +use SqlParser\Components\CaseExpression; + +use SqlParser\Tests\TestCase; + +class CaseExpressionTest extends TestCase +{ + + public function testParseBuild() + { + $caseExprQuery = 'case 1 when 1 then "Some" else "Other" end'; + $component = CaseExpression::parse( + new Parser(), + $this->getTokensList($caseExprQuery)); + $this->assertEquals( + CaseExpression::build($component), + 'CASE 1 WHEN 1 THEN "Some" ELSE "Other" END' + ); + } + + public function testParseBuild2() + { + $caseExprQuery = 'case when 1=1 then "India" else "Other" end'; + $component = CaseExpression::parse( + new Parser(), + $this->getTokensList($caseExprQuery)); + $this->assertEquals( + CaseExpression::build($component), + 'CASE WHEN 1=1 THEN "India" ELSE "Other" END' + ); + } + + public function testParseBuild3() + { + $caseExprQuery = 'case 1 when 1 then "Some" ' + . 'when 2 then "SomeOther" else "Other" end'; + $component = CaseExpression::parse( + new Parser(), + $this->getTokensList($caseExprQuery)); + $this->assertEquals( + CaseExpression::build($component), + 'CASE 1 WHEN 1 THEN "Some" WHEN 2 THEN "SomeOther" ELSE "Other" END' + ); + } + + public function testParseBuild4() + { + $caseExprQuery = 'case 1 when 1 then "Some" ' + . 'when 2 then "SomeOther" end'; + $component = CaseExpression::parse( + new Parser(), + $this->getTokensList($caseExprQuery)); + $this->assertEquals( + CaseExpression::build($component), + 'CASE 1 WHEN 1 THEN "Some" WHEN 2 THEN "SomeOther" END' + ); + } + + public function testParseBuild5() + { + $caseExprQuery = 'case when 1=1 then "Some" ' + . 'when 1=2 then "SomeOther" else "Other" end'; + $component = CaseExpression::parse( + new Parser(), + $this->getTokensList($caseExprQuery)); + $this->assertEquals( + CaseExpression::build($component), + 'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" ELSE "Other" END' + ); + } + + public function testParseBuild6() + { + $caseExprQuery = 'case when 1=1 then "Some" ' + . 'when 1=2 then "SomeOther" end'; + $component = CaseExpression::parse( + new Parser(), + $this->getTokensList($caseExprQuery)); + $this->assertEquals( + CaseExpression::build($component), + 'CASE WHEN 1=1 THEN "Some" WHEN 1=2 THEN "SomeOther" END' + ); + } +} |