Browse Source

Merge pull request #11040 from chinpei215/3.4-query-expression

Fix backward incompatibility of QueryExpression::type()
José Lorenzo Rodríguez 8 years ago
parent
commit
bf64092785

+ 1 - 1
src/Database/Expression/QueryExpression.php

@@ -122,7 +122,7 @@ class QueryExpression implements ExpressionInterface, Countable
      */
      */
     public function type($conjunction = null)
     public function type($conjunction = null)
     {
     {
-        return $this->setConjunction($conjunction);
+        return $this->tieWith($conjunction);
     }
     }
 
 
     /**
     /**

+ 51 - 0
tests/TestCase/Database/Expression/QueryExpressionTest.php

@@ -24,6 +24,57 @@ use Cake\TestSuite\TestCase;
 class QueryExpressionTest extends TestCase
 class QueryExpressionTest extends TestCase
 {
 {
     /**
     /**
+     * Test setConjunction()/getConjunction() works.
+     *
+     * @return
+     */
+    public function testConjunction()
+    {
+        $expr = new QueryExpression(['1', '2']);
+        $binder = new ValueBinder();
+
+        $this->assertSame($expr, $expr->setConjunction('+'));
+        $this->assertSame('+', $expr->getConjunction());
+
+        $result = $expr->sql($binder);
+        $this->assertEquals('(1 + 2)', $result);
+    }
+
+    /**
+     * Test tieWith() works.
+     *
+     * @return
+     */
+    public function testTieWith()
+    {
+        $expr = new QueryExpression(['1', '2']);
+        $binder = new ValueBinder();
+
+        $this->assertSame($expr, $expr->tieWith('+'));
+        $this->assertSame('+', $expr->tieWith());
+
+        $result = $expr->sql($binder);
+        $this->assertEquals('(1 + 2)', $result);
+    }
+
+    /**
+     * Test type() works.
+     *
+     * @return
+     */
+    public function testType()
+    {
+        $expr = new QueryExpression(['1', '2']);
+        $binder = new ValueBinder();
+
+        $this->assertSame($expr, $expr->type('+'));
+        $this->assertSame('+', $expr->type());
+
+        $result = $expr->sql($binder);
+        $this->assertEquals('(1 + 2)', $result);
+    }
+
+    /**
      * Test and() and or() calls work transparently
      * Test and() and or() calls work transparently
      *
      *
      * @return void
      * @return void