Completed
Push — master ( 860392...c518de )
by Alex
02:22
created

FilesystemLoaderTest::testGetCacheKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
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);
0 ignored issues
show
Unused Code introduced by
$source is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
$source is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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