-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
RouteListCommandTest.php
152 lines (126 loc) · 5.22 KB
/
RouteListCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace Illuminate\Tests\Testing\Console;
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
*/
private $router;
/**
* @var \Illuminate\Routing\UrlGenerator
*/
private $urlGenerator;
protected function setUp(): void
{
parent::setUp();
$this->router = $this->app->make(Registrar::class);
RouteListCommand::resolveTerminalWidthUsing(function () {
return 70;
});
}
public function testDisplayRoutesForCli()
{
$this->router->get('/', function () {
//
});
$this->router->get('closure', function () {
return new RedirectResponse($this->urlGenerator->signedRoute('signed-route'));
});
$this->router->get('controller-method/{user}', [FooController::class, 'show']);
$this->router->post('controller-invokable', FooController::class);
$this->router->domain('{account}.example.com')->group(function () {
$this->router->get('/', function () {
//
});
$this->router->get('user/{id}', function ($account, $id) {
//
})->name('user.show')->middleware('web');
});
$this->artisan(RouteListCommand::class)
->assertSuccessful()
->expectsOutput('')
->expectsOutput(' GET|HEAD / ..................................................... ')
->expectsOutput(' GET|HEAD {account}.example.com/ ................................ ')
->expectsOutput(' GET|HEAD closure ............................................... ')
->expectsOutput(' POST controller-invokable Illuminate\Tests\Testing\Console\…')
->expectsOutput(' GET|HEAD controller-method/{user} Illuminate\Tests\Testing\Cons…')
->expectsOutput(' GET|HEAD {account}.example.com/user/{id} ............. user.show')
->expectsOutput('');
}
public function testDisplayRoutesForCliInVerboseMode()
{
$this->router->get('closure', function () {
return new RedirectResponse($this->urlGenerator->signedRoute('signed-route'));
});
$this->router->get('controller-method/{user}', [FooController::class, 'show']);
$this->router->post('controller-invokable', FooController::class);
$this->router->domain('{account}.example.com')->group(function () {
$this->router->get('user/{id}', function ($account, $id) {
//
})->name('user.show')->middleware('web');
});
$this->artisan(RouteListCommand::class, ['-v' => true])
->assertSuccessful()
->expectsOutput('')
->expectsOutput(' GET|HEAD closure ............................................... ')
->expectsOutput(' POST controller-invokable Illuminate\\Tests\\Testing\\Console\\FooController')
->expectsOutput(' GET|HEAD controller-method/{user} Illuminate\\Tests\\Testing\\Console\\FooController@show')
->expectsOutput(' GET|HEAD {account}.example.com/user/{id} ............. user.show')
->expectsOutput(' ⇂ web')
->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('');
}
public function testDisplayRoutesExceptVendor()
{
$this->router->get('foo/{user}', [FooController::class, 'show']);
$this->router->view('view', 'blade.path');
$this->router->redirect('redirect', 'destination');
$this->artisan(RouteListCommand::class, ['--except-vendor' => true])
->assertSuccessful()
->expectsOutput('')
->expectsOutput(' GET|HEAD foo/{user} Illuminate\Tests\Testing\Console\FooCon…')
->expectsOutput(' ANY redirect .... Illuminate\Routing\RedirectController')
->expectsOutput(' GET|HEAD view .............................................. ')
->expectsOutput('');
}
protected function tearDown(): void
{
parent::tearDown();
Facade::setFacadeApplication(null);
RouteListCommand::resolveTerminalWidthUsing(null);
}
}
class FooController extends Controller
{
public function show(User $user)
{
// ..
}
public function __invoke()
{
// ..
}
}