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