Skip to content

Commit

Permalink
Fix null handling of EqFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
codeliner committed Jul 11, 2018
1 parent bfb8f30 commit 3a3f38e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Persistence/DocumentStore/Filter/EqFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function match(array $doc): bool

$prop = $reader->mixedValue($this->prop, self::NOT_SET_PROPERTY);

if ($prop === self::NOT_SET_PROPERTY) {
return false;
if ($prop === self::NOT_SET_PROPERTY && $this->val === null) {
return $reader->pathExists($this->prop);
}

return $prop === $this->val;
Expand Down
4 changes: 1 addition & 3 deletions src/Persistence/DocumentStore/Filter/ExistsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public function match(array $doc): bool
{
$reader = new ArrayReader($doc);

$prop = $reader->mixedValue($this->prop, self::NOT_SET_PROPERTY);

return $prop !== self::NOT_SET_PROPERTY;
return $reader->pathExists($this->prop);
}
}
14 changes: 14 additions & 0 deletions tests/Persistence/DocumentStore/Filter/EqFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ public function it_filters_docs_with_eq_filter()

$this->assertEquals('Quak', implode(', ', $names));
}

/**
* @test
*/
public function it_filters_docs_with_eq_null_filter()
{
$this->loadFixtures();

$animals = $this->store->filterDocs($this->collection, new EqFilter('race', null));

$names = iterator_to_array($this->extractFieldIntoList('name', $animals));

$this->assertEquals('Quak', implode(', ', $names));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function it_filters_docs_with_exists_filter()

$names = iterator_to_array($this->extractFieldIntoList('name', $animals));

$this->assertEquals('Hasso', implode(', ', $names));
$this->assertEquals('Hasso, Quak', implode(', ', $names));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private function loadFixtures()
'name' => 'Quak',
'animal' => 'duck',
'age' => 1,
'race' => null,
]);
}
}

0 comments on commit 3a3f38e

Please sign in to comment.