Skip to content
Browse files

Bugfix for join equality when default join type is used

$j1 = new Join('foo', 'bar');
$j2 = new Join('foo', 'bar', 'INNER JOIN');
$this->assertTrue($j1->equals($j2));
  • Loading branch information...
1 parent 9e8e176 commit dcace442d4dc0302f2db568b0550af73a53532ad @arvenil committed
Showing with 24 additions and 3 deletions.
  1. +2 −3 runtime/lib/query/Join.php
  2. +22 −0 test/testsuite/runtime/query/JoinTest.php
View
5 runtime/lib/query/Join.php
@@ -226,8 +226,7 @@ public function setJoinType($joinType = null)
/**
* Get the join type
*
- * @return string The type of the join, i.e. Criteria::LEFT_JOIN(), ...,
- * or null for adding the join condition to the where Clause
+ * @return string The type of the join, i.e. Criteria::LEFT_JOIN()
*/
public function getJoinType()
{
@@ -548,7 +547,7 @@ public function equals($join)
{
return $join !== null
&& $join instanceof Join
- && $this->joinType == $join->getJoinType()
+ && $this->getJoinType() == $join->getJoinType()
&& $this->getConditions() == $join->getConditions();
}
View
22 test/testsuite/runtime/query/JoinTest.php
@@ -165,6 +165,28 @@ public function testCompositeeConstructor()
$this->assertEquals('LEFT JOIN', $j->getJoinType());
}
+ public function testEquality() {
+ $j1 = new Join('foo', 'bar', 'INNER JOIN');
+
+ $j2 = new Join('foo', 'bar', 'INNER JOIN');
+ $this->assertTrue($j1->equals($j2));
+
+ $j3 = new Join('foo', 'bar', 'LEFT JOIN');
+ $this->assertFalse($j1->equals($j3), 'INNER JOIN is not equal to LEFT JOIN');
+
+ $j4 = new Join('foo', 'bar', 'RIGHT JOIN');
+ $this->assertFalse($j1->equals($j4), 'INNER JOIN is not equal to RIGHT JOIN');
+
+ $j5 = new Join('foo', 'bar');
+ $j6 = new Join('foo', 'bar');
+ $this->assertTrue($j5->equals($j6), 'Joins without specified join type should be equal,
+ as they fallback to default join type');
+
+ $j7 = new Join('foo', 'bar', 'INNER JOIN');
+ $this->assertTrue($j5->equals($j7), 'Join without specified join type should be equal
+ to INNER JOIN, as it fallback to default join type');
+ }
+
public function testCountConditions()
{
$j = new Join();

0 comments on commit dcace44

Please sign in to comment.
Something went wrong with that request. Please try again.