Skip to content

Commit

Permalink
Merge branch 'fix/#97-use-strict-comparison-in-expression-visitor'
Browse files Browse the repository at this point in the history
Close #97
e commit.
  • Loading branch information
Ocramius committed Jul 22, 2017
2 parents fafd879 + 310f54c commit a01ee38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ public function walkComparison(Comparison $comparison)

case Comparison::IN:
return function ($object) use ($field, $value) : bool {
return in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
return in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value, true);
};

case Comparison::NIN:
return function ($object) use ($field, $value) : bool {
return ! in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value);
return ! in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value, true);
};

case Comparison::CONTAINS:
Expand All @@ -179,7 +179,7 @@ public function walkComparison(Comparison $comparison)
if (!is_array($fieldValues)) {
$fieldValues = iterator_to_array($fieldValues);
}
return in_array($value, $fieldValues);
return in_array($value, $fieldValues, true);
};

case Comparison::STARTS_WITH:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,24 @@ public function testWalkGreaterThanComparison() : void

public function testWalkInComparison() : void
{
$closure = $this->visitor->walkComparison($this->builder->in("foo", [1, 2, 3]));
$closure = $this->visitor->walkComparison($this->builder->in("foo", [1, 2, 3, '04']));

$this->assertTrue($closure(new TestObject(2)));
$this->assertTrue($closure(new TestObject(1)));
$this->assertFalse($closure(new TestObject(0)));
$this->assertFalse($closure(new TestObject(4)));
$this->assertTrue($closure(new TestObject('04')));
}

public function testWalkNotInComparison() : void
{
$closure = $this->visitor->walkComparison($this->builder->notIn("foo", [1, 2, 3]));
$closure = $this->visitor->walkComparison($this->builder->notIn("foo", [1, 2, 3, '04']));

$this->assertFalse($closure(new TestObject(1)));
$this->assertFalse($closure(new TestObject(2)));
$this->assertTrue($closure(new TestObject(0)));
$this->assertTrue($closure(new TestObject(4)));
$this->assertFalse($closure(new TestObject('04')));
}

public function testWalkContainsComparison() : void
Expand All @@ -178,6 +181,7 @@ public function testWalkMemberOfComparisonWithObject() : void
$this->assertTrue($closure(new TestObject([1,2,3])));
$this->assertTrue($closure(new TestObject([2])));
$this->assertFalse($closure(new TestObject([1,3,5])));
$this->assertFalse($closure(new TestObject(array(1,'02'))));
}

public function testWalkStartsWithComparison() : void
Expand Down

0 comments on commit a01ee38

Please sign in to comment.