Skip to content

Commit

Permalink
[9.x] Fix deprecation warnings from route:list when filtering on name…
Browse files Browse the repository at this point in the history
… or domain (#41421)

* Add failing test for passing null to Str::contains

* Fix issue by casting route name and domain to string since they can be null
  • Loading branch information
hmazter committed Mar 10, 2022
1 parent bf9f8f7 commit f20b074
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Console/RouteListCommand.php
Expand Up @@ -240,10 +240,10 @@ protected function isVendorRoute(Route $route)
*/
protected function filterRoute(array $route)
{
if (($this->option('name') && ! Str::contains($route['name'], $this->option('name'))) ||
if (($this->option('name') && ! Str::contains((string) $route['name'], $this->option('name'))) ||
($this->option('path') && ! Str::contains($route['uri'], $this->option('path'))) ||
($this->option('method') && ! Str::contains($route['method'], strtoupper($this->option('method')))) ||
($this->option('domain') && ! Str::contains($route['domain'], $this->option('domain'))) ||
($this->option('domain') && ! Str::contains((string) $route['domain'], $this->option('domain'))) ||
($this->option('except-vendor') && $route['vendor'])) {
return;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Testing/Console/RouteListCommandTest.php
Expand Up @@ -5,13 +5,16 @@
use Illuminate\Contracts\Routing\Registrar;
use Illuminate\Foundation\Auth\User;
use Illuminate\Foundation\Console\RouteListCommand;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDeprecationHandling;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Facade;
use Orchestra\Testbench\TestCase;

class RouteListCommandTest extends TestCase
{
use InteractsWithDeprecationHandling;

/**
* @var \Illuminate\Contracts\Routing\Registrar
*/
Expand Down Expand Up @@ -92,6 +95,24 @@ public function testDisplayRoutesForCliInVerboseMode()
->expectsOutput('');
}

public function testRouteCanBeFilteredByName()
{
$this->withoutDeprecationHandling();

$this->router->get('/', function () {
//
});
$this->router->get('/foo', function () {
//
})->name('foo.show');

$this->artisan(RouteListCommand::class, ['--name' => 'foo'])
->assertSuccessful()
->expectsOutput('')
->expectsOutput(' GET|HEAD foo ...................................... foo.show')
->expectsOutput('');
}

protected function tearDown(): void
{
parent::tearDown();
Expand Down

0 comments on commit f20b074

Please sign in to comment.