|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Barryvdh\Debugbar\Tests\DataCollector; |
| 4 | + |
| 5 | +use Barryvdh\Debugbar\Tests\TestCase; |
| 6 | +use DebugBar\DataCollector\DataCollector; |
| 7 | + |
| 8 | +class RouteCollectorTest extends TestCase |
| 9 | +{ |
| 10 | + /** @var \Barryvdh\Debugbar\DataCollector\RouteCollector $collector */ |
| 11 | + private DataCollector $routeCollector; |
| 12 | + protected function setUp(): void |
| 13 | + { |
| 14 | + parent::setUp(); |
| 15 | + debugbar()->boot(); |
| 16 | + |
| 17 | + $this->routeCollector = debugbar()->getCollector('route'); |
| 18 | + } |
| 19 | + |
| 20 | + public function testItCollectsRouteUri() |
| 21 | + { |
| 22 | + $this->get('web/html'); |
| 23 | + $this->assertSame('GET web/html', $this->routeCollector->collect()['uri']); |
| 24 | + |
| 25 | + $this->call('POST', 'web/mw'); |
| 26 | + $this->assertSame('POST web/mw', $this->routeCollector->collect()['uri']); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @dataProvider controllerData |
| 31 | + */ |
| 32 | + public function testItCollectsWithControllerHandler($controller, $file) |
| 33 | + { |
| 34 | + $this->get('web/show'); |
| 35 | + |
| 36 | + $collected = $this->routeCollector->collect(); |
| 37 | + |
| 38 | + $this->assertNotEmpty($collected); |
| 39 | + $this->assertArrayHasKey('file', $collected); |
| 40 | + $this->assertArrayHasKey('controller', $collected); |
| 41 | + $this->assertStringContainsString($file, $collected['file']); |
| 42 | + $this->assertStringContainsString($controller, $collected['controller']); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @dataProvider viewComponentData |
| 47 | + */ |
| 48 | + public function testItCollectsWithViewComponentHandler($controller, $file) |
| 49 | + { |
| 50 | + $this->get('web/view'); |
| 51 | + |
| 52 | + $collected = $this->routeCollector->collect(); |
| 53 | + |
| 54 | + $this->assertStringContainsString($file, $collected['file']); |
| 55 | + $this->assertStringContainsString($controller, $collected['controller']); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @dataProvider closureData |
| 60 | + */ |
| 61 | + public function testItCollectsWithClosureHandler($file) |
| 62 | + { |
| 63 | + $this->get('web/html'); |
| 64 | + |
| 65 | + $collected = $this->routeCollector->collect(); |
| 66 | + |
| 67 | + $this->assertNotEmpty($collected); |
| 68 | + $this->assertArrayHasKey('uses', $collected); |
| 69 | + $this->assertArrayHasKey('file', $collected); |
| 70 | + $this->assertStringContainsString($file, $collected['uses']); |
| 71 | + $this->assertStringContainsString($file, $collected['file']); |
| 72 | + } |
| 73 | + |
| 74 | + public function testItCollectsMiddleware() |
| 75 | + { |
| 76 | + $this->call('POST', 'web/mw'); |
| 77 | + |
| 78 | + $collected = $this->routeCollector->collect(); |
| 79 | + |
| 80 | + $this->assertNotEmpty($collected); |
| 81 | + $this->assertArrayHasKey('middleware', $collected); |
| 82 | + $this->assertStringContainsString('MockMiddleware', $collected['middleware']); |
| 83 | + } |
| 84 | + |
| 85 | + public static function controllerData() |
| 86 | + { |
| 87 | + $filePath = urlencode(str_replace('\\', '/', realpath(__DIR__ . '/../Mocks/MockController.php'))); |
| 88 | + return [['MockController@show', |
| 89 | + sprintf('phpstorm://open?file=%s', $filePath) |
| 90 | + ]]; |
| 91 | + } |
| 92 | + |
| 93 | + public static function viewComponentData() |
| 94 | + { |
| 95 | + $filePath = urlencode(str_replace('\\', '/', realpath(__DIR__ . '/../Mocks/MockViewComponent.php'))); |
| 96 | + return [['MockViewComponent@render', |
| 97 | + sprintf('phpstorm://open?file=%s', $filePath) |
| 98 | + ]]; |
| 99 | + } |
| 100 | + |
| 101 | + public static function closureData() |
| 102 | + { |
| 103 | + return [['TestCase.php']]; |
| 104 | + } |
| 105 | +} |
0 commit comments