Completed
Push — master ( 2b67c6...21b23e )
by Christian
02:46
created

SubStatementSpec   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 13
dl 0
loc 112
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_is_an_xapi_object() 0 9 1
B it_is_different_from_another_sub_statement_if_contexts_differ() 0 31 1
A it_rejects_to_hold_another_sub_statement_as_object() 0 9 1
A it_returns_a_new_instance_with_actor() 0 9 1
A it_returns_a_new_instance_with_verb() 0 9 1
A it_returns_a_new_instance_with_object() 0 9 1
A it_returns_a_new_instance_with_result() 0 9 1
A it_returns_a_new_instance_with_context() 0 9 1
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\Result;
23
use Xabbuh\XApi\Model\StatementReference;
24
use Xabbuh\XApi\Model\SubStatement;
25
use Xabbuh\XApi\Model\Verb;
26
27
class SubStatementSpec extends ObjectBehavior
28
{
29
    function let()
30
    {
31
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
32
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
33
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
34
        $this->beConstructedWith($actor, $verb, $object);
35
    }
36
37
    function it_is_an_xapi_object()
38
    {
39
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
40
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
41
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
42
        $this->beConstructedWith($actor, $verb, $object);
43
44
        $this->shouldHaveType('Xabbuh\XApi\Model\Object');
45
    }
46
47
    function it_is_different_from_another_sub_statement_if_contexts_differ()
48
    {
49
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
50
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
51
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
52
        $this->beConstructedWith($actor, $verb, $object, null, new Context());
53
54
        $subStatement = new SubStatement($actor, $verb, $object);
55
56
        $this->equals($subStatement)->shouldReturn(false);
57
58
        $context = new Context();
59
        $context = $context->withRegistration('16fd2706-8baf-433b-82eb-8c7fada847da')
60
            ->withInstructor(new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')))
61
            ->withTeam(new Group(InverseFunctionalIdentifier::withMbox('mailto:[email protected]')))
62
            ->withContextActivities(new ContextActivities(
63
                array(new Activity('http://tincanapi.com/conformancetest/activityid')),
64
                array(new Activity('http://tincanapi.com/conformancetest/activityid')),
65
                array(new Activity('http://tincanapi.com/conformancetest/activityid')),
66
                array(new Activity('http://tincanapi.com/conformancetest/activityid'))
67
            ))
68
            ->withRevision('test')
69
            ->withPlatform('test')
70
            ->withLanguage('en-US')
71
            ->withStatement(new StatementReference('16fd2706-8baf-433b-82eb-8c7fada847da'))
72
            ->withExtensions(new Extensions(array()))
73
        ;
74
        $subStatement = new SubStatement($actor, $verb, $object, null, $context);
75
76
        $this->equals($subStatement)->shouldReturn(false);
77
    }
78
79
    function it_rejects_to_hold_another_sub_statement_as_object()
80
    {
81
        $actor = new Agent(InverseFunctionalIdentifier::withMbox('mailto:[email protected]'));
82
        $verb = new Verb('http://tincanapi.com/conformancetest/verbid', array('en-US' => 'test'));
83
        $object = new Activity('http://tincanapi.com/conformancetest/activityid');
84
        $subStatement = new SubStatement($actor, $verb, $object);
85
86
        $this->shouldThrow('\InvalidArgumentException')->during('__construct', array($actor, $verb, $subStatement));
87
    }
88
89
    public function it_returns_a_new_instance_with_actor()
90
    {
91
        $actor = new Agent(InverseFunctionalIdentifier::withOpenId('http://openid.tincanapi.com'));
92
        $subStatement = $this->withActor($actor);
93
94
        $subStatement->shouldNotBe($this);
95
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
96
        $subStatement->getActor()->shouldReturn($actor);
97
    }
98
99
    public function it_returns_a_new_instance_with_verb()
100
    {
101
        $verb = new Verb('http://adlnet.gov/expapi/verbs/voided');
102
        $subStatement = $this->withVerb($verb);
103
104
        $subStatement->shouldNotBe($this);
105
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
106
        $subStatement->getVerb()->shouldReturn($verb);
107
    }
108
109
    public function it_returns_a_new_instance_with_object()
110
    {
111
        $statementReference = new StatementReference('12345678-1234-5678-8234-567812345678');
112
        $subStatement = $this->withObject($statementReference);
113
114
        $subStatement->shouldNotBe($this);
115
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
116
        $subStatement->getObject()->shouldReturn($statementReference);
117
    }
118
119
    public function it_returns_a_new_instance_with_result()
120
    {
121
        $result = new Result();
122
        $subStatement = $this->withResult($result);
123
124
        $subStatement->shouldNotBe($this);
125
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
126
        $subStatement->getResult()->shouldReturn($result);
127
    }
128
129
    public function it_returns_a_new_instance_with_context()
130
    {
131
        $context = new Context();
132
        $subStatement = $this->withContext($context);
133
134
        $subStatement->shouldNotBe($this);
135
        $subStatement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\SubStatement');
136
        $subStatement->getContext()->shouldReturn($context);
137
    }
138
}
139