|
9 | 9 | use Illuminate\Routing\Router;
|
10 | 10 | use Mockery as m;
|
11 | 11 | use PHPUnit\Framework\TestCase;
|
| 12 | +use Stringable; |
12 | 13 |
|
13 | 14 | class RouteRegistrarTest extends TestCase
|
14 | 15 | {
|
@@ -60,6 +61,42 @@ public function testMiddlewareFluentRegistration()
|
60 | 61 | $this->assertEquals(['seven'], $this->getRoute()->middleware());
|
61 | 62 | }
|
62 | 63 |
|
| 64 | + public function testMiddlewareAsStringableObject() |
| 65 | + { |
| 66 | + $one = new class implements Stringable |
| 67 | + { |
| 68 | + public function __toString() |
| 69 | + { |
| 70 | + return 'one'; |
| 71 | + } |
| 72 | + }; |
| 73 | + |
| 74 | + $this->router->middleware($one)->get('users', function () { |
| 75 | + return 'all-users'; |
| 76 | + }); |
| 77 | + |
| 78 | + $this->seeResponse('all-users', Request::create('users', 'GET')); |
| 79 | + $this->assertSame(['one'], $this->getRoute()->middleware()); |
| 80 | + } |
| 81 | + |
| 82 | + public function testMiddlewareAsArrayWithStringables() |
| 83 | + { |
| 84 | + $one = new class implements Stringable |
| 85 | + { |
| 86 | + public function __toString() |
| 87 | + { |
| 88 | + return 'one'; |
| 89 | + } |
| 90 | + }; |
| 91 | + |
| 92 | + $this->router->middleware([$one, 'two'])->get('users', function () { |
| 93 | + return 'all-users'; |
| 94 | + }); |
| 95 | + |
| 96 | + $this->seeResponse('all-users', Request::create('users', 'GET')); |
| 97 | + $this->assertSame(['one', 'two'], $this->getRoute()->middleware()); |
| 98 | + } |
| 99 | + |
63 | 100 | public function testWithoutMiddlewareRegistration()
|
64 | 101 | {
|
65 | 102 | $this->router->middleware(['one', 'two'])->get('users', function () {
|
@@ -190,6 +227,26 @@ public function testCanRegisterGroupWithMiddleware()
|
190 | 227 | $this->seeMiddleware('group-middleware');
|
191 | 228 | }
|
192 | 229 |
|
| 230 | + public function testCanRegisterGroupWithStringableMiddleware() |
| 231 | + { |
| 232 | + $one = new class implements Stringable |
| 233 | + { |
| 234 | + public function __toString() |
| 235 | + { |
| 236 | + return 'one'; |
| 237 | + } |
| 238 | + }; |
| 239 | + |
| 240 | + $this->router->middleware($one)->group(function ($router) { |
| 241 | + $router->get('users', function () { |
| 242 | + return 'all-users'; |
| 243 | + }); |
| 244 | + }); |
| 245 | + |
| 246 | + $this->seeResponse('all-users', Request::create('users', 'GET')); |
| 247 | + $this->seeMiddleware('one'); |
| 248 | + } |
| 249 | + |
193 | 250 | public function testCanRegisterGroupWithNamespace()
|
194 | 251 | {
|
195 | 252 | $this->router->namespace('App\Http\Controllers')->group(function ($router) {
|
@@ -606,6 +663,27 @@ public function testResourceWithoutMiddlewareRegistration()
|
606 | 663 | $this->assertEquals(['one'], $this->getRoute()->excludedMiddleware());
|
607 | 664 | }
|
608 | 665 |
|
| 666 | + public function testResourceWithMiddlewareAsStringable() |
| 667 | + { |
| 668 | + $one = new class implements Stringable |
| 669 | + { |
| 670 | + public function __toString() |
| 671 | + { |
| 672 | + return 'one'; |
| 673 | + } |
| 674 | + }; |
| 675 | + |
| 676 | + $this->router->resource('users', RouteRegistrarControllerStub::class) |
| 677 | + ->only('index') |
| 678 | + ->middleware([$one, 'two']) |
| 679 | + ->withoutMiddleware('one'); |
| 680 | + |
| 681 | + $this->seeResponse('controller', Request::create('users', 'GET')); |
| 682 | + |
| 683 | + $this->assertEquals(['one', 'two'], $this->getRoute()->middleware()); |
| 684 | + $this->assertEquals(['one'], $this->getRoute()->excludedMiddleware()); |
| 685 | + } |
| 686 | + |
609 | 687 | public function testResourceWheres()
|
610 | 688 | {
|
611 | 689 | $wheres = [
|
|
0 commit comments