Skip to content

Commit 1467c3a

Browse files
committed
Fix tests
1 parent 52897ca commit 1467c3a

6 files changed

Lines changed: 8 additions & 46 deletions

File tree

src/Exceptions/SharpInvalidFilterValueException.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Filters/GlobalRequiredFilter.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Code16\Sharp\Filters;
44

5-
use Code16\Sharp\Exceptions\SharpInvalidFilterValueException;
6-
75
abstract class GlobalRequiredFilter extends SelectRequiredFilter
86
{
97
private mixed $currentValue = null;
@@ -15,7 +13,7 @@ final public function currentValue(): mixed
1513
: $this->defaultValue();
1614
}
1715

18-
final public function setCurrentValue(mixed $value, bool $throwIfInvalid = true): void
16+
final public function setCurrentValue(mixed $value): void
1917
{
2018
if ($value === null) {
2119
$this->currentValue = null;
@@ -27,10 +25,6 @@ final public function setCurrentValue(mixed $value, bool $throwIfInvalid = true)
2725
->where('id', $value)
2826
->first();
2927

30-
if ($throwIfInvalid && ! $formattedValue) {
31-
throw new SharpInvalidFilterValueException('['.$value.'] is not a valid value for this filter.');
32-
}
33-
3428
$this->currentValue = $formattedValue['id'] ?? null;
3529
}
3630

src/Http/Controllers/GlobalFilterController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function update(string $filterKey, GlobalFilters $globalFilters): Redirec
1414

1515
abort_if(! $handler instanceof GlobalRequiredFilter, 404);
1616

17-
$handler->setCurrentValue(request('value'), throwIfInvalid: false);
17+
$handler->setCurrentValue(request('value'));
1818

1919
return redirect()->route('code16.sharp.home', [
2020
'filterKey' => sharp()->context()->globalFilterUrlSegmentValue(),

src/Http/Middleware/HandleGlobalFilters.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Code16\Sharp\Http\Middleware;
44

55
use Closure;
6-
use Code16\Sharp\Exceptions\SharpInvalidFilterValueException;
76
use Code16\Sharp\Filters\GlobalFilters\GlobalFilters;
87
use Code16\Sharp\Filters\GlobalRequiredFilter;
98
use Illuminate\Http\Request;
@@ -23,14 +22,10 @@ public function handle(Request $request, Closure $next)
2322
return redirect()->route('code16.sharp.home');
2423
}
2524

26-
try {
27-
collect($this->globalFiltersHandler->getFilters())
28-
->each(fn (GlobalRequiredFilter $globalFilter, int $index) => $globalFilter
29-
->setCurrentValue($filterKeys[$index])
30-
);
31-
} catch (SharpInvalidFilterValueException) {
32-
abort(404);
33-
}
25+
collect($this->globalFiltersHandler->getFilters())
26+
->each(fn (GlobalRequiredFilter $globalFilter, int $index) => $globalFilter
27+
->setCurrentValue($filterKeys[$index])
28+
);
3429
}
3530

3631
URL::defaults(['filterKey' => sharp()->context()->globalFilterUrlSegmentValue()]);

tests/Http/GlobalFilterControllerTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,9 @@ public function defaultValue(): mixed
7777
->where('globalFilters.filterValues.default.test', 2)
7878
);
7979

80-
$this
81-
->post(route('code16.sharp.filters.update', 'test'), ['value' => 3]);
82-
8380
$this
8481
->followingRedirects()
85-
->get('/sharp/s-list/person')
82+
->get('/sharp/3/s-list/person')
8683
->assertInertia(fn (Assert $page) => $page
8784
->has('globalFilters.config.filters._root.0', fn (Assert $filter) => $filter
8885
->where('key', 'test')

tests/Http/GlobalFilterRoutesTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939

4040
$this->get('/sharp/s-list/person')
4141
->assertRedirect('/sharp/two/s-list/person');
42-
43-
$this->post(route('code16.sharp.filters.update', 'test'), ['value' => 'three']);
44-
45-
$this->get('/sharp/s-list/person/s-show/person/1')
46-
->assertRedirect('/sharp/three/s-list/person/s-show/person/1');
4742
});
4843

4944
it('sets the current filterKey according to the URL', function () {
@@ -60,7 +55,7 @@
6055
fakeGlobalFilter();
6156

6257
$this->get('/sharp/five/s-list/person/s-show/person/1')
63-
->assertNotFound();
58+
->assertOk();
6459

6560
expect(sharp()->context()->globalFilterValue('test'))->toEqual('two');
6661
});
@@ -71,12 +66,6 @@
7166

7267
$this->get('/sharp/s-list/person')
7368
->assertRedirect('/sharp/two~two/s-list/person');
74-
75-
$this->post(route('code16.sharp.filters.update', 'test1'), ['value' => 'one']);
76-
$this->post(route('code16.sharp.filters.update', 'test2'), ['value' => 'three']);
77-
78-
$this->get('/sharp/s-list/person/s-show/person/1')
79-
->assertRedirect('/sharp/one~three/s-list/person/s-show/person/1');
8069
});
8170

8271
it('sets the current multiple filterKeys according to the URL', function () {

0 commit comments

Comments
 (0)