-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathRouterMatchCommandTest.php
89 lines (76 loc) · 2.85 KB
/
RouterMatchCommandTest.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
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouterInterface;
class RouterMatchCommandTest extends TestCase
{
public function testWithMatchPath()
{
$tester = $this->createCommandTester();
$ret = $tester->execute(['path_info' => '/foo', 'foo'], ['decorated' => false]);
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertStringContainsString('Route Name | foo', $tester->getDisplay());
}
public function testWithNotMatchPath()
{
$tester = $this->createCommandTester();
$ret = $tester->execute(['path_info' => '/test', 'foo'], ['decorated' => false]);
$this->assertEquals(1, $ret, 'Returns 1 in case of failure');
$this->assertStringContainsString('None of the routes match the path "/test"', $tester->getDisplay());
}
private function createCommandTester(): CommandTester
{
$application = new Application($this->getKernel());
$application->add(new RouterMatchCommand($this->getRouter()));
$application->add(new RouterDebugCommand($this->getRouter()));
return new CommandTester($application->find('router:match'));
}
private function getRouter()
{
$routeCollection = new RouteCollection();
$routeCollection->add('foo', new Route('foo'));
$requestContext = new RequestContext();
$router = $this->createMock(RouterInterface::class);
$router
->expects($this->any())
->method('getRouteCollection')
->willReturn($routeCollection);
$router
->expects($this->any())
->method('getContext')
->willReturn($requestContext);
return $router;
}
private function getKernel()
{
$kernel = $this->createMock(KernelInterface::class);
$kernel
->expects($this->any())
->method('getContainer')
->willReturn(new Container())
;
$kernel
->expects($this->once())
->method('getBundles')
->willReturn([])
;
return $kernel;
}
}