StatementsFilterTest   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 197
Duplicated Lines 11.17 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 22
c 5
b 0
f 0
lcom 1
cbo 5
dl 22
loc 197
rs 10

22 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testByActor() 0 8 1
A testByActorWithNotIdentifiedGroup() 0 4 1
A testByVerb() 0 11 1
A testByActivity() 0 11 1
A testByRegistration() 0 7 1
A testEnableRelatedActivityFilter() 0 7 1
A testDisableRelatedActivityFilter() 0 7 1
A testEnableRelatedAgentFilter() 0 7 1
A testDisableRelatedAgentFilter() 0 7 1
A testSince() 11 11 1
A testUntil() 11 11 1
A testLimit() 0 7 1
A testIdsFormat() 0 7 1
A testExactFormat() 0 7 1
A testCanonicalFormat() 0 7 1
A testInvalidFormat() 0 4 1
A testIncludeAttachments() 0 7 1
A testExcludeAttachments() 0 7 1
A testLimitWithNegativeArgument() 0 4 1
A testAscending() 0 7 1
A testDescending() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Xabbuh\XApi\Client\Tests;
13
14
use Xabbuh\XApi\Model\Activity;
15
use Xabbuh\XApi\Model\Agent;
16
use Xabbuh\XApi\Model\Group;
17
use Xabbuh\XApi\Model\StatementsFilter;
18
use Xabbuh\XApi\Model\Verb;
19
20
/**
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
class StatementsFilterTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var StatementsFilter
27
     */
28
    private $statementsFilter;
29
30
    protected function setUp()
31
    {
32
        $this->statementsFilter = new StatementsFilter();
33
    }
34
35
    public function testByActor()
36
    {
37
        $agent = new Agent('[email protected]');
38
        $this->statementsFilter->byActor($agent);
39
        $filter = $this->statementsFilter->getFilter();
40
41
        $this->assertEquals($agent, $filter['agent']);
42
    }
43
44
    /**
45
     * @expectedException \InvalidArgumentException
46
     */
47
    public function testByActorWithNotIdentifiedGroup()
48
    {
49
        $this->statementsFilter->byActor(new Group());
50
    }
51
52
    public function testByVerb()
53
    {
54
        $verb = new Verb('http://adlnet.gov/expapi/verbs/attended');
55
        $this->statementsFilter->byVerb($verb);
56
        $filter = $this->statementsFilter->getFilter();
57
58
        $this->assertEquals(
59
            'http://adlnet.gov/expapi/verbs/attended',
60
            $filter['verb']
61
        );
62
    }
63
64
    public function testByActivity()
65
    {
66
        $activity = new Activity('8f87ccde-bb56-4c2e-ab83-44982ef22df0');
67
        $this->statementsFilter->byActivity($activity);
68
        $filter = $this->statementsFilter->getFilter();
69
70
        $this->assertEquals(
71
            '8f87ccde-bb56-4c2e-ab83-44982ef22df0',
72
            $filter['activity']
73
        );
74
    }
75
76
    public function testByRegistration()
77
    {
78
        $this->statementsFilter->byRegistration('foo');
79
        $filter = $this->statementsFilter->getFilter();
80
81
        $this->assertEquals($filter['registration'], 'foo');
82
    }
83
84
    public function testEnableRelatedActivityFilter()
85
    {
86
        $this->statementsFilter->enableRelatedActivityFilter();
87
        $filter = $this->statementsFilter->getFilter();
88
89
        $this->assertTrue($filter['related_activities']);
90
    }
91
92
    public function testDisableRelatedActivityFilter()
93
    {
94
        $this->statementsFilter->disableRelatedActivityFilter();
95
        $filter = $this->statementsFilter->getFilter();
96
97
        $this->assertFalse($filter['related_activities']);
98
    }
99
100
    public function testEnableRelatedAgentFilter()
101
    {
102
        $this->statementsFilter->enableRelatedAgentFilter();
103
        $filter = $this->statementsFilter->getFilter();
104
105
        $this->assertTrue($filter['related_agents']);
106
    }
107
108
    public function testDisableRelatedAgentFilter()
109
    {
110
        $this->statementsFilter->disableRelatedAgentFilter();
111
        $filter = $this->statementsFilter->getFilter();
112
113
        $this->assertFalse($filter['related_agents']);
114
    }
115
116 View Code Duplication
    public function testSince()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        $timestamp = \DateTime::createFromFormat(\DateTime::ISO8601, '2013-05-18T05:32:34Z');
119
        $this->statementsFilter->since($timestamp);
120
        $filter = $this->statementsFilter->getFilter();
121
122
        $this->assertEquals(
123
            '2013-05-18T05:32:34+00:00',
124
            $filter['since']
125
        );
126
    }
127
128 View Code Duplication
    public function testUntil()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
129
    {
130
        $timestamp = \DateTime::createFromFormat(\DateTime::ISO8601, '2013-05-18T05:32:34Z');
131
        $this->statementsFilter->until($timestamp);
132
        $filter = $this->statementsFilter->getFilter();
133
134
        $this->assertEquals(
135
            '2013-05-18T05:32:34+00:00',
136
            $filter['until']
137
        );
138
    }
139
140
    public function testLimit()
141
    {
142
        $this->statementsFilter->limit(10);
143
        $filter = $this->statementsFilter->getFilter();
144
145
        $this->assertEquals(10, $filter['limit']);
146
    }
147
148
    public function testIdsFormat()
149
    {
150
        $this->statementsFilter->format('ids');
151
        $filter = $this->statementsFilter->getFilter();
152
153
        $this->assertEquals('ids', $filter['format']);
154
    }
155
156
    public function testExactFormat()
157
    {
158
        $this->statementsFilter->format('exact');
159
        $filter = $this->statementsFilter->getFilter();
160
161
        $this->assertEquals('exact', $filter['format']);
162
    }
163
164
    public function testCanonicalFormat()
165
    {
166
        $this->statementsFilter->format('canonical');
167
        $filter = $this->statementsFilter->getFilter();
168
169
        $this->assertEquals('canonical', $filter['format']);
170
    }
171
172
    /**
173
     * @expectedException \InvalidArgumentException
174
     */
175
    public function testInvalidFormat()
176
    {
177
        $this->statementsFilter->format('minimal');
178
    }
179
180
    public function testIncludeAttachments()
181
    {
182
        $this->statementsFilter->includeAttachments();
183
        $filter = $this->statementsFilter->getFilter();
184
185
        $this->assertTrue($filter['attachments']);
186
    }
187
188
    public function testExcludeAttachments()
189
    {
190
        $this->statementsFilter->excludeAttachments();
191
        $filter = $this->statementsFilter->getFilter();
192
193
        $this->assertFalse($filter['attachments']);
194
    }
195
196
    /**
197
     * @expectedException \InvalidArgumentException
198
     */
199
    public function testLimitWithNegativeArgument()
200
    {
201
        $this->statementsFilter->limit(-1);
202
    }
203
204
    public function testAscending()
205
    {
206
        $this->statementsFilter->ascending();
207
        $filter = $this->statementsFilter->getFilter();
208
209
        $this->assertEquals('True', $filter['ascending']);
210
    }
211
212
    public function testDescending()
213
    {
214
        $this->statementsFilter->descending();
215
        $filter = $this->statementsFilter->getFilter();
216
217
        $this->assertEquals('False', $filter['ascending']);
218
    }
219
}
220