Completed
Push — master ( d19327...2d2cc6 )
by Christian
08:11 queued 05:46
created

StatementFactorySpec::it_can_reset_the_stored()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace spec\Xabbuh\XApi\Model;
4
5
use PhpSpec\ObjectBehavior;
6
use Xabbuh\XApi\Model\Activity;
7
use Xabbuh\XApi\Model\Agent;
8
use Xabbuh\XApi\Model\Context;
9
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
10
use Xabbuh\XApi\Model\Result;
11
use Xabbuh\XApi\Model\Verb;
12
13
class StatementFactorySpec extends ObjectBehavior
14
{
15
    function it_creates_a_statement()
16
    {
17
        $this->withActor(new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')));
18
        $this->withVerb(new Verb('http://tincanapi.com/conformancetest/verbid'));
19
        $this->withObject(new Activity('http://tincanapi.com/conformancetest/activityid'));
20
21
        $this->createStatement()->shouldBeAnInstanceOf('\Xabbuh\Xapi\Model\Statement');
22
    }
23
24
    function it_configures_all_statement_properties()
25
    {
26
        $id = '39e24cc4-69af-4b01-a824-1fdc6ea8a3af';
27
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
28
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid');
29
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
30
        $result = new Result();
31
        $context = new Context();
32
        $created = new \DateTime('2014-07-23T12:34:02-05:00');
33
        $stored = new \DateTime('2014-07-24T12:34:02-05:00');
34
        $authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
35
36
        $this->withId($id);
37
        $this->withActor($actor);
38
        $this->withVerb($verb);
39
        $this->withObject($object);
40
        $this->withResult($result);
41
        $this->withContext($context);
42
        $this->withCreated($created);
43
        $this->withStored($stored);
44
        $this->withAuthority($authority);
45
46
        $statement = $this->createStatement();
47
48
        $statement->getId()->shouldBe($id);
49
        $statement->getActor()->shouldBe($actor);
50
        $statement->getVerb()->shouldBe($verb);
51
        $statement->getObject()->shouldBe($object);
52
        $statement->getResult()->shouldBe($result);
53
        $statement->getContext()->shouldBe($context);
54
        $statement->getCreated()->shouldBe($created);
55
        $statement->getStored()->shouldBe($stored);
56
        $statement->getAuthority()->shouldBe($authority);
57
    }
58
59
    function it_throws_an_exception_when_a_statement_is_created_without_an_actor()
60
    {
61
        $this->withVerb(new Verb('http://tincanapi.com/conformancetest/verbid'));
62
        $this->withObject(new Activity('http://tincanapi.com/conformancetest/activityid'));
63
64
        $this->shouldThrow('\Xabbuh\XApi\Model\Exception\InvalidStateException')->during('createStatement');
65
    }
66
67
    function it_throws_an_exception_when_a_statement_is_created_without_a_verb()
68
    {
69
        $this->withActor(new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')));
70
        $this->withObject(new Activity('http://tincanapi.com/conformancetest/activityid'));
71
72
        $this->shouldThrow('\Xabbuh\XApi\Model\Exception\InvalidStateException')->during('createStatement');
73
    }
74
75
    function it_throws_an_exception_when_a_statement_is_created_without_an_object()
76
    {
77
        $this->withActor(new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')));
78
        $this->withVerb(new Verb('http://tincanapi.com/conformancetest/verbid'));
79
80
        $this->shouldThrow('\Xabbuh\XApi\Model\Exception\InvalidStateException')->during('createStatement');
81
    }
82
83
    function it_can_reset_the_result()
84
    {
85
        $this->configureAllProperties();
86
        $this->withResult(null);
87
        $statement = $this->createStatement();
88
89
        $statement->getResult()->shouldReturn(null);
90
    }
91
92
    function it_can_reset_the_context()
93
    {
94
        $this->configureAllProperties();
95
        $this->withContext(null);
96
        $statement = $this->createStatement();
97
98
        $statement->getContext()->shouldReturn(null);
99
    }
100
101
    function it_can_reset_the_created()
102
    {
103
        $this->configureAllProperties();
104
        $this->withCreated(null);
105
        $statement = $this->createStatement();
106
107
        $statement->getCreated()->shouldReturn(null);
108
    }
109
110
    function it_can_reset_the_stored()
111
    {
112
        $this->configureAllProperties();
113
        $this->withStored(null);
114
        $statement = $this->createStatement();
115
116
        $statement->getStored()->shouldReturn(null);
117
    }
118
119
    function it_can_reset_the_authority()
120
    {
121
        $this->configureAllProperties();
122
        $this->withAuthority(null);
123
        $statement = $this->createStatement();
124
125
        $statement->getAuthority()->shouldReturn(null);
126
    }
127
128
    private function configureAllProperties()
129
    {
130
        $id = '39e24cc4-69af-4b01-a824-1fdc6ea8a3af';
131
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
132
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid');
133
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
134
        $result = new Result();
135
        $context = new Context();
136
        $created = new \DateTime('2014-07-23T12:34:02-05:00');
137
        $stored = new \DateTime('2014-07-24T12:34:02-05:00');
138
        $authority = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
139
140
        $this->withId($id);
141
        $this->withActor($actor);
142
        $this->withVerb($verb);
143
        $this->withObject($object);
144
        $this->withResult($result);
145
        $this->withContext($context);
146
        $this->withCreated($created);
147
        $this->withStored($stored);
148
        $this->withAuthority($authority);
149
    }
150
}
151