diff --git a/src/QueryExpressionFilter.php b/src/QueryExpressionFilter.php index 07b803a..7dd3f6b 100644 --- a/src/QueryExpressionFilter.php +++ b/src/QueryExpressionFilter.php @@ -124,21 +124,25 @@ private function matchValue($data, $column, $expectation) return $this->matchComparator($data, $column, $expectation); } - $expectedValue = $expectation; - $comparator = '$is'; - - if ($this->isVector($expectedValue)) { - // list of possible values - $comparator = '$in'; - } elseif ($this->isObject($expectedValue)) { - // custom comparator ('>', '<', ...) - $comparator = key($expectedValue); - $expectedValue = reset($expectedValue); + if ($this->isVector($expectation)) { + // L2 simple list matching + $expectation = array('$in' => $expectation); + } elseif (!$this->isObject($expectation)) { + // L2 simple scalar matching + $expectation = array('$is' => $expectation); } $actualValue = $this->fetchValue($data, $column); - return $this->matchComparator($actualValue, $comparator, $expectedValue); + foreach ($expectation as $comparator => $expectedValue) { + $ret = $this->matchComparator($actualValue, $comparator, $expectedValue); + + if (!$ret) { + return false; + } + } + + return true; } private function fetchValue($data, $column) diff --git a/tests/QueryExpressionFilterTest.php b/tests/QueryExpressionFilterTest.php index 75755c8..cc3bbda 100644 --- a/tests/QueryExpressionFilterTest.php +++ b/tests/QueryExpressionFilterTest.php @@ -470,6 +470,21 @@ public function testRootMatchingContainsArray() ))); } + public function testMultipleOperators() + { + $filter = new QueryExpressionFilter(array( + 'id' => array( + '$gte' => 100, + '$lt' => 200 + ) + )); + + $this->assertFalse($filter->doesMatch(array('id' => 99))); + $this->assertTrue($filter->doesMatch(array('id' => 100))); + $this->assertTrue($filter->doesMatch(array('id' => 199))); + $this->assertFalse($filter->doesMatch(array('id' => 200))); + } + /** * @expectedException DomainException */