|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Symfony-Util package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Jean-Bernard Addor |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
use Symfony\Bridge\Twig\TwigEngine; |
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
18
|
|
|
use Symfony\Component\HttpKernel\Controller\ArgumentResolver; |
|
19
|
|
|
use Symfony\Component\HttpKernel\Controller\ControllerResolver; |
|
20
|
|
|
use Symfony\Component\HttpKernel\EventListener\ResponseListener; |
|
21
|
|
|
use Symfony\Component\HttpKernel\EventListener\RouterListener; |
|
22
|
|
|
use Symfony\Component\HttpKernel\HttpKernel; |
|
23
|
|
|
use Symfony\Component\Routing\Matcher\UrlMatcher; |
|
24
|
|
|
use Symfony\Component\Routing\RequestContext; |
|
25
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
|
26
|
|
|
use SymfonyUtil\Controller\EngineAsArgumentController; |
|
27
|
|
|
use Tests\Component\AppKernel; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @covers \SymfonyUtil\Controller\EngineAsArgumentController |
|
31
|
|
|
*/ |
|
32
|
|
|
final class EngineAsArgumentInKernelControllerTest extends TestCase |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
public function testCanBeCreated() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->assertInstanceOf( |
|
37
|
|
|
// ...::class, // 5.4 < php |
|
|
|
|
|
|
38
|
|
|
'Symfony\Component\HttpKernel\Kernel', |
|
39
|
|
|
new AppKernel('dev', true) |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testKernelInterface() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->assertInstanceOf( |
|
46
|
|
|
// ...::class, // 5.4 < php |
|
|
|
|
|
|
47
|
|
|
'Symfony\Component\HttpKernel\KernelInterface', |
|
48
|
|
|
new AppKernel('dev', true) |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testFrameworkReturnsResponse() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->assertInstanceOf( |
|
55
|
|
|
// Response::class, // 5.4 < php |
|
56
|
|
|
'Symfony\Component\HttpFoundation\Response', |
|
57
|
|
|
(new AppKernel('dev', true))->handle(Request::create('/', 'GET')) |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testComponentReturnsResponse() |
|
62
|
|
|
{ |
|
63
|
|
|
$requestStack = new RequestStack(); |
|
64
|
|
|
$routes = new RouteCollectionBuilder(); // Because I know how to use it. |
|
65
|
|
|
$routes->add('/', EngineAsArgumentController::class, 'index'); // returns Symfony/Component/Routing/Route |
|
66
|
|
|
$dispatcher = new EventDispatcher(); |
|
67
|
|
|
$dispatcher->addSubscriber(new RouterListener( |
|
68
|
|
|
new UrlMatcher( |
|
69
|
|
|
$routes-> build(), |
|
70
|
|
|
new RequestContext() |
|
71
|
|
|
), |
|
72
|
|
|
$requestStack |
|
73
|
|
|
)); |
|
74
|
|
|
$dispatcher->addSubscriber(new ResponseListener('UTF-8')); |
|
75
|
|
|
$this->assertInstanceOf( |
|
76
|
|
|
// Response::class, // 5.4 < php |
|
77
|
|
|
'Symfony\Component\HttpFoundation\Response', |
|
78
|
|
|
(new HttpKernel( |
|
79
|
|
|
$dispatcher, |
|
80
|
|
|
new ControllerResolver(), |
|
81
|
|
|
$requestStack, |
|
82
|
|
|
new ArgumentResolver(); |
|
|
|
|
|
|
83
|
|
|
))->handle(Request::create('/', 'GET')) |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// http://api.symfony.com/3.3/Symfony/Bridge/Twig/TwigEngine.html |
|
89
|
|
|
// http://api.symfony.com/3.3/Symfony/Bundle/TwigBundle/TwigEngine.html |
|
90
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.