Skip to content

Commit

Permalink
Add BackedEnum for route names (#183)
Browse files Browse the repository at this point in the history
* Add BackedEnum for route names

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
parijke and taylorotwell authored Oct 29, 2024
1 parent 8508cc9 commit 940acf1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Concerns/InteractsWithPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\BrowserKitTesting\Concerns;

use BackedEnum;
use Closure;
use Illuminate\Http\UploadedFile;
use InvalidArgumentException;
Expand Down Expand Up @@ -65,7 +66,7 @@ public function visit($uri)
/**
* Visit the given named route with a GET request.
*
* @param string $route
* @param BackedEnum|string $route
* @param array $parameters
* @return $this
*/
Expand Down Expand Up @@ -195,7 +196,7 @@ protected function seePageIs($uri)
/**
* Assert that the current page matches a given named route.
*
* @param string $route
* @param BackedEnum|string $route
* @param array $parameters
* @return $this
*/
Expand Down
10 changes: 8 additions & 2 deletions src/Concerns/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Laravel\BrowserKitTesting\Concerns;

use BackedEnum;
use Illuminate\Cookie\CookieValuePrefix;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Laravel\BrowserKitTesting\TestResponse;
use PHPUnit\Framework\ExpectationFailedException;
use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile;
Expand Down Expand Up @@ -622,7 +624,7 @@ public function action($method, $action, $wildcards = [], $parameters = [], $coo
* Call a named route and return the Response.
*
* @param string $method
* @param string $name
* @param BackedEnum|string $name
* @param array $routeParameters
* @param array $parameters
* @param array $cookies
Expand All @@ -633,6 +635,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);
Expand Down Expand Up @@ -808,7 +814,7 @@ public function assertRedirectedTo($uri, $with = [])
/**
* Assert whether the client was redirected to a given route.
*
* @param string $name
* @param BackedEnum|string $name
* @param array $parameters
* @param array $with
* @return $this
Expand Down
3 changes: 2 additions & 1 deletion src/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\BrowserKitTesting;

use BackedEnum;
use Illuminate\Testing\Assert as PHPUnit;
use Symfony\Component\HttpFoundation\RedirectResponse;

Expand Down Expand Up @@ -49,7 +50,7 @@ public function assertRedirectedTo($uri, $with = [])
/**
* Assert whether the client was redirected to a given route.
*
* @param string $name
* @param BackedEnum|string $name
* @param array $parameters
* @param array $with
* @return $this
Expand Down

0 comments on commit 940acf1

Please sign in to comment.