Completed
Pull Request — master (#513)
by Helpful
04:05
created

AbstractPipelineTest::testCheckPipelineStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50
Code Lines 38

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 50
rs 9.3333
cc 1
eloc 38
nc 1
nop 0
1
<?php
2
3
class AbstractPipelineTest extends PipelineTest {
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
5
	// Fixture file containing test pipeline data
6
	protected static $fixture_file = 'AbstractPipelineTest.yml';
7
8
	public function testCheckPipelineStatus() {
9
		$pipeline = $this->objFromFixture('Pipeline', 'Pipe2');
10
		$pipeline->Config = serialize(array());
11
		$pipeline->write();
12
13
		// First step should start.
14
		$pipeline->checkPipelineStatus();
15
16
		$this->assertEquals('Running', $pipeline->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
17
		$this->assertEquals(true, $pipeline->isRunning());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18
		$this->assertDOSEquals(array(
19
			array('Name'=>'step1', 'Status'=>'Started'),
20
			array('Name'=>'step2', 'Status'=>'Queued'),
21
		), $pipeline->Steps());
22
23
		// Try to progress the pipeline second time. Shouldn't move until step is finished.
24
		$pipeline->checkPipelineStatus();
25
		$this->assertEquals('Running', $pipeline->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
		$this->assertEquals(true, $pipeline->isRunning());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
		$this->assertDOSEquals(array(
28
			array('Name'=>'step1', 'Status'=>'Started'),
29
			array('Name'=>'step2', 'Status'=>'Queued'),
30
		), $pipeline->Steps());
31
32
		// First step finished, pipeline should move now.
33
		$firstStep = $pipeline->CurrentStep();
34
		$firstStep->Status = 'Finished';
35
		$firstStep->write();
36
		$pipeline->checkPipelineStatus();
37
38
		$this->assertEquals('Running', $pipeline->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
		$this->assertEquals(true, $pipeline->isRunning());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
		$this->assertDOSEquals(array(
41
			array('Name'=>'step1', 'Status'=>'Finished'),
42
			array('Name'=>'step2', 'Status'=>'Started'),
43
		), $pipeline->Steps());
44
45
		// Last step finished. Pipeline should fold now.
46
		$lastStep = $pipeline->CurrentStep();
47
		$lastStep->Status = 'Finished';
48
		$lastStep->write();
49
		$pipeline->checkPipelineStatus();
50
51
		$this->assertEquals('Complete', $pipeline->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
		$this->assertEquals(false, $pipeline->isRunning());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
		$this->assertDOSEquals(array(
54
			array('Name'=>'step1', 'Status'=>'Finished'),
55
			array('Name'=>'step2', 'Status'=>'Finished'),
56
		), $pipeline->Steps());
57
	}
58
59
	public function testAborted() {
60
		$pipeline = $this->objFromFixture('Pipeline', 'Pipe1');
61
		$pipeline->Config = serialize(array());
62
		$pipeline->write();
63
64
		$pipeline->markAborted();
65
66
		// confirm Status is now aborted
67
		$this->assertEquals('Aborted', $pipeline->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
		$this->assertEquals(true, $pipeline->isAborted());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
70
		// Confirm steps have correct status.
71
		$this->assertDOSEquals(array(
72
			array('Name'=>'step1', 'Status'=>'Finished'),
73
			array('Name'=>'step2', 'Status'=>'Aborted'),
74
			array('Name'=>'step3', 'Status'=>'Aborted')
75
		), $pipeline->Steps());
76
	}
77
78
	public function testAbortPipelineLink() {
79
		$pipeline = $this->objFromFixture('Pipeline', 'Pipe1');
80
81
		// Confirm the correct abort link is generated
82
		$this->assertEquals($pipeline->Link('abort'),
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
			'naut/project/Project 1/environment/env1/pipeline/'.$pipeline->ID.'/abort');
84
	}
85
86
	public function testCanCancelPipeline() {
87
		$member = $this->objFromFixture('Member', 'Deployer2');
88
		$member->logIn();
89
		$pipeline = $this->objFromFixture('Pipeline', 'Pipe1');
90
91
		$environment = $pipeline->Environment();
92
93
		// confirm Status is now running
94
		$this->assertEquals('Running', $pipeline->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
95
96
		// confirm non-admin member who did not start the pipeline cannot stop it
97
		$this->assertEquals(false, $environment->CanCancelPipeline());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
98
99
		// confirm member who started pipeline can stop it
100
		$member = $this->objFromFixture('Member', 'Deployer1');
101
		$member->logIn();
102
		$this->assertEquals(true, $environment->CanCancelPipeline());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
104
		// confirm admin member can stop pipeline
105
		$member = $this->objFromFixture('Member', 'Deployer3');
106
		$member->logIn();
107
		$this->assertEquals(true, $environment->CanCancelPipeline());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
	}
109
110
	public function testMarkFailed() {
111
		$pipeline = $this->objFromFixture('Pipeline', 'Pipe1');
112
		$pipeline->Config = serialize(array());
113
		$pipeline->write();
114
115
		// Pretend second step fails.
116
		$step = $this->objFromFixture('PipelineStep', 'Step2');
117
		$step->Status = 'Failed';
118
		$step->write();
119
		$pipeline->markFailed();
120
121
		// confirm Status is now Failed.
122
		$this->assertEquals('Failed', $pipeline->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
		$this->assertEquals(true, $pipeline->isFailed());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
125
		// Confirm steps have correct status.
126
		$this->assertDOSEquals(array(
127
			array('Name'=>'step1', 'Status'=>'Finished'),
128
			array('Name'=>'step2', 'Status'=>'Failed'),
129
			array('Name'=>'step3', 'Status'=>'Aborted')
130
		), $pipeline->Steps());
131
	}
132
133
	/**
134
	 * Provide rollback-able pipeline on the verge of failing.
135
	 */
136
	public function getFailingPipeline() {
137
		// Get default backups
138
		$previous = DNDeployment::create();
139
		$previous->SHA = '9f0a012e97715b1871n41gk30f34268u12a0029q';
140
		$previous->write();
141
		$current = DNDeployment::create();
142
		$current->write();
143
		$snapshot = DNDataTransfer::create();
144
		$snapshot->write();
145
146
		$pipeline = $this->objFromFixture('Pipeline', 'FailingPipe');
147
		$pipeline->Config = serialize(array(
148
			'RollbackStep1' => array(
149
				'Class' => 'RollbackStep',
150
				'RestoreDB' => false,
151
				'MaxDuration' => '3600'
152
			),
153
			'RollbackStep2' => array(
154
				'Class' => 'SmokeTestPipelineStep',
155
				'MaxDuration' => '3600'
156
			)
157
		));
158
		$pipeline->PreviousDeploymentID = $previous->ID;
159
		$pipeline->CurrentDeploymentID = $current->ID;
160
		$pipeline->PreviousSnapshotID = $snapshot->ID;
161
		$pipeline->write();
162
163
		return $pipeline;
164
	}
165
166
	public function testMarkFailedRollbackStart() {
167
168
		$pipeline = $this->getFailingPipeline();
169
		$this->assertEquals($pipeline->RollbackStep1ID, 0);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
170
		$this->assertEquals($pipeline->RollbackStep2ID, 0);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
171
		$this->assertFalse($pipeline->isFailed());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
172
		$this->assertFalse($pipeline->isRollback());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
173
174
		$pipeline->markFailed();
175
176
		$this->assertNotEmpty($pipeline->RollbackStep1());
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
177
		$this->assertNotEmpty($pipeline->RollbackStep2());
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
178
		$this->assertFalse($pipeline->isFailed());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
179
		$this->assertTrue($pipeline->isRollback());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
180
		$this->assertHasLog('Beginning rollback...');
181
		$this->assertEquals($pipeline->RollbackStep1()->Status, 'Started');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
182
		$this->assertEquals($pipeline->RollbackStep2()->Status, 'Queued');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
183
184
	}
185
186
	public function testMarkFailedRollbackFailing() {
187
188
		$pipeline = $this->getFailingPipeline();
189
190
		// Trigger rollback.
191
		$pipeline->markFailed();
192
193
		// Fail first rollback step.
194
		$pipeline->RollbackStep1()->markFailed();
195
196
		$this->assertHasLog('Pipeline failed, rollback failed.');
197
198
		$pipeline = Pipeline::get()->byID($pipeline->ID);
199
		$this->assertTrue($pipeline->isFailed());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
200
		$this->assertFalse($pipeline->isRollback());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
201
		$this->assertEquals($pipeline->RollbackStep1()->Status, 'Failed');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
202
		$this->assertEquals($pipeline->RollbackStep2()->Status, 'Aborted');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
203
		$this->assertEquals($pipeline->Status, 'Failed');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
204
205
	}
206
207
	public function testMarkCompleteRollback() {
208
209
		$pipeline = $this->getFailingPipeline();
210
211
		// Trigger rollback.
212
		$pipeline->markFailed();
213
214
		// Succeed the rollback.
215
		$pipeline->RollbackStep1()->finish();
216
		$pipeline->RollbackStep2()->finish();
217
218
		// Progress the pipeline. Will call markFailed.
219
		$pipeline->checkPipelineStatus();
220
221
		$this->assertHasLog('Pipeline failed, but rollback completed successfully.');
222
223
		$pipeline = Pipeline::get()->byID($pipeline->ID);
224
		$this->assertTrue($pipeline->isFailed());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
225
		$this->assertFalse($pipeline->isRollback());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
226
		$this->assertEquals($pipeline->RollbackStep1()->Status, 'Finished');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
227
		$this->assertEquals($pipeline->RollbackStep2()->Status, 'Finished');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
228
		$this->assertEquals($pipeline->Status, 'Failed');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AbstractPipelineTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
229
230
	}
231
}
232