Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Thavarshan committed Apr 10, 2024
1 parent bf0172a commit 4a5fb11
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":1,"defects":{"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectly":8,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenDisabled":7,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForced":7,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForcedWithCustomTtl":7,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForcedWithCustomKey":8,"Filterable\\Tests\\FilterTest::testAppliesPreFiltersCorrectly":8,"Filterable\\Tests\\FilterableTest::testFilter":8,"Filterable\\Tests\\FilterableTest::testFilterAppliesFiltersToModelQuery":8,"Filterable\\Tests\\FilterableTest::testFilterThrowsExceptionWhenFilterApplicationFails":8,"Filterable\\Tests\\FilterTest::testClearsCacheCorrectly":5},"times":{"Filterable\\Tests\\FilterTest::testAppliesFiltersDynamicallyBasedOnRequest":0.029,"Filterable\\Tests\\FilterTest::testAppliesFiltersDynamicallyBasedOnRequestWithCustomMethodNames":0.018,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectly":0.017,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenDisabled":0.017,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForced":0.017,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForcedWithCustomTtl":0.017,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForcedWithCustomKey":0.017,"Filterable\\Tests\\FilterTest::testClearsCacheCorrectly":0.015,"Filterable\\Tests\\FilterTest::testAppliesPreFiltersCorrectly":0.017,"Filterable\\Tests\\FilterTest::testSetsAndGetsOptionsCorrectly":0.014,"Filterable\\Tests\\FilterableTest::testFilter":0.061,"Filterable\\Tests\\FilterableTest::testFilterAppliesFiltersToModelQuery":0.05,"Filterable\\Tests\\FilterableTest::testFilterThrowsExceptionWhenFilterApplicationFails":0.015}}
{"version":1,"defects":{"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectly":8,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenDisabled":7,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForced":7,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForcedWithCustomTtl":7,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForcedWithCustomKey":8,"Filterable\\Tests\\FilterTest::testAppliesPreFiltersCorrectly":8,"Filterable\\Tests\\FilterableTest::testFilter":8,"Filterable\\Tests\\FilterableTest::testFilterAppliesFiltersToModelQuery":8,"Filterable\\Tests\\FilterableTest::testFilterThrowsExceptionWhenFilterApplicationFails":8,"Filterable\\Tests\\FilterTest::testClearsCacheCorrectly":5,"Filterable\\Tests\\FilterTest::testAppliesFiltersDynamicallyBasedOnRequest":7,"Filterable\\Tests\\FilterTest::testAppliesFiltersDynamicallyBasedOnRequestWithCustomMethodNames":7},"times":{"Filterable\\Tests\\FilterTest::testAppliesFiltersDynamicallyBasedOnRequest":0.03,"Filterable\\Tests\\FilterTest::testAppliesFiltersDynamicallyBasedOnRequestWithCustomMethodNames":0.019,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectly":0.017,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenDisabled":0.019,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForced":0.018,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForcedWithCustomTtl":0.018,"Filterable\\Tests\\FilterTest::testHandlesCachingCorrectlyWhenForcedWithCustomKey":0.017,"Filterable\\Tests\\FilterTest::testClearsCacheCorrectly":0.016,"Filterable\\Tests\\FilterTest::testAppliesPreFiltersCorrectly":0.018,"Filterable\\Tests\\FilterTest::testSetsAndGetsOptionsCorrectly":0.015,"Filterable\\Tests\\FilterableTest::testFilter":0.061,"Filterable\\Tests\\FilterableTest::testFilterAppliesFiltersToModelQuery":0.053,"Filterable\\Tests\\FilterableTest::testFilterThrowsExceptionWhenFilterApplicationFails":0.015}}
2 changes: 1 addition & 1 deletion src/Filterable/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function () {
protected function applyFiltersToQuery(): void
{
collect($this->getFilterables())
->filter(fn (mixed $value) => (! is_string($value) && ! is_null($value))
->filter(fn (mixed $value) => $value !== null
&& $value !== ''
&& $value !== false
&& $value !== [])
Expand Down
5 changes: 3 additions & 2 deletions tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testAppliesFiltersDynamicallyBasedOnRequest(): void
$builder = $model->newQuery();

$cache = m::mock(Repository::class);
$cache->shouldReceive('remember')->andReturn($builder);
$cache->shouldNotReceive('remember')->andReturn($builder);

// Assuming 'name' filter translates to a method call
$filter = new MockFilter($request, $cache);
Expand All @@ -69,7 +69,7 @@ public function testAppliesFiltersDynamicallyBasedOnRequestWithCustomMethodNames
$builder = $model->newQuery();

$cache = m::mock(Repository::class);
$cache->shouldReceive('remember')->andReturn($builder);
$cache->shouldNotReceive('remember')->andReturn($builder);

// Assuming 'name' filter translates to a method call
$filter = new class ($request, $cache) extends Filter {
Expand All @@ -82,6 +82,7 @@ public function filterByName($name)
return $this->builder->where('name', 'LIKE', "%{$name}%");
}
};

$filter->setUseCache(false);

$results = $filter->apply($builder);
Expand Down

0 comments on commit 4a5fb11

Please sign in to comment.