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

TriggerDeployStepTest::testTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 9

Duplication

Lines 18
Ratio 100 %
Metric Value
dl 18
loc 18
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
class TriggerDeployStepTest 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 TriggerDeployStep
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
		$triggerDeployStep = $this->objFromFixture('TriggerDeployStep', 'testdeploy');
18
		$pipeline = $triggerDeployStep->Pipeline();
19
		$pipeline->Config = serialize($data);
20
		$pipeline->write();
21
		$triggerDeployStep->Config = serialize($pipeline->getConfigSetting('Steps', 'RequestDeploymentStep'));
22
		$triggerDeployStep->write();
23
24
		return $triggerDeployStep;
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<TriggerDeployStepTest>.

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

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<TriggerDeployStepTest>.

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('Deployment step is older then 86400 seconds and has timed out');
47
	}
48
49
	public function testDeploy() {
50
		SS_Datetime::set_mock_now(date('Y-m-d H:i:s'));
51
		$step = $this->getDummyConfirmationStep();
52
53
		$step->start();
54
		$step->deploy();
55
56
		// Assert not error at startup
57
		$this->assertEquals('Finished', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<TriggerDeployStepTest>.

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->Deployed);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<TriggerDeployStepTest>.

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('RequestDeploymentStep is being deployed');
63
	}
64
65 View Code Duplication
	public function testCanTrigger() {
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...
66
		$step = $this->getDummyConfirmationStep();
67
68
		$step->start();
69
70
		// can the author trigger the deploy
71
		$member = Member::get_by_id('Member', $step->Pipeline()->AuthorID);
72
		$member->logIn();
73
74
		$this->assertTrue($step->canTriggerDeploy());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<TriggerDeployStepTest>.

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...
75
76
		// can another member with deploy permissions trigger the deploy
77
		$member = Member::get()
78
			->filter('Email', '[email protected]')
79
			->first();
80
		$member->logIn();
81
		$this->assertTrue($step->canTriggerDeploy());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<TriggerDeployStepTest>.

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...
82
83
		$this->logInWithPermission('APPLY_ROLES');
84
		$this->assertFalse($step->canTriggerDeploy());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<TriggerDeployStepTest>.

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...
85
86
		$this->logInWithPermission('ADMIN');
87
		$this->assertTrue($step->canTriggerDeploy());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<TriggerDeployStepTest>.

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...
88
89
		// confirm other members without admin permissions can not trigger the deploy
90
		$member = Member::get()
91
			->filter('Email', '[email protected]')
92
			->first();
93
		$member->logIn();
94
		$this->assertFalse($step->canTriggerDeploy());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<TriggerDeployStepTest>.

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
	}
97
98
	public function testStartDeployment() {
99
		$step = $this->getDummyConfirmationStep();
100
101
		$step->start();
102
103
		$this->logInWithPermission('APPLY_ROLES');
104
		$this->assertTrue($step->startDeployment());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<TriggerDeployStepTest>.

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...
105
	}
106
107
	public function testRunningConfiguration() {
108
		$step = $this->getDummyConfirmationStep();
109
110
		$step->start();
111
		$this->logInWithPermission('ADMIN');
112
		$this->assertEquals('Please press the "Deploy" button to continue deployment',
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<TriggerDeployStepTest>.

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...
113
			$step->getRunningDescription());
114
	}
115
116
	public function testStartFail() {
117
		$step = $this->getDummyConfirmationStep();
118
		// set status so it fails
119
		$step->Status = 'Failed';
120
121
		$this->assertFalse($step->start());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<TriggerDeployStepTest>.

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...
122
	}
123
}
124