Completed
Pull Request — master (#27)
by Christian
02:36
created

createEmptyInteraction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace spec\Xabbuh\XApi\Model\Interaction;
4
5
use Xabbuh\XApi\Model\Interaction\InteractionComponent;
6
use Xabbuh\XApi\Model\Interaction\MatchingInteractionDefinition;
7
8
class MatchingInteractionDefinitionSpec extends InteractionDefinitionSpec
9
{
10
    public function it_returns_a_new_instance_with_source()
11
    {
12
        $source = array(new InteractionComponent('test'));
13
        $interaction = $this->withSource($source);
14
15
        $this->getSource()->shouldBeNull();
16
17
        $interaction->shouldNotBe($this);
18
        $interaction->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Interaction\MatchingInteractionDefinition');
19
        $interaction->getSource()->shouldReturn($source);
20
    }
21
22
    public function it_returns_a_new_instance_with_target()
23
    {
24
        $target = array(new InteractionComponent('test'));
25
        $interaction = $this->withTarget($target);
26
27
        $this->getTarget()->shouldBeNull();
28
29
        $interaction->shouldNotBe($this);
30
        $interaction->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Interaction\MatchingInteractionDefinition');
31
        $interaction->getTarget()->shouldReturn($target);
32
    }
33
34
    function it_is_not_equal_if_only_other_interaction_has_source()
35
    {
36
        $interaction = $this->createEmptyInteraction();
37
        $interaction = $interaction->withSource(array(new InteractionComponent('test')));
38
39
        $this->equals($interaction)->shouldReturn(false);
40
    }
41
42
    function it_is_not_equal_if_only_this_interaction_has_source()
43
    {
44
        $this->beConstructedWith(null, null, null, null, null, array(new InteractionComponent('test')));
45
46
        $this->equals($this->createEmptyInteraction())->shouldReturn(false);
47
    }
48
49
    function it_is_not_equal_if_number_of_source_differs()
50
    {
51
        $this->beConstructedWith(null, null, null, null, null, array(new InteractionComponent('test')));
52
53
        $interaction = $this->createEmptyInteraction();
54
        $interaction = $interaction->withSource(array(new InteractionComponent('test'), new InteractionComponent('foo')));
55
56
        $this->equals($interaction)->shouldReturn(false);
57
    }
58
59
    function it_is_not_equal_if_source_differ()
60
    {
61
        $this->beConstructedWith(null, null, null, null, null, array(new InteractionComponent('foo')));
62
63
        $interaction = $this->createEmptyInteraction();
64
        $interaction = $interaction->withSource(array(new InteractionComponent('bar')));
65
66
        $this->equals($interaction)->shouldReturn(false);
67
    }
68
69
    function it_is_equal_if_sources_are_equal()
70
    {
71
        $this->beConstructedWith(null, null, null, null, null, array(new InteractionComponent('test')));
72
73
        $interaction = $this->createEmptyInteraction();
74
        $interaction = $interaction->withSource(array(new InteractionComponent('test')));
75
76
        $this->equals($interaction)->shouldReturn(true);
77
    }
78
79
    function it_is_not_equal_if_only_other_interaction_has_target()
80
    {
81
        $interaction = $this->createEmptyInteraction();
82
        $interaction = $interaction->withTarget(array(new InteractionComponent('test')));
83
84
        $this->equals($interaction)->shouldReturn(false);
85
    }
86
87
    function it_is_not_equal_if_only_this_interaction_has_target()
88
    {
89
        $this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
90
91
        $this->equals($this->createEmptyInteraction())->shouldReturn(false);
92
    }
93
94
    function it_is_not_equal_if_number_of_target_differs()
95
    {
96
        $this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
97
98
        $interaction = $this->createEmptyInteraction();
99
        $interaction = $interaction->withTarget(array(new InteractionComponent('test'), new InteractionComponent('foo')));
100
101
        $this->equals($interaction)->shouldReturn(false);
102
    }
103
104
    function it_is_not_equal_if_target_differ()
105
    {
106
        $this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('foo')));
107
108
        $interaction = $this->createEmptyInteraction();
109
        $interaction = $interaction->withTarget(array(new InteractionComponent('bar')));
110
111
        $this->equals($interaction)->shouldReturn(false);
112
    }
113
114
    function it_is_equal_if_targets_are_equal()
115
    {
116
        $this->beConstructedWith(null, null, null, null, null, null, array(new InteractionComponent('test')));
117
118
        $interaction = $this->createEmptyInteraction();
119
        $interaction = $interaction->withTarget(array(new InteractionComponent('test')));
120
121
        $this->equals($interaction)->shouldReturn(true);
122
    }
123
124
    protected function createEmptyInteraction()
125
    {
126
        return new MatchingInteractionDefinition();
127
    }
128
}
129