AgentProfileApiClientTest::createAgentProfile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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