Completed
Push — master ( 0136c1...94aca9 )
by Lukas Kahwe
03:29
created

SignerTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 56
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
rs 10
1
<?php
2
3
namespace Liip\ImagineBundle\Tests\Imagine\Cache;
4
5
use Liip\ImagineBundle\Tests\AbstractTest;
6
use Liip\ImagineBundle\Imagine\Cache\Signer;
7
8
class SignerTest extends AbstractTest
9
{
10
    public function testImplementsSignerInterface()
11
    {
12
        $rc = new \ReflectionClass('Liip\ImagineBundle\Imagine\Cache\Signer');
13
14
        $this->assertTrue($rc->implementsInterface('Liip\ImagineBundle\Imagine\Cache\SignerInterface'));
15
    }
16
17
    public function testCouldBeConstructedWithSecret()
18
    {
19
        new Signer('aSecret');
20
    }
21
22
    public function testShouldReturnShortHashOnSign()
23
    {
24
        $singer = new Signer('aSecret');
25
26
        $this->assertEquals(8, strlen($singer->sign('aPath')));
27
    }
28
29
    public function testShouldSingAndSuccessfullyCheckPathWithoutRuntimeConfig()
30
    {
31
        $singer = new Signer('aSecret');
32
33
        $this->assertTrue($singer->check($singer->sign('aPath'), 'aPath'));
34
    }
35
36
    public function testShouldSingAndSuccessfullyCheckPathWithRuntimeConfig()
37
    {
38
        $singer = new Signer('aSecret');
39
40
        $this->assertTrue($singer->check($singer->sign('aPath', array('aConfig')), 'aPath', array('aConfig')));
41
    }
42
43
    public function testShouldConvertRecursivelyToStringAllRuntimeConfigParameters()
44
    {
45
        $singer = new Signer('aSecret');
46
47
        $runtimeConfigInts = array(
48
            'foo' => 14,
49
            'bar' => array(
50
                'bar' => 15,
51
            ),
52
        );
53
54
        $runtimeConfigStrings = array(
55
            'foo' => '14',
56
            'bar' => array(
57
                'bar' => '15',
58
            ),
59
        );
60
61
        $this->assertTrue($singer->check($singer->sign('aPath', $runtimeConfigInts), 'aPath', $runtimeConfigStrings));
62
    }
63
}
64