Passed
Push — master ( 3c32e6...6d1be7 )
by Adam
02:49
created

ApplicationsTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 62
dl 0
loc 121
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetAllTags() 0 17 3
A testRenameApplication() 0 12 1
A testCreateTag() 0 12 1
A testGetApplications() 0 17 3
A testGetApplication() 0 14 2
A testDeleteTag() 0 12 1
1
<?php
2
3
namespace AcquiaCloudApi\Tests\Endpoints;
4
5
use AcquiaCloudApi\Tests\CloudApiTestCase;
6
use AcquiaCloudApi\Endpoints\Applications;
7
8
class ApplicationsTest extends CloudApiTestCase
9
{
10
11
    protected $properties = [
12
    'uuid',
13
    'name',
14
    'hosting',
15
    'subscription',
16
    'organization',
17
    'type',
18
    'flags',
19
    'status',
20
    'links'
21
    ];
22
23
    protected $tagProperties = [
24
        'name',
25
        'color',
26
        'context',
27
        'links'
28
    ];
29
30
    public function testGetApplications()
31
    {
32
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Applications/getAllApplications.json');
33
        $client = $this->getMockClient($response);
34
35
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
36
        $application = new Applications($client);
37
        $result = $application->getAll();
38
39
        $this->assertInstanceOf('\ArrayObject', $result);
40
        $this->assertInstanceOf('\AcquiaCloudApi\Response\ApplicationsResponse', $result);
41
42
        foreach ($result as $record) {
43
            $this->assertInstanceOf('\AcquiaCloudApi\Response\ApplicationResponse', $record);
44
45
            foreach ($this->properties as $property) {
46
                $this->assertObjectHasAttribute($property, $record);
47
            }
48
        }
49
    }
50
51
    public function testGetApplication()
52
    {
53
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Applications/getApplication.json');
54
        $client = $this->getMockClient($response);
55
56
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
57
        $application = new Applications($client);
58
        $result = $application->get('8ff6c046-ec64-4ce4-bea6-27845ec18600');
59
60
        $this->assertNotInstanceOf('\AcquiaCloudApi\Response\ApplicationsResponse', $result);
61
        $this->assertInstanceOf('\AcquiaCloudApi\Response\ApplicationResponse', $result);
62
63
        foreach ($this->properties as $property) {
64
            $this->assertObjectHasAttribute($property, $result);
65
        }
66
    }
67
68
    public function testRenameApplication()
69
    {
70
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Applications/renameApplication.json');
71
        $client = $this->getMockClient($response);
72
73
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
74
        $application = new Applications($client);
75
        $result = $application->rename('8ff6c046-ec64-4ce4-bea6-27845ec18600', "My application's new name");
76
77
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
78
79
        $this->assertEquals('Application renamed.', $result->message);
80
    }
81
82
    public function testGetAllTags()
83
    {
84
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Applications/getAllTags.json');
85
        $client = $this->getMockClient($response);
86
87
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
88
        $application = new Applications($client);
89
        $result = $application->getAllTags('8ff6c046-ec64-4ce4-bea6-27845ec18600');
90
91
        $this->assertInstanceOf('\ArrayObject', $result);
92
        $this->assertInstanceOf('\AcquiaCloudApi\Response\TagsResponse', $result);
93
94
        foreach ($result as $record) {
95
            $this->assertInstanceOf('\AcquiaCloudApi\Response\TagResponse', $record);
96
97
            foreach ($this->tagProperties as $property) {
98
                $this->assertObjectHasAttribute($property, $record);
99
            }
100
        }
101
    }
102
103
    public function testCreateTag()
104
    {
105
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Applications/createTag.json');
106
        $client = $this->getMockClient($response);
107
108
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
109
        $application = new Applications($client);
110
        $result = $application->createTag('8ff6c046-ec64-4ce4-bea6-27845ec18600', "deloitte", "orange");
111
112
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
113
114
        $this->assertEquals('The tag has been added to the application.', $result->message);
115
    }
116
117
    public function testDeleteTag()
118
    {
119
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Applications/deleteTag.json');
120
        $client = $this->getMockClient($response);
121
122
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
123
        $application = new Applications($client);
124
        $result = $application->deleteTag('8ff6c046-ec64-4ce4-bea6-27845ec18600', "deloitte");
125
126
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
127
128
        $this->assertEquals('The tag has been removed from the application.', $result->message);
129
    }
130
}
131