Skip to content

Commit

Permalink
Reset the count cache when applying a filter (#183)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksei Gagarin <roxblnfk@ya.ru>
  • Loading branch information
msmakouz and roxblnfk committed Jan 24, 2024
1 parent b23d5ed commit c40d9e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Data/Reader/EntityReader.php
Expand Up @@ -115,6 +115,7 @@ public function withFilter(FilterInterface $filter): static
$new->filter = $filter;
$new->itemsCache = new CachedCollection();
$new->oneItemCache = new CachedCollection();
$new->resetCountCache();
}
return $new;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Feature/Data/Reader/EntityReaderTest.php
Expand Up @@ -91,6 +91,18 @@ public function testCountWithLimit(): void
self::assertSame(count(self::FIXTURES_USER), $reader->count());
}

/**
* @covers ::count
*/
public function testCountWithFilter(): void
{
$this->fillFixtures();

$reader = (new EntityReader($this->select('user')))->withFilter(new Equals('id', 2));

self::assertSame(1, $reader->count());
}

/**
* @covers ::withLimit
*/
Expand Down

0 comments on commit c40d9e5

Please sign in to comment.