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

SslCertificatesTest::testCreateSslCertificate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 20
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace AcquiaCloudApi\Tests\Endpoints;
4
5
use AcquiaCloudApi\Tests\CloudApiTestCase;
6
use AcquiaCloudApi\Endpoints\SslCertificates;
7
8
class SslCertificatesTest extends CloudApiTestCase
9
{
10
11
    public $properties = [
12
    'id',
13
    'label',
14
    'certificate',
15
    'private_key',
16
    'ca',
17
    'flags',
18
    'expires_at',
19
    'domains',
20
    'environment',
21
    'links'
22
    ];
23
24
    public function testGetCertificates()
25
    {
26
27
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/SslCertificates/getAllSslCertificates.json');
28
        $client = $this->getMockClient($response);
29
30
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
31
        $certificate = new SslCertificates($client);
32
        $result = $certificate->getAll('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
33
34
        $this->assertInstanceOf('\ArrayObject', $result);
35
        $this->assertInstanceOf('\AcquiaCloudApi\Response\SslCertificatesResponse', $result);
36
37
        foreach ($result as $record) {
38
            $this->assertInstanceOf('\AcquiaCloudApi\Response\SslCertificateResponse', $record);
39
40
            foreach ($this->properties as $property) {
41
                $this->assertObjectHasAttribute($property, $record);
42
            }
43
        }
44
    }
45
46
    public function testGetCertificate()
47
    {
48
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/SslCertificates/getSslCertificate.json');
49
        $client = $this->getMockClient($response);
50
51
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
52
        $certificate = new SslCertificates($client);
53
        $result = $certificate->get('8ff6c046-ec64-4ce4-bea6-27845ec18600', 3);
54
55
        $this->assertNotInstanceOf('\AcquiaCloudApi\Response\SslCertificatesResponse', $result);
56
        $this->assertInstanceOf('\AcquiaCloudApi\Response\SslCertificateResponse', $result);
57
58
        foreach ($this->properties as $property) {
59
              $this->assertObjectHasAttribute($property, $result);
60
        }
61
    }
62
63
    public function testCreateSslCertificate()
64
    {
65
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/SslCertificates/createSslCertificate.json');
66
        $client = $this->getMockClient($response);
67
68
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
69
        $certificate = new SslCertificates($client);
70
        $result = $certificate->create(
71
            '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851',
72
            'My New Cert',
73
            '-----BEGIN CERTIFICATE-----abc123....-----END CERTIFICATE-----',
74
            '-----BEGIN RSA PRIVATE KEY-----secret....-----END RSA PRIVATE KEY-----',
75
            '-----BEGIN CERTIFICATE-----123abc....-----END CERTIFICATE-----',
76
            123,
77
            false
78
        );
79
80
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
81
82
        $this->assertEquals('Installing the certificate.', $result->message);
83
    }
84
85
    public function testDeleteSslCertificate()
86
    {
87
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/SslCertificates/deleteSslCertificate.json');
88
        $client = $this->getMockClient($response);
89
90
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
91
        $certificate = new SslCertificates($client);
92
        $result = $certificate->delete('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 14);
93
94
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
95
96
        $this->assertEquals('Deleting the certificate.', $result->message);
97
    }
98
99
    public function testActivateSslCertificate()
100
    {
101
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/SslCertificates/activateSslCertificate.json');
102
        $client = $this->getMockClient($response);
103
104
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
105
        $certificate = new SslCertificates($client);
106
        $result = $certificate->enable('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 2);
107
108
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
109
110
        $this->assertEquals('Activating the certificate.', $result->message);
111
    }
112
113
    public function testDeactivateSslCertificate()
114
    {
115
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/SslCertificates/deactivateSslCertificate.json');
116
        $client = $this->getMockClient($response);
117
118
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
119
        $certificate = new SslCertificates($client);
120
        $result = $certificate->disable('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 2);
121
122
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
123
124
        $this->assertEquals('Deactivating the certificate.', $result->message);
125
    }
126
}
127