StateApiClientTest::testCreateOrUpdateDocument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 20
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 20
loc 20
rs 9.4285
cc 1
eloc 14
nc 1
nop 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 Xabbuh\XApi\Client\Tests\Api;
13
14
use Xabbuh\XApi\Client\Api\StateApiClient;
15
use Xabbuh\XApi\DataFixtures\DocumentFixtures;
16
use Xabbuh\XApi\Model\Activity;
17
use Xabbuh\XApi\Model\Agent;
18
use Xabbuh\XApi\Model\State;
19
use Xabbuh\XApi\Serializer\ActorSerializer;
20
use Xabbuh\XApi\Serializer\DocumentDataSerializer;
21
22
/**
23
 * @author Christian Flothmann <[email protected]>
24
 */
25
class StateApiClientTest extends ApiClientTest
26
{
27
    /**
28
     * @var StateApiClient
29
     */
30
    private $client;
31
32 View Code Duplication
    protected function setUp()
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...
33
    {
34
        parent::setUp();
35
        $this->client = new StateApiClient(
36
            $this->requestHandler,
37
            '1.0.1',
38
            new DocumentDataSerializer($this->serializer),
39
            new ActorSerializer($this->serializer)
40
        );
41
    }
42
43 View Code Duplication
    public function testCreateOrUpdateDocument()
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...
44
    {
45
        $document = DocumentFixtures::getStateDocument();
46
47
        $this->validateStoreApiCall(
48
            'post',
49
            'activities/state',
50
            array(
51
                'activityId' => 'activity-id',
52
                'agent' => 'agent-as-json',
53
                'stateId' => 'state-id',
54
            ),
55
            204,
56
            '',
57
            $document->getData(),
58
            array(array('data' => $document->getState()->getActor(), 'result' => 'agent-as-json'))
59
        );
60
61
        $this->client->createOrUpdateDocument($document);
62
    }
63
64 View Code Duplication
    public function testCreateOrReplaceDocument()
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...
65
    {
66
        $document = DocumentFixtures::getStateDocument();
67
68
        $this->validateStoreApiCall(
69
            'put',
70
            'activities/state',
71
            array(
72
                'activityId' => 'activity-id',
73
                'agent' => 'agent-as-json',
74
                'stateId' => 'state-id',
75
            ),
76
            204,
77
            '',
78
            $document->getData(),
79
            array(array('data' => $document->getState()->getActor(), 'result' => 'agent-as-json'))
80
        );
81
82
        $this->client->createOrReplaceDocument($document);
83
    }
84
85 View Code Duplication
    public function testDeleteDocument()
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...
86
    {
87
        $state = $this->createState();
88
89
        $this->validateDeleteDocumentCall(
90
            'activities/state',
91
            array(
92
                'activityId' => 'activity-id',
93
                'agent' => 'agent-as-json',
94
                'stateId' => 'state-id',
95
            ),
96
            array(array('data' => $state->getActor(), 'result' => 'agent-as-json'))
97
        );
98
99
        $this->client->deleteDocument($state);
100
    }
101
102 View Code Duplication
    public function testGetDocument()
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...
103
    {
104
        $document = DocumentFixtures::getStateDocument();
105
        $state = $document->getState();
106
107
        $this->validateRetrieveApiCall(
108
            'get',
109
            'activities/state',
110
            array(
111
                'activityId' => 'activity-id',
112
                'agent' => 'agent-as-json',
113
                'stateId' => 'state-id',
114
            ),
115
            200,
116
            'DocumentData',
117
            $document->getData(),
118
            array(array('data' => $state->getActor(), 'result' => 'agent-as-json'))
119
        );
120
121
        $document = $this->client->getDocument($state);
122
123
        $this->assertInstanceOf('Xabbuh\XApi\Model\StateDocument', $document);
124
        $this->assertEquals($state, $document->getState());
125
    }
126
127
    private function createState()
128
    {
129
        $agent = new Agent('mailto:[email protected]');
130
        $activity = new Activity('activity-id');
131
        $state = new State($activity, $agent, 'state-id');
132
133
        return $state;
134
    }
135
}
136