Completed
Push — feature/service-wrapper-for-sw... ( faf928...5dac9b )
by Samuel
13:45 queued 01:09
created

XDynamicKeyTest::testResolveRefNotExistingFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 22
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
dl 22
loc 22
rs 9.2
c 2
b 0
f 2
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
/**
3
 * validate XDynamicKey
4
 */
5
6
namespace Graviton\GeneratorBundle\Tests\Generator\ResourceGenerator;
7
8
use Graviton\GeneratorBundle\Generator\ResourceGenerator\XDynamicKey;
9
10
/**
11
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
12
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
13
 * @link     http://swisscom.ch
14
 */
15
class XDynamicKeyTest extends \PHPUnit_Framework_TestCase
16
{
17
18
    /**
19
     * test if it does resolve
20
     *
21
     * @return void
22
     */
23 View Code Duplication
    public function testResolveRef()
24
    {
25
        $c = $this->getMockBuilder('ClassC')
26
            ->setMethods(array('getId'))
27
            ->getMock();
28
        $c->method('getId')
29
            ->willReturn('someRandomId');
30
31
        $b = $this->getMockBuilder('ClassB')
32
            ->setMethods(array('getRef'))
33
            ->getMock();
34
        $b->method('getRef')
35
            ->willReturn($c);
36
37
        $a = $this->getMockBuilder('ClassA')
38
            ->setMethods(array('getB'))
39
            ->getMock();
40
        $a->method('getB')
41
            ->willReturn($b);
42
43
        $this->assertArrayHasKey('someRandomId', XDynamicKey::resolveRef([$a], 'b.ref'));
44
    }
45
46
    /**
47
     * test only one field in method variable
48
     *
49
     * @return void
50
     */
51
    public function testResolveRefOne()
52
    {
53
        $b = $this->getMockBuilder('ClassB')
54
            ->setMethods(array('getId'))
55
            ->getMock();
56
        $b->method('getId')
57
            ->willReturn('someRandomId');
58
59
        $a = $this->getMockBuilder('ClassA')
60
            ->setMethods(array('getRef'))
61
            ->getMock();
62
        $a->method('getRef')
63
            ->willReturn($b);
64
65
        $this->assertArrayHasKey('someRandomId', XDynamicKey::resolveRef([$a], 'ref'));
66
    }
67
68
    /**
69
     * test empty vars
70
     *
71
     * @return void
72
     */
73
    public function testResolveRefMethodEmptyVars()
74
    {
75
        $this->assertEmpty(XDynamicKey::resolveRef([], ''));
76
    }
77
78
    /**
79
     * test if it behaves correctly if the methods don't exist
80
     *
81
     * @expectedException Graviton\ExceptionBundle\Exception\XDynamicKeyException
82
     * @return void
83
     */
84 View Code Duplication
    public function testResolveRefNotExistingFields()
85
    {
86
        $c = $this->getMockBuilder('ClassC')
87
            ->setMethods(array('getId'))
88
            ->getMock();
89
        $c->method('getId')
90
            ->willReturn('someRandomId');
91
92
        $b = $this->getMockBuilder('ClassB')
93
            ->setMethods(array('getRef'))
94
            ->getMock();
95
        $b->method('getRef')
96
            ->willReturn($c);
97
98
        $a = $this->getMockBuilder('ClassA')
99
            ->setMethods(array('getB'))
100
            ->getMock();
101
        $a->method('getB')
102
            ->willReturn($b);
103
104
        XDynamicKey::resolveRef([$a], 'some.thing.that.doesnt.exist');
105
    }
106
}
107