Completed
Pull Request — master (#15)
by Marin
01:29
created

WpHydraSetupDomainTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 32.88 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 24
loc 73
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A tearDown() 0 3 1
A testWithWrongURL() 0 7 1
A testWithNoHost() 12 12 1
A testWithTheSameDomain() 12 12 1
A testWithDifferentDomain() 0 15 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 WpHydraSetupDomainTest extends WP_UnitTestCase {
4
5
	public function setUp() {
6
		$this->wp_hydra = $this->getMockBuilder('WP_Hydra')->setMethods(null)->getMock();
7
	}
8
9
	public function tearDown() {
10
		unset( $this->wp_hydra );
11
	}
12
13
	/**
14
	 * @covers WP_Hydra::setup_domain
15
	 */
16
	public function testWithWrongURL() {
17
		$url = 'foo/com';
18
19
		$result = $this->wp_hydra->setup_domain( $url );
20
21
		$this->assertSame( $url, $result );
22
	}
23
24
	/**
25
	 * @covers WP_Hydra::setup_domain
26
	 */
27 View Code Duplication
	public function testWithNoHost() {
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
		$original_host = $_SERVER['HTTP_HOST'];
29
		unset($_SERVER['HTTP_HOST']);
30
31
		$url = 'http://example.xyz/lorem-ipsum/';
32
33
		$result = $this->wp_hydra->setup_domain( $url );
34
35
		$this->assertSame( $url, $result );
36
37
		$_SERVER['HTTP_HOST'] = $original_host;
38
	}
39
40
	/**
41
	 * @covers WP_Hydra::setup_domain
42
	 */
43 View Code Duplication
	public function testWithTheSameDomain() {
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
		$original_host = $_SERVER['HTTP_HOST'];
45
46
		$_SERVER['HTTP_HOST'] = 'example.com';
47
		$url = 'http://example.com/lorem-ipsum/';
48
49
		$result = $this->wp_hydra->setup_domain( $url );
50
51
		$this->assertSame( $url, $result );
52
53
		$_SERVER['HTTP_HOST'] = $original_host;
54
	}
55
56
	/**
57
	 * @covers WP_Hydra::setup_domain
58
	 */
59
	public function testWithDifferentDomain() {
60
		$original_host = $_SERVER['HTTP_HOST'];
61
62
		$current_domain = $_SERVER['HTTP_HOST'] = 'foobar.com';
63
		$original_domain = 'example.com';
64
		$url = 'http://example.com/lorem-ipsum/';
65
		$exposed_instance = $this->getMockBuilder('WP_Hydra_Exposed')->setMethods(null)->getMock();
66
67
		$expected = $exposed_instance->replace_domain_exposed( $url, $original_domain, $current_domain );
68
		$actual = $this->wp_hydra->setup_domain( $url );
69
70
		$this->assertSame( $expected, $actual );
71
72
		$_SERVER['HTTP_HOST'] = $original_host;
73
	}
74
75
}
76
77
class WP_Hydra_Exposed extends WP_Hydra {
78
	public function replace_domain_exposed( $url, $original_domain, $current_domain ) {
79
		return $this->replace_domain( $url, $original_domain, $current_domain );
80
	}
81
}