-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathRouteCollectorTest.php
112 lines (89 loc) · 3.29 KB
/
RouteCollectorTest.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
<?php
namespace Barryvdh\Debugbar\Tests\DataCollector;
use Barryvdh\Debugbar\Tests\TestCase;
use DebugBar\DataCollector\DataCollector;
class RouteCollectorTest extends TestCase
{
/** @var \Barryvdh\Debugbar\DataCollector\RouteCollector $collector */
private DataCollector $routeCollector;
protected function setUp(): void
{
parent::setUp();
debugbar()->boot();
$this->routeCollector = debugbar()->getCollector('route');
}
protected function getEnvironmentSetUp($app)
{
$app['config']->set('debugbar.collectors.route', true);
parent::getEnvironmentSetUp($app);
}
public function testItCollectsRouteUri()
{
$this->get('web/html');
$this->assertSame('GET web/html', $this->routeCollector->collect()['uri']);
$this->call('POST', 'web/mw');
$this->assertSame('POST web/mw', $this->routeCollector->collect()['uri']);
}
/**
* @dataProvider controllerData
*/
public function testItCollectsWithControllerHandler($controller, $file)
{
$this->get('web/show');
$collected = $this->routeCollector->collect();
$this->assertNotEmpty($collected);
$this->assertArrayHasKey('file', $collected);
$this->assertArrayHasKey('controller', $collected);
$this->assertStringContainsString($file, $collected['file']);
$this->assertStringContainsString($controller, $collected['controller']);
}
/**
* @dataProvider viewComponentData
*/
public function testItCollectsWithViewComponentHandler($controller, $file)
{
$this->get('web/view');
$collected = $this->routeCollector->collect();
$this->assertStringContainsString($file, $collected['file']);
$this->assertStringContainsString($controller, $collected['controller']);
}
/**
* @dataProvider closureData
*/
public function testItCollectsWithClosureHandler($file)
{
$this->get('web/html');
$collected = $this->routeCollector->collect();
$this->assertNotEmpty($collected);
$this->assertArrayHasKey('uses', $collected);
$this->assertArrayHasKey('file', $collected);
$this->assertStringContainsString($file, $collected['uses']);
$this->assertStringContainsString($file, $collected['file']);
}
public function testItCollectsMiddleware()
{
$this->call('POST', 'web/mw');
$collected = $this->routeCollector->collect();
$this->assertNotEmpty($collected);
$this->assertArrayHasKey('middleware', $collected);
$this->assertStringContainsString('MockMiddleware', $collected['middleware']);
}
public static function controllerData()
{
$filePath = urlencode(str_replace('\\', '/', realpath(__DIR__ . '/../Mocks/MockController.php')));
return [['MockController@show',
sprintf('phpstorm://open?file=%s', $filePath)
]];
}
public static function viewComponentData()
{
$filePath = urlencode(str_replace('\\', '/', realpath(__DIR__ . '/../Mocks/MockViewComponent.php')));
return [['MockViewComponent@render',
sprintf('phpstorm://open?file=%s', $filePath)
]];
}
public static function closureData()
{
return [['TestCase.php']];
}
}