Completed
Push — master ( 2bedd9...b42c0c )
by Christian
02:23
created

SubStatementSpec   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 15

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 15
dl 0
loc 112
rs 9.1666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Xabbuh\XApi\Model;
13
14
use PhpSpec\ObjectBehavior;
15
use Xabbuh\XApi\Model\Activity;
16
use Xabbuh\XApi\Model\Agent;
17
use Xabbuh\XApi\Model\Context;
18
use Xabbuh\XApi\Model\ContextActivities;
19
use Xabbuh\XApi\Model\Extensions;
20
use Xabbuh\XApi\Model\Group;
21
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
22
use Xabbuh\XApi\Model\LanguageMap;
23
use Xabbuh\XApi\Model\Result;
24
use Xabbuh\XApi\Model\StatementId;
25
use Xabbuh\XApi\Model\StatementReference;
26
use Xabbuh\XApi\Model\SubStatement;
27
use Xabbuh\XApi\Model\Verb;
28
29
class SubStatementSpec extends ObjectBehavior
30
{
31
    function let()
32
    {
33
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
34
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', LanguageMap::create(array('en-US' => 'test')));
35
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
36
        $this->beConstructedWith($actor, $verb, $object);
37
    }
38
39
    function it_is_an_xapi_object()
40
    {
41
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
42
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', LanguageMap::create(array('en-US' => 'test')));
43
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
44
        $this->beConstructedWith($actor, $verb, $object);
45
46
        $this->shouldHaveType('Xabbuh\XApi\Model\Object');
47
    }
48
49
    function it_is_different_from_another_sub_statement_if_contexts_differ()
50
    {
51
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
52
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', LanguageMap::create(array('en-US' => 'test')));
53
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
54
        $this->beConstructedWith($actor, $verb, $object, null, new Context());
55
56
        $subStatement = new SubStatement($actor, $verb, $object);
57
58
        $this->equals($subStatement)->shouldReturn(false);
59
60
        $context = new Context();
61
        $context = $context->withRegistration('16fd2706-8baf-433b-82eb-8c7fada847da')
62
            ->withInstructor(new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')))
63
            ->withTeam(new Group(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')))
64
            ->withContextActivities(new ContextActivities(
65
                array(new Activity('http://tincanapi.com/conformancetest/activityid')),
66
                array(new Activity('http://tincanapi.com/conformancetest/activityid')),
67
                array(new Activity('http://tincanapi.com/conformancetest/activityid')),
68
                array(new Activity('http://tincanapi.com/conformancetest/activityid'))
69
            ))
70
            ->withRevision('test')
71
            ->withPlatform('test')
72
            ->withLanguage('en-US')
73
            ->withStatement(new StatementReference(StatementId::fromString('16fd2706-8baf-433b-82eb-8c7fada847da')))
74
            ->withExtensions(new Extensions(array()))
75
        ;
76
        $subStatement = new SubStatement($actor, $verb, $object, null, $context);
77
78
        $this->equals($subStatement)->shouldReturn(false);
79
    }
80
81
    function it_rejects_to_hold_another_sub_statement_as_object()
82
    {
83
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
84
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', LanguageMap::create(array('en-US' => 'test')));
85
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
86
        $subStatement = new SubStatement($actor, $verb, $object);
87
88
        $this->shouldThrow('\InvalidArgumentException')->during('__construct', array($actor, $verb, $subStatement));
89
    }
90
91
    public function it_returns_a_new_instance_with_actor()
92
    {
93
        $actor = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
94
        $subStatement = $this->withActor($actor);
95
96
        $subStatement->shouldNotBe($this);
97
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
98
        $subStatement->getActor()->shouldReturn($actor);
99
    }
100
101
    public function it_returns_a_new_instance_with_verb()
102
    {
103
        $verb = new Verb('http://adlnet.gov/expapi/verbs/voided');
104
        $subStatement = $this->withVerb($verb);
105
106
        $subStatement->shouldNotBe($this);
107
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
108
        $subStatement->getVerb()->shouldReturn($verb);
109
    }
110
111
    public function it_returns_a_new_instance_with_object()
112
    {
113
        $statementReference = new StatementReference(StatementId::fromString('12345678-1234-5678-8234-567812345678'));
114
        $subStatement = $this->withObject($statementReference);
115
116
        $subStatement->shouldNotBe($this);
117
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
118
        $subStatement->getObject()->shouldReturn($statementReference);
119
    }
120
121
    public function it_returns_a_new_instance_with_result()
122
    {
123
        $result = new Result();
124
        $subStatement = $this->withResult($result);
125
126
        $subStatement->shouldNotBe($this);
127
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
128
        $subStatement->getResult()->shouldReturn($result);
129
    }
130
131
    public function it_returns_a_new_instance_with_context()
132
    {
133
        $context = new Context();
134
        $subStatement = $this->withContext($context);
135
136
        $subStatement->shouldNotBe($this);
137
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
138
        $subStatement->getContext()->shouldReturn($context);
139
    }
140
}
141