Skip to content

Commit 940acf1

Browse files
Add BackedEnum for route names (#183)
* Add BackedEnum for route names * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 8508cc9 commit 940acf1

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/Concerns/InteractsWithPages.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravel\BrowserKitTesting\Concerns;
44

5+
use BackedEnum;
56
use Closure;
67
use Illuminate\Http\UploadedFile;
78
use InvalidArgumentException;
@@ -65,7 +66,7 @@ public function visit($uri)
6566
/**
6667
* Visit the given named route with a GET request.
6768
*
68-
* @param string $route
69+
* @param BackedEnum|string $route
6970
* @param array $parameters
7071
* @return $this
7172
*/
@@ -195,7 +196,7 @@ protected function seePageIs($uri)
195196
/**
196197
* Assert that the current page matches a given named route.
197198
*
198-
* @param string $route
199+
* @param BackedEnum|string $route
199200
* @param array $parameters
200201
* @return $this
201202
*/

src/Concerns/MakesHttpRequests.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Laravel\BrowserKitTesting\Concerns;
44

5+
use BackedEnum;
56
use Illuminate\Cookie\CookieValuePrefix;
67
use Illuminate\Http\Request;
78
use Illuminate\Http\UploadedFile;
89
use Illuminate\Support\Str;
10+
use InvalidArgumentException;
911
use Laravel\BrowserKitTesting\TestResponse;
1012
use PHPUnit\Framework\ExpectationFailedException;
1113
use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile;
@@ -622,7 +624,7 @@ public function action($method, $action, $wildcards = [], $parameters = [], $coo
622624
* Call a named route and return the Response.
623625
*
624626
* @param string $method
625-
* @param string $name
627+
* @param BackedEnum|string $name
626628
* @param array $routeParameters
627629
* @param array $parameters
628630
* @param array $cookies
@@ -633,6 +635,10 @@ public function action($method, $action, $wildcards = [], $parameters = [], $coo
633635
*/
634636
public function route($method, $name, $routeParameters = [], $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
635637
{
638+
if ($name instanceof BackedEnum && ! is_string($name = $name->value)) {
639+
throw new InvalidArgumentException('Route name must be a string or a BackedEnum.');
640+
}
641+
636642
$uri = $this->app['url']->route($name, $routeParameters);
637643

638644
return $this->call($method, $uri, $parameters, $cookies, $files, $server, $content);
@@ -808,7 +814,7 @@ public function assertRedirectedTo($uri, $with = [])
808814
/**
809815
* Assert whether the client was redirected to a given route.
810816
*
811-
* @param string $name
817+
* @param BackedEnum|string $name
812818
* @param array $parameters
813819
* @param array $with
814820
* @return $this

src/TestResponse.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravel\BrowserKitTesting;
44

5+
use BackedEnum;
56
use Illuminate\Testing\Assert as PHPUnit;
67
use Symfony\Component\HttpFoundation\RedirectResponse;
78

@@ -49,7 +50,7 @@ public function assertRedirectedTo($uri, $with = [])
4950
/**
5051
* Assert whether the client was redirected to a given route.
5152
*
52-
* @param string $name
53+
* @param BackedEnum|string $name
5354
* @param array $parameters
5455
* @param array $with
5556
* @return $this

0 commit comments

Comments
 (0)