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

SmokeTestPipelineStepTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 51.52 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 4
lcom 1
cbo 3
dl 34
loc 66
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDummySmokeTestStep() 11 11 1
A testSmokeTestPass() 12 12 1
A testSmokeTestFail() 11 11 1
A testReattempts() 0 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class SmokeTestPipelineStepTest 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
	 * Make the dummy deployment step
9
	 *
10
	 * @return SmokeTestPipelineStep
11
	 */
12 View Code Duplication
	public function getDummySmokeTestStep($name) {
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 data inte step and pipeline
14
		$data = $this->getPipelineConfig();
15
		$smokeStep = $this->objFromFixture('SmokeTestPipelineStep', 'testsmoketest');
16
		$pipeline = $smokeStep->Pipeline();
17
		$pipeline->Config = serialize($data);
18
		$pipeline->write();
19
		$smokeStep->Config = serialize($pipeline->getConfigSetting('Steps', $name));
20
		$smokeStep->write();
21
		return $smokeStep;
22
	}
23
24
	/**
25
	 * Test successful smoke test
26
	 */
27 View Code Duplication
	public function testSmokeTestPass() {
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...
28
		$this->markTestSkipped("Failing sporadically");
0 ignored issues
show
Bug introduced by
The method markTestSkipped() does not seem to exist on object<SmokeTestPipelineStepTest>.

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...
29
		return;
30
31
		$step = $this->getDummySmokeTestStep('SmokeTest');
0 ignored issues
show
Unused Code introduced by
$step = $this->getDummyS...eTestStep('SmokeTest'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
32
		$this->assertTrue($step->start());
33
		$this->assertHasLog('Starting smoke test "Videos" to URL http://www.youtube.com/');
34
		$this->assertHasLog('Smoke test "Videos" to URL http://www.youtube.com/ successful');
35
		$this->assertHasLog('Starting smoke test "Home" to URL https://github.com/');
36
		$this->assertHasLog('Smoke test "Home" to URL https://github.com/ successful');
37
		$this->assertEquals('Finished', $step->Status);
38
	}
39
40
	/**
41
	 * Test failed smoke test
42
	 */
43 View Code Duplication
	public function testSmokeTestFail() {
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...
44
		// the testsmokefaile yml config contains a invalid smoketest url
45
		// which is how it fails
46
		$step = $this->getDummySmokeTestStep('FailTest');
47
		$this->assertFalse($step->start());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<SmokeTestPipelineStepTest>.

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...
48
		$this->assertHasLog('Starting smoke test "BrokenPage" to URL http://bob.bob.bob.bob/');
49
		$this->assertHasLog('Curl error: ');
50
		$this->assertHasLog('Starting smoke test "Home" to URL https://github.com/');
51
		$this->assertHasLog('Smoke test "Home" to URL https://github.com/ successful');
52
		$this->assertEquals('Failed', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SmokeTestPipelineStepTest>.

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
	}
54
55
	public function testReattempts() {
56
		// the testsmokefaile yml config contains a invalid smoketest url which is how it fails
57
		$step = $this->getDummySmokeTestStep('RepeatTest');
58
		$this->assertFalse($step->start());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<SmokeTestPipelineStepTest>.

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...
59
		$this->assertHasLog('Starting smoke test "BrokenPage" to URL http://bob.bob.bob.bob/');
60
		$this->assertHasLog('Curl error: ');
61
		$this->assertHasLog('Starting smoke test "Home" to URL https://github.com/');
62
		$this->assertHasLog('Smoke test "Home" to URL https://github.com/ successful');
63
		$this->assertHasLog('Request failed, performing reattempt (#1)');
64
		$this->assertHasLog('Request failed, performing reattempt (#2)');
65
		$this->assertHasLog('Failed after 3 attempts');
66
		$this->assertEquals('Failed', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SmokeTestPipelineStepTest>.

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...
67
	}
68
}
69