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

CronsTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 71
dl 0
loc 131
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateCron() 0 16 1
A testDisableCron() 0 11 1
A testUpdateCron() 0 17 1
A testGetCron() 0 14 2
A testGetAllCrons() 0 18 3
A testDeleteCron() 0 11 1
A testEnableCron() 0 11 1
1
<?php
2
3
namespace AcquiaCloudApi\Tests\Endpoints;
4
5
use AcquiaCloudApi\Tests\CloudApiTestCase;
6
use AcquiaCloudApi\Endpoints\Crons;
7
8
class CronsTest extends CloudApiTestCase
9
{
10
11
    public $properties = [
12
    'id',
13
    'server',
14
    'command',
15
    'minute',
16
    'hour',
17
    'dayMonth',
18
    'month',
19
    'dayWeek',
20
    'label',
21
    'flags',
22
    'environment',
23
    'links'
24
    ];
25
26
    public function testGetAllCrons()
27
    {
28
29
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Crons/getAllCrons.json');
30
        $client = $this->getMockClient($response);
31
32
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
33
        $cron = new Crons($client);
34
        $result = $cron->getAll('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
35
36
        $this->assertInstanceOf('\ArrayObject', $result);
37
        $this->assertInstanceOf('\AcquiaCloudApi\Response\CronsResponse', $result);
38
39
        foreach ($result as $record) {
40
            $this->assertInstanceOf('\AcquiaCloudApi\Response\CronResponse', $record);
41
42
            foreach ($this->properties as $property) {
43
                $this->assertObjectHasAttribute($property, $record);
44
            }
45
        }
46
    }
47
48
    public function testGetCron()
49
    {
50
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Crons/getCron.json');
51
        $client = $this->getMockClient($response);
52
53
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
54
        $cron = new Crons($client);
55
        $result = $cron->get('8ff6c046-ec64-4ce4-bea6-27845ec18600', 3);
56
57
        $this->assertNotInstanceOf('\AcquiaCloudApi\Response\CronsResponse', $result);
58
        $this->assertInstanceOf('\AcquiaCloudApi\Response\CronResponse', $result);
59
60
        foreach ($this->properties as $property) {
61
              $this->assertObjectHasAttribute($property, $result);
62
        }
63
    }
64
65
    public function testCreateCron()
66
    {
67
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Crons/createCron.json');
68
        $client = $this->getMockClient($response);
69
70
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
71
        $cron = new Crons($client);
72
        $result = $cron->create(
73
            '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851',
74
            '/usr/local/bin/drush cc all',
75
            '*/30 * * * *',
76
            'My New Cron'
77
        );
78
79
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
80
        $this->assertEquals('Creating a new cron.', $result->message);
81
    }
82
83
    public function testUpdateCron()
84
    {
85
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Crons/updateCron.json');
86
        $client = $this->getMockClient($response);
87
88
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
89
        $cron = new Crons($client);
90
        $result = $cron->update(
91
            '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851',
92
            '14',
93
            '/usr/local/bin/drush cc all',
94
            '*/30 * * * *',
95
            'My New Cron'
96
        );
97
98
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
99
        $this->assertEquals('Updating cron.', $result->message);
100
    }
101
102
    public function testDeleteCron()
103
    {
104
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Crons/deleteCron.json');
105
        $client = $this->getMockClient($response);
106
107
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
108
        $cron = new Crons($client);
109
        $result = $cron->delete('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 14);
110
111
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
112
        $this->assertEquals('Deleting cron.', $result->message);
113
    }
114
115
    public function testEnableCron()
116
    {
117
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Crons/enableCron.json');
118
        $client = $this->getMockClient($response);
119
120
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
121
        $cron = new Crons($client);
122
        $result = $cron->enable('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 2);
123
124
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
125
        $this->assertEquals('The cron is being enabled.', $result->message);
126
    }
127
128
    public function testDisableCron()
129
    {
130
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Crons/disableCron.json');
131
        $client = $this->getMockClient($response);
132
133
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
134
        $cron = new Crons($client);
135
        $result = $cron->disable('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 2);
136
137
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
138
        $this->assertEquals('The cron is being disabled.', $result->message);
139
    }
140
}
141