Skip to content

Commit

Permalink
bugfix in substituting value with default
Browse files Browse the repository at this point in the history
  • Loading branch information
henzeb committed Jan 7, 2023
1 parent 2a151ab commit df47c11
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Laravel/Middleware/SubstituteEnums.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private function getParameters(Route|null $route): array
$route?->signatureParameters(['subClass' => UnitEnum::class])
)->mapWithKeys(
function (ReflectionParameter $parameter) {
$backedEnumClass = rtrim((string)$parameter->getType(), '?');
$backedEnumClass = ltrim((string)$parameter->getType(), '?');

if (enum_exists($backedEnumClass)) {
return [$parameter->getName() => new ReflectionEnum($backedEnumClass)];
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Laravel/Middleware/SubstituteEnumsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function (SimpleEnum $status) {

$router->get('/optional/{status?}',
function (SimpleEnum $status = null) {
return $status?->name;
}
);

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

public function testShouldBindBasicEnumOptionally()
{
$this->get('/optional/')->assertOk();
// $this->get('/optional/')->assertOk()->assertSee('');
$this->get('/optional/open')->assertOk()->assertSee('Open');
}

public function testShouldBindBasicEnumWithDefault()
Expand Down

0 comments on commit df47c11

Please sign in to comment.