|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Asmaster\EquipTwig\Tests\Loader; |
|
4
|
|
|
|
|
5
|
|
|
use Asmaster\EquipTwig\Exception\LoaderException; |
|
6
|
|
|
use Asmaster\EquipTwig\Loader\FilesystemLoader; |
|
7
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
|
8
|
|
|
|
|
9
|
|
|
class FilesystemLoaderTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testEmptyConstructor() |
|
12
|
|
|
{ |
|
13
|
|
|
$path = '/templates'; |
|
14
|
|
|
$fileExtensions = ['html.twig']; |
|
15
|
|
|
|
|
16
|
|
|
$loader = new FilesystemLoader( |
|
17
|
|
|
$path, |
|
18
|
|
|
$fileExtensions |
|
19
|
|
|
); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertEquals($path, $loader->getPath()); |
|
22
|
|
|
$this->assertEquals($fileExtensions, $loader->getFileExtensions()); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testGetSource() |
|
26
|
|
|
{ |
|
27
|
|
|
$path = __DIR__.'/../Asset/templates'; |
|
28
|
|
|
$template = 'sugar.html.twig'; |
|
29
|
|
|
|
|
30
|
|
|
$loader = new FilesystemLoader($path); |
|
31
|
|
|
$source = $loader->getSource($template); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertEquals("sugar\n", $source); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testGetCacheKey() |
|
37
|
|
|
{ |
|
38
|
|
|
$template = 'sugar.html.twig'; |
|
39
|
|
|
|
|
40
|
|
|
$path = __DIR__.'/../Asset/templates'; |
|
41
|
|
|
$realPath = realpath($path . DIRECTORY_SEPARATOR . $template); |
|
42
|
|
|
|
|
43
|
|
|
$loader = new FilesystemLoader($path); |
|
44
|
|
|
$cacheKey = $loader->getCacheKey($template); |
|
45
|
|
|
$source = $loader->getSource($template); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
$this->assertEquals($realPath, $cacheKey); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testIsFresh() |
|
51
|
|
|
{ |
|
52
|
|
|
$template = 'sugar.html.twig'; |
|
53
|
|
|
$path = __DIR__.'/../Asset/templates'; |
|
54
|
|
|
|
|
55
|
|
|
$loader = new FilesystemLoader($path); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertTrue($loader->isFresh($template, time())); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testExists() |
|
61
|
|
|
{ |
|
62
|
|
|
$template = 'sugar.html.twig'; |
|
63
|
|
|
$path = __DIR__.'/../Asset/templates'; |
|
64
|
|
|
|
|
65
|
|
|
$loader = new FilesystemLoader($path); |
|
66
|
|
|
$exists = $loader->exists($template); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertTrue($exists); |
|
69
|
|
|
|
|
70
|
|
|
$loader = new FilesystemLoader($path); |
|
71
|
|
|
$source = $loader->getSource($template); |
|
|
|
|
|
|
72
|
|
|
$exists = $loader->exists($template); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertTrue($exists); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testFindTemplateException() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->expectException(LoaderException::class); |
|
80
|
|
|
|
|
81
|
|
|
$loader = new FilesystemLoader('/templates'); |
|
82
|
|
|
$loader->getSource('nowhere.html.twig'); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.