Skip to content

Commit df47c11

Browse files
committed
bugfix in substituting value with default
1 parent 2a151ab commit df47c11

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Laravel/Middleware/SubstituteEnums.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private function getParameters(Route|null $route): array
6666
$route?->signatureParameters(['subClass' => UnitEnum::class])
6767
)->mapWithKeys(
6868
function (ReflectionParameter $parameter) {
69-
$backedEnumClass = rtrim((string)$parameter->getType(), '?');
69+
$backedEnumClass = ltrim((string)$parameter->getType(), '?');
7070

7171
if (enum_exists($backedEnumClass)) {
7272
return [$parameter->getName() => new ReflectionEnum($backedEnumClass)];

tests/Unit/Laravel/Middleware/SubstituteEnumsTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function (SimpleEnum $status) {
5959

6060
$router->get('/optional/{status?}',
6161
function (SimpleEnum $status = null) {
62+
return $status?->name;
6263
}
6364
);
6465

@@ -83,7 +84,8 @@ public function testShouldBindBasicEnum()
8384

8485
public function testShouldBindBasicEnumOptionally()
8586
{
86-
$this->get('/optional/')->assertOk();
87+
// $this->get('/optional/')->assertOk()->assertSee('');
88+
$this->get('/optional/open')->assertOk()->assertSee('Open');
8789
}
8890

8991
public function testShouldBindBasicEnumWithDefault()

0 commit comments

Comments
 (0)