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

testCreateLogForwardingDestination()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 20
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace AcquiaCloudApi\Tests\Endpoints;
4
5
use AcquiaCloudApi\Tests\CloudApiTestCase;
6
use AcquiaCloudApi\Endpoints\LogForwardingDestinations;
7
8
class LogForwardingTest extends CloudApiTestCase
9
{
10
11
    public $properties = [
12
    'uuid',
13
    'label',
14
    'address',
15
    'consumer',
16
    'credentials',
17
    'sources',
18
    'status',
19
    'flags',
20
    'health',
21
    'environment'
22
    ];
23
24
    public function testGetLogForwardingDestinations()
25
    {
26
27
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/LogForwarding/getAllLogForwarding.json');
28
        $client = $this->getMockClient($response);
29
30
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
31
        $logForwarding = new LogForwardingDestinations($client);
32
        $result = $logForwarding->getAll('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
33
34
        $this->assertInstanceOf('\ArrayObject', $result);
35
        $this->assertInstanceOf('\AcquiaCloudApi\Response\LogForwardingDestinationsResponse', $result);
36
37
        foreach ($result as $record) {
38
            $this->assertInstanceOf('\AcquiaCloudApi\Response\LogForwardingDestinationResponse', $record);
39
40
            foreach ($this->properties as $property) {
41
                $this->assertObjectHasAttribute($property, $record);
42
            }
43
        }
44
    }
45
46
    public function testGetLogForwardingDestination()
47
    {
48
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/LogForwarding/getLogForwarding.json');
49
        $client = $this->getMockClient($response);
50
51
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
52
        $logForwarding = new LogForwardingDestinations($client);
53
        $result = $logForwarding->get('8ff6c046-ec64-4ce4-bea6-27845ec18600', 3);
54
55
        $this->assertNotInstanceOf('\AcquiaCloudApi\Response\LogForwardingDestinationsResponse', $result);
56
        $this->assertInstanceOf('\AcquiaCloudApi\Response\LogForwardingDestinationResponse', $result);
57
58
        foreach ($this->properties as $property) {
59
              $this->assertObjectHasAttribute($property, $result);
60
        }
61
    }
62
63
    public function testCreateLogForwardingDestination()
64
    {
65
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/LogForwarding/createLogForwarding.json');
66
        $client = $this->getMockClient($response);
67
68
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
69
        $logForwarding = new LogForwardingDestinations($client);
70
71
        $result = $logForwarding->create(
72
            '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851',
73
            'Test destination',
74
            ["apache-access", "apache-error"],
75
            'syslog',
76
            ["certificate" => "-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----"],
77
            'example.com:1234'
78
        );
79
80
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
81
82
        $this->assertEquals('Log forwarding destination for the environment has been created.', $result->message);
83
    }
84
85
    public function testDeleteLogForwardingDestination()
86
    {
87
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/LogForwarding/deleteLogForwarding.json');
88
        $client = $this->getMockClient($response);
89
90
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
91
        $logForwarding = new LogForwardingDestinations($client);
92
        $result = $logForwarding->delete('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 14);
93
94
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
95
96
        $this->assertEquals('Log forwarding destination has been deleted.', $result->message);
97
    }
98
99
    public function testEnableLogForwardingDestination()
100
    {
101
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/LogForwarding/enableLogForwarding.json');
102
        $client = $this->getMockClient($response);
103
104
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
105
        $logForwarding = new LogForwardingDestinations($client);
106
        $result = $logForwarding->enable('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 2);
107
108
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
109
110
        $this->assertEquals('Log forwarding destination has been enabled.', $result->message);
111
    }
112
113
    public function testDisableLogForwardingDestination()
114
    {
115
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/LogForwarding/disableLogForwarding.json');
116
        $client = $this->getMockClient($response);
117
118
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
119
        $logForwarding = new LogForwardingDestinations($client);
120
        $result = $logForwarding->disable('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 2);
121
122
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
123
124
        $this->assertEquals('Log forwarding destination has been disabled.', $result->message);
125
    }
126
127
    public function testUpdateLogForwardingDestination()
128
    {
129
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/LogForwarding/updateLogForwarding.json');
130
        $client = $this->getMockClient($response);
131
132
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
133
        $logForwarding = new LogForwardingDestinations($client);
134
        $result = $logForwarding->update(
135
            '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851',
136
            12,
137
            'Test destination',
138
            ["apache-access", "apache-error"],
139
            'syslog',
140
            ["certificate" => "-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----"],
141
            'example.com:1234'
142
        );
143
144
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
145
146
        $this->assertEquals('Log forwarding destination has been updated.', $result->message);
147
    }
148
}
149