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\HttpFoundation\Response; |
15
|
|
|
use Symfony\Component\Templating\TemplateNameParser; |
16
|
|
|
use SymfonyUtil\Controller\TemplatingController; |
17
|
|
|
|
18
|
|
|
class HomeTemplatingController extends TemplatingController // To test more in details |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
const TEMPLATE = 'home.html.twig'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @covers \SymfonyUtil\Controller\TemplatingController |
25
|
|
|
*/ |
26
|
|
|
final class TemplatingControllerTest extends TestCase |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
public function testCanBeCreated() |
29
|
|
|
{ |
30
|
|
|
$this->assertInstanceOf( |
31
|
|
|
// ::class, // 5.4 < php |
32
|
|
|
'SymfonyUtil\Controller\TemplatingController', |
33
|
|
|
new TemplatingController(new TwigEngine( |
34
|
|
|
new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])), |
|
|
|
|
35
|
|
|
new TemplateNameParser() |
36
|
|
|
)) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testHomeCanBeCreated() |
41
|
|
|
{ |
42
|
|
|
$this->assertInstanceOf( |
43
|
|
|
// ::class, // 5.4 < php |
44
|
|
|
'SymfonyUtil\Controller\TemplatingController', |
45
|
|
|
new HomeTemplatingController(new TwigEngine( |
46
|
|
|
new Twig_Environment(new Twig_Loader_Array(['home.html.twig' => 'Hello World!'])), |
|
|
|
|
47
|
|
|
new TemplateNameParser() |
48
|
|
|
)) |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testEmptyReturnsResponse() |
53
|
|
|
{ |
54
|
|
|
$this->assertInstanceOf( |
55
|
|
|
// Response::class, // 5.4 < php |
56
|
|
|
'Symfony\Component\HttpFoundation\Response', |
57
|
|
|
(new TemplatingController(new TwigEngine( |
58
|
|
|
new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])), |
|
|
|
|
59
|
|
|
new TemplateNameParser() |
60
|
|
|
)))->__invoke() |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testArrayReturnsResponse() |
65
|
|
|
{ |
66
|
|
|
$this->assertInstanceOf( |
67
|
|
|
// Response::class, // 5.4 < php |
68
|
|
|
'Symfony\Component\HttpFoundation\Response', |
69
|
|
|
(new TemplatingController(new TwigEngine( |
70
|
|
|
new Twig_Environment(new Twig_Loader_Array([ |
|
|
|
|
71
|
|
|
'index.html.twig' => '<ul>{% for item in 0 %}<li>{{ item }}</li>{% endfor %}</ul>', |
72
|
|
|
])), |
73
|
|
|
new TemplateNameParser() |
74
|
|
|
)))->__invoke([ |
|
|
|
|
75
|
|
|
'One', |
76
|
|
|
'Two', |
77
|
|
|
'Three', |
78
|
|
|
]) |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// http://api.symfony.com/3.3/Symfony/Bridge/Twig/TwigEngine.html |
84
|
|
|
// http://api.symfony.com/3.3/Symfony/Bundle/TwigBundle/TwigEngine.html |
85
|
|
|
|
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.