testCreateOrUpdateDocument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 18
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 18
loc 18
rs 9.4285
cc 1
eloc 12
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\ActivityProfileApiClient;
15
use Xabbuh\XApi\DataFixtures\DocumentFixtures;
16
use Xabbuh\XApi\Model\Activity;
17
use Xabbuh\XApi\Model\ActivityProfile;
18
use Xabbuh\XApi\Serializer\DocumentDataSerializer;
19
20
/**
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
class ActivityProfileApiClientTest extends ApiClientTest
24
{
25
    /**
26
     * @var ActivityProfileApiClient
27
     */
28
    private $client;
29
30
    protected function setUp()
31
    {
32
        parent::setUp();
33
        $this->client = new ActivityProfileApiClient(
34
            $this->requestHandler,
35
            '1.0.1',
36
            new DocumentDataSerializer($this->serializer)
37
        );
38
    }
39
40 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...
41
    {
42
        $document = DocumentFixtures::getActivityProfileDocument();
43
44
        $this->validateStoreApiCall(
45
            'post',
46
            'activities/profile',
47
            array(
48
                'activityId' => 'activity-id',
49
                'profileId' => 'profile-id',
50
            ),
51
            204,
52
            '',
53
            $document->getData()
54
        );
55
56
        $this->client->createOrUpdateDocument($document);
57
    }
58
59 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...
60
    {
61
        $document = DocumentFixtures::getActivityProfileDocument();
62
63
        $this->validateStoreApiCall(
64
            'put',
65
            'activities/profile',
66
            array(
67
                'activityId' => 'activity-id',
68
                'profileId' => 'profile-id',
69
            ),
70
            204,
71
            '',
72
            $document->getData()
73
        );
74
75
        $this->client->createOrReplaceDocument($document);
76
    }
77
78
    public function testDeleteDocument()
79
    {
80
        $activityProfile = $this->createActivityProfile();
81
82
        $this->validateDeleteDocumentCall('activities/profile', array(
83
            'activityId' => 'activity-id',
84
            'profileId' => 'profile-id',
85
        ));
86
87
        $this->client->deleteDocument($activityProfile);
88
    }
89
90
    public function testGetDocument()
91
    {
92
        $document = DocumentFixtures::getActivityProfileDocument();
93
        $activityProfile = $document->getActivityProfile();
94
95
        $this->validateRetrieveApiCall(
96
            'get',
97
            'activities/profile',
98
            array(
99
                'activityId' => 'activity-id',
100
                'profileId' => 'profile-id',
101
            ),
102
            200,
103
            'DocumentData',
104
            $document->getData()
105
        );
106
107
        $document = $this->client->getDocument($activityProfile);
108
109
        $this->assertInstanceOf('Xabbuh\XApi\Model\ActivityProfileDocument', $document);
110
        $this->assertEquals($activityProfile, $document->getActivityProfile());
111
    }
112
113
    private function createActivityProfile()
114
    {
115
        $activity = new Activity('activity-id');
116
        $activityProfile = new ActivityProfile('profile-id', $activity);
117
118
        return $activityProfile;
119
    }
120
}
121