|
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
|
|
View Code Duplication |
public function testCanBeCreated() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertInstanceOf( |
|
31
|
|
|
// TemplatingController::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
|
|
View Code Duplication |
public function testHomeCanBeCreated() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertInstanceOf( |
|
43
|
|
|
TemplatingController::class, // 5.4 < php |
|
44
|
|
|
new HomeTemplatingController(new TwigEngine( |
|
45
|
|
|
new Twig_Environment(new Twig_Loader_Array(['home.html.twig' => 'Hello World!'])), |
|
46
|
|
|
new TemplateNameParser() |
|
47
|
|
|
)) |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
View Code Duplication |
public function testEmptyReturnsResponse() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->assertInstanceOf( |
|
54
|
|
|
Response::class, // 5.4 < php |
|
55
|
|
|
(new TemplatingController(new TwigEngine( |
|
56
|
|
|
new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])), |
|
57
|
|
|
new TemplateNameParser() |
|
58
|
|
|
)))->__invoke() |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
View Code Duplication |
public function testArrayReturnsResponse() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->assertInstanceOf( |
|
65
|
|
|
Response::class, // 5.4 < php |
|
66
|
|
|
(new TemplatingController(new TwigEngine( |
|
67
|
|
|
new Twig_Environment(new Twig_Loader_Array([ |
|
68
|
|
|
'index.html.twig' => '<ul>{% for item in 0 %}<li>{{ item }}</li>{% endfor %}</ul>', |
|
69
|
|
|
])), |
|
70
|
|
|
new TemplateNameParser() |
|
71
|
|
|
)))->__invoke([ // This is strange. |
|
|
|
|
|
|
72
|
|
|
'One', |
|
73
|
|
|
'Two', |
|
74
|
|
|
'Three', |
|
75
|
|
|
]) |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
// http://api.symfony.com/3.3/Symfony/Bridge/Twig/TwigEngine.html |
|
81
|
|
|
// http://api.symfony.com/3.3/Symfony/Bundle/TwigBundle/TwigEngine.html |
|
82
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.