summaryrefslogtreecommitdiffstats
path: root/tests/Components
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Components')
-rw-r--r--tests/Components/CaseExpressionTest.php88
-rw-r--r--tests/Components/LimitTest.php4
2 files changed, 90 insertions, 2 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'
+ );
+ }
+}
diff --git a/tests/Components/LimitTest.php b/tests/Components/LimitTest.php
index bc5a462..15c665a 100644
--- a/tests/Components/LimitTest.php
+++ b/tests/Components/LimitTest.php
@@ -10,10 +10,10 @@ use SqlParser\Tests\TestCase;
class LimitTest extends TestCase
{
- public function testBuild()
+ public function testBuildWithoutOffset()
{
$component = new Limit(1);
- $this->assertEquals(Limit::build($component), '1');
+ $this->assertEquals(Limit::build($component), '0, 1');
}
public function testBuildWithOffset()