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

EmergencyRollbackStepTest::testStartFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
class EmergencyRollbackStepTest 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
	protected static $fixture_file = 'PipelineTest.yml';
6
7
	/**
8
	 * Makse the dummy deployment step
9
	 *
10
	 * @return EmergencyRollbackStep
11
	 */
12 View Code Duplication
	public function getDummyConfirmationStep() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
		// Load config
14
		$data = $this->getPipelineConfig();
15
16
		// Load data into step and pipeline
17
		$emergencyRollback = $this->objFromFixture('EmergencyRollbackStep', 'testdeploy');
18
		$pipeline = $emergencyRollback->Pipeline();
19
		$pipeline->Config = serialize($data);
20
		$pipeline->write();
21
		$emergencyRollback->Config = serialize($pipeline->getConfigSetting('Steps', 'RollbackWindowStep'));
22
		$emergencyRollback->write();
23
24
		return $emergencyRollback;
25
	}
26
27
	/**
28
	 * Test that timeout expiry works
29
	 */
30 View Code Duplication
	public function testTimeout() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
		$step = $this->getDummyConfirmationStep();
32
		$step->start();
33
34
		// Assert not error at startup
35
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
36
37
		// Go to two hours in the future
38
		SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+2 hours')));
39
40
		// Retry step
41
		$step->start();
42
		$this->assertEquals('Finished', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
43
		$this->assertTrue($step->isTimedOut());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
44
45
		// check a log entry exists
46
		$this->assertHasLog('RollbackWindowStep is older than 3600 seconds and has timed out');
47
	}
48
49
	public function testRollback() {
50
		SS_Datetime::set_mock_now(date('Y-m-d H:i:s'));
51
		$step = $this->getDummyConfirmationStep();
52
53
		$step->start();
54
		$step->rollback();
55
56
		// Assert not error at startup
57
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
58
59
		// Assert that 'now' is used for the deployment date
60
		$this->assertEquals(SS_Datetime::now()->Format('Y-m-d H:i:s'), $step->RolledBack);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
61
62
		$this->assertHasLog('RollbackWindowStep is being rolled back');
63
	}
64
65
	public function testDismiss() {
66
		SS_Datetime::set_mock_now(date('Y-m-d H:i:s'));
67
		$step = $this->getDummyConfirmationStep();
68
69
		$step->start();
70
		$step->dismiss();
71
72
		// Assert not error at startup
73
		$this->assertEquals('Finished', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
74
		$this->assertHasLog('Dismissing rollback window.');
75
	}
76
77 View Code Duplication
	public function testCanRollback() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
		$step = $this->getDummyConfirmationStep();
79
80
		$step->start();
81
82
		// can the author trigger a rollback
83
		$member = Member::get_by_id('Member', $step->Pipeline()->AuthorID);
84
		$member->logIn();
85
86
		$this->assertTrue($step->canTriggerRollback());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
87
88
		// can another member with deploy permissions trigger a rollback
89
		$member = Member::get()
90
			->filter('Email', '[email protected]')
91
			->first();
92
		$member->logIn();
93
		$this->assertTrue($step->canTriggerRollback());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
94
95
		$this->logInWithPermission('APPLY_ROLES');
96
		$this->assertFalse($step->canTriggerRollback());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
97
98
		$this->logInWithPermission('ADMIN');
99
		$this->assertTrue($step->canTriggerRollback());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
100
101
		// confirm other members without admin permissions can not trigger a rollback
102
		$member = Member::get()
103
			->filter('Email', '[email protected]')
104
			->first();
105
		$member->logIn();
106
		$this->assertFalse($step->canTriggerRollback());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
107
108
	}
109
110
	public function testBeginRollbackWindow() {
111
		$step = $this->getDummyConfirmationStep();
112
113
		$step->start();
114
115
		$this->logInWithPermission('APPLY_ROLES');
116
		$this->assertTrue($step->beginRollbackWindow());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
117
118
		// Check that the message is sent
119
		$this->assertSentMessage('Deployment for testproject/uat has successfully completed', '[email protected]');
120
	}
121
122
	public function testRunningConfiguration() {
123
		$step = $this->getDummyConfirmationStep();
124
125
		$step->start();
126
		$this->logInWithPermission('ADMIN');
127
		$this->assertEquals('You may now roll back to the previous version, if needed.',
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
128
			$step->getRunningDescription());
129
	}
130
131
	public function testStartFail() {
132
		$step = $this->getDummyConfirmationStep();
133
		// set status so it fails
134
		$step->Status = 'Failed';
135
136
		$this->assertFalse($step->start());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EmergencyRollbackStepTest>.

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...
137
138
		// Check that the message is sent
139
		$this->assertNotSentMessage('Deployment for testproject/uat has successfully completed', '[email protected]');
140
	}
141
}
142