From b487073668ef13e147e3d74f7b39b4aa643f1572 Mon Sep 17 00:00:00 2001 From: Paul Rijke Date: Sat, 26 Oct 2024 15:16:07 +0200 Subject: [PATCH] Add BackedEnum for route names --- src/Concerns/InteractsWithPages.php | 5 +++-- src/Concerns/MakesHttpRequests.php | 9 +++++++-- src/TestResponse.php | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Concerns/InteractsWithPages.php b/src/Concerns/InteractsWithPages.php index 391cbcc..dc1086e 100644 --- a/src/Concerns/InteractsWithPages.php +++ b/src/Concerns/InteractsWithPages.php @@ -2,6 +2,7 @@ namespace Laravel\BrowserKitTesting\Concerns; +use BackedEnum; use Closure; use Illuminate\Http\UploadedFile; use InvalidArgumentException; @@ -65,7 +66,7 @@ public function visit($uri) /** * Visit the given named route with a GET request. * - * @param string $route + * @param string|BackedEnum $route * @param array $parameters * @return $this */ @@ -195,7 +196,7 @@ protected function seePageIs($uri) /** * Assert that the current page matches a given named route. * - * @param string $route + * @param string|BackedEnum $route * @param array $parameters * @return $this */ diff --git a/src/Concerns/MakesHttpRequests.php b/src/Concerns/MakesHttpRequests.php index 29665c7..eb131bd 100644 --- a/src/Concerns/MakesHttpRequests.php +++ b/src/Concerns/MakesHttpRequests.php @@ -2,6 +2,7 @@ namespace Laravel\BrowserKitTesting\Concerns; +use BackedEnum; use Illuminate\Cookie\CookieValuePrefix; use Illuminate\Http\Request; use Illuminate\Http\UploadedFile; @@ -622,7 +623,7 @@ public function action($method, $action, $wildcards = [], $parameters = [], $coo * Call a named route and return the Response. * * @param string $method - * @param string $name + * @param string|BackedEnum $name * @param array $routeParameters * @param array $parameters * @param array $cookies @@ -633,6 +634,10 @@ public function action($method, $action, $wildcards = [], $parameters = [], $coo */ public function route($method, $name, $routeParameters = [], $parameters = [], $cookies = [], $files = [], $server = [], $content = null) { + if ($name instanceof BackedEnum && ! is_string($name = $name->value)) { + throw new \InvalidArgumentException('Route name must be a string or a BackedEnum.'); + } + $uri = $this->app['url']->route($name, $routeParameters); return $this->call($method, $uri, $parameters, $cookies, $files, $server, $content); @@ -808,7 +813,7 @@ public function assertRedirectedTo($uri, $with = []) /** * Assert whether the client was redirected to a given route. * - * @param string $name + * @param string|BackedEnum $name * @param array $parameters * @param array $with * @return $this diff --git a/src/TestResponse.php b/src/TestResponse.php index 577e4bf..c3b0351 100644 --- a/src/TestResponse.php +++ b/src/TestResponse.php @@ -2,6 +2,7 @@ namespace Laravel\BrowserKitTesting; +use BackedEnum; use Illuminate\Testing\Assert as PHPUnit; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -49,7 +50,7 @@ public function assertRedirectedTo($uri, $with = []) /** * Assert whether the client was redirected to a given route. * - * @param string $name + * @param string|BackedEnum $name * @param array $parameters * @param array $with * @return $this