diff --git a/src/Database/Expression/QueryExpression.php b/src/Database/Expression/QueryExpression.php index f2e7e44eceb..cf8606edfc2 100644 --- a/src/Database/Expression/QueryExpression.php +++ b/src/Database/Expression/QueryExpression.php @@ -122,7 +122,7 @@ public function tieWith($conjunction = null) */ public function type($conjunction = null) { - return $this->setConjunction($conjunction); + return $this->tieWith($conjunction); } /** diff --git a/tests/TestCase/Database/Expression/QueryExpressionTest.php b/tests/TestCase/Database/Expression/QueryExpressionTest.php index 329431c37bd..d6bd88f3754 100644 --- a/tests/TestCase/Database/Expression/QueryExpressionTest.php +++ b/tests/TestCase/Database/Expression/QueryExpressionTest.php @@ -23,6 +23,57 @@ */ 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 *