|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Tests\Collector; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Di\Container; |
|
8
|
|
|
use Yiisoft\Di\ContainerConfig; |
|
9
|
|
|
use Yiisoft\Router\Group; |
|
10
|
|
|
use Yiisoft\Router\Route; |
|
11
|
|
|
use Yiisoft\Router\RouteCollection; |
|
12
|
|
|
use Yiisoft\Router\RouteCollectionInterface; |
|
13
|
|
|
use Yiisoft\Router\RouteCollector; |
|
14
|
|
|
use Yiisoft\Router\RouteCollectorInterface; |
|
15
|
|
|
use Yiisoft\Router\UrlMatcherInterface; |
|
16
|
|
|
use Yiisoft\Yii\Debug\Collector\CollectorInterface; |
|
17
|
|
|
use Yiisoft\Yii\Debug\Collector\RouterCollector; |
|
18
|
|
|
|
|
19
|
|
|
final class RouterCollectorTest extends CollectorTestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var \PHPUnit\Framework\MockObject\MockObject|\Yiisoft\Router\RouteCollectorInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $routeCollector; |
|
25
|
|
|
|
|
26
|
|
|
private ?Container $container = null; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param \Yiisoft\Yii\Debug\Collector\CollectorInterface|\Yiisoft\Yii\Debug\Collector\RouterCollector $collector |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function collectTestData(CollectorInterface $collector): void |
|
32
|
|
|
{ |
|
33
|
|
|
$routes = $this->createRoutes(); |
|
34
|
|
|
$this->routeCollector |
|
35
|
|
|
->method('getItems') |
|
|
|
|
|
|
36
|
|
|
->willReturn($routes); |
|
37
|
|
|
$collector->collect(0.001); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function getCollector(): CollectorInterface |
|
41
|
|
|
{ |
|
42
|
|
|
$this->routeCollector = $this->createMock(RouteCollectorInterface::class); |
|
43
|
|
|
$routeCollector = new RouteCollector(); |
|
44
|
|
|
$routeCollector->addGroup(Group::create()->routes(...$this->createRoutes())); |
|
45
|
|
|
|
|
46
|
|
|
$config = ContainerConfig::create() |
|
47
|
|
|
->withDefinitions([ |
|
48
|
|
|
UrlMatcherInterface::class => $this->routeCollector, |
|
49
|
|
|
RouteCollectionInterface::class => RouteCollection::class, |
|
50
|
|
|
RouteCollectorInterface::class => $routeCollector, |
|
51
|
|
|
]); |
|
52
|
|
|
$this->container = new Container($config); |
|
53
|
|
|
|
|
54
|
|
|
return new RouterCollector($this->container); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected function checkCollectedData(CollectorInterface $collector): void |
|
58
|
|
|
{ |
|
59
|
|
|
parent::checkCollectedData($collector); |
|
60
|
|
|
$this->assertArrayHasKey('routes', $collector->getCollected()); |
|
61
|
|
|
$this->assertArrayHasKey('routesTree', $collector->getCollected()); |
|
62
|
|
|
$this->assertArrayHasKey('routeTime', $collector->getCollected()); |
|
63
|
|
|
$this->assertEquals( |
|
64
|
|
|
$this->container->get(RouteCollectionInterface::class)->getRoutes(), |
|
|
|
|
|
|
65
|
|
|
$collector->getCollected()['routes'] |
|
66
|
|
|
); |
|
67
|
|
|
$this->assertEquals( |
|
68
|
|
|
$this->container->get(RouteCollectionInterface::class)->getRouteTree(), |
|
69
|
|
|
$collector->getCollected()['routesTree'] |
|
70
|
|
|
); |
|
71
|
|
|
$this->assertEquals( |
|
72
|
|
|
0.001, |
|
73
|
|
|
$collector->getCollected()['routeTime'] |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
private function createRoutes(): array |
|
78
|
|
|
{ |
|
79
|
|
|
return [ |
|
80
|
|
|
Route::get('/'), |
|
81
|
|
|
Group::create('/api')->routes(Route::get('/v1')), |
|
82
|
|
|
]; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.