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

WpHydraSetupContentTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 92
Duplicated Lines 43.48 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 40
loc 92
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A tearDown() 0 4 1
A testOccurencesInTheBeginning() 8 8 1
A testOccurencesInTheMiddle() 8 8 1
A testOccurencesInTheEnd() 8 8 1
A testMultipleOccurences() 0 8 1
A testOccurencesInAnImage() 8 8 1
A testOccurencesInALink() 8 8 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 WpHydraSetupContentTest extends WP_UnitTestCase {
4
5
	public function setUp() {
6
		$this->wp_hydra = $this->getMockBuilder('WP_Hydra')->disableOriginalConstructor()->setMethods(array('setup_domain'))->getMock();
7
8
		$this->domain = 'https://foobar.com';
9
10
		$this->wp_hydra->expects($this->any())
11
			->method('setup_domain')
12
			->will($this->returnValue($this->domain));
13
14
		remove_all_filters( 'option_home', 1 );
15
	}
16
17
	public function tearDown() {
18
		unset( $this->wp_hydra );
19
		unset( $this->domain );
20
	}
21
22
	/**
23
	 * @covers WP_Hydra::setup_content
24
	 */
25 View Code Duplication
	public function testOccurencesInTheBeginning() {
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...
26
		$content = 'https://example.org/ foo bar ';
27
28
		$expected = $this->domain . '/ foo bar ';
29
		$actual = $this->wp_hydra->setup_content( $content );
30
31
		$this->assertSame( $expected, $actual );
32
	}
33
34
	/**
35
	 * @covers WP_Hydra::setup_content
36
	 */
37 View Code Duplication
	public function testOccurencesInTheMiddle() {
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...
38
		$content = 'helloWorld https://example.org/ foo bar ';
39
40
		$expected = 'helloWorld ' . $this->domain . '/ foo bar ';
41
		$actual = $this->wp_hydra->setup_content( $content );
42
43
		$this->assertSame( $expected, $actual );
44
	}
45
46
	/**
47
	 * @covers WP_Hydra::setup_content
48
	 */
49 View Code Duplication
	public function testOccurencesInTheEnd() {
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...
50
		$content = 'helloWorld https://example.org/';
51
52
		$expected = 'helloWorld ' . $this->domain . '/';
53
		$actual = $this->wp_hydra->setup_content( $content );
54
55
		$this->assertSame( $expected, $actual );
56
	}
57
58
	/**
59
	 * @covers WP_Hydra::setup_content
60
	 */
61
	public function testMultipleOccurences() {
62
		$content = 'https://example.org/ helloWorld https://example.org/ foo bar https://example.org/';
63
64
		$expected = $this->domain . '/ helloWorld ' . $this->domain . '/ foo bar ' . $this->domain . '/';
65
		$actual = $this->wp_hydra->setup_content( $content );
66
67
		$this->assertSame( $expected, $actual );
68
	}
69
70
	/**
71
	 * @covers WP_Hydra::setup_content
72
	 */
73 View Code Duplication
	public function testOccurencesInAnImage() {
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...
74
		$content = '<img src="https://example.org/wp-content/uploads/2012/12/test.jpg" width="640" height="480" alt="" />';
75
76
		$expected = '<img src="' . $this->domain . '/wp-content/uploads/2012/12/test.jpg" width="640" height="480" alt="" />';
77
		$actual = $this->wp_hydra->setup_content( $content );
78
79
		$this->assertSame( $expected, $actual );
80
	}
81
82
	/**
83
	 * @covers WP_Hydra::setup_content
84
	 */
85 View Code Duplication
	public function testOccurencesInALink() {
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...
86
		$content = '<a href="https://example.org/foo/bar/">Test</a>';
87
88
		$expected = '<a href="' . $this->domain . '/foo/bar/">Test</a>';
89
		$actual = $this->wp_hydra->setup_content( $content );
90
91
		$this->assertSame( $expected, $actual );
92
	}
93
94
}