Completed
Push — master ( 659231...788af6 )
by Wanderson
05:06
created

ViewTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 25.42 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 1
dl 15
loc 59
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testViewNotFound() 0 4 1
A testViewIndex() 0 4 1
A testToString() 0 7 1
A testParamData() 0 4 1
A testAddData() 0 5 1
A testMergeData() 7 7 1
A testAddDataAndMergeData() 8 8 1
A testParamAndMergeDataAndAddData() 0 9 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
namespace Win\Mvc;
4
5
use Win\Mvc\View;
6
7
class ViewTest extends \PHPUnit_Framework_TestCase {
8
9
	public function testViewNotFound() {
10
		$view = new View('this-view-doesnt-exist');
11
		$this->assertFalse($view->exists());
12
	}
13
14
	public function testViewIndex() {
15
		$view = new View('index');
16
		$this->assertTrue($view->exists());
17
	}
18
19
	public function testToString() {
20
		$viewEmpty = new View('this-file-doent-exist');
21
		$this->assertEquals(0, strlen($viewEmpty->toString()));
22
23
		$viewNotEmpty = new View('index');
24
		$this->assertNotEquals(0, strlen($viewNotEmpty->toString()));
25
	}
26
27
	public function testParamData() {
28
		$view = new View('index', ['a' => 5]);
29
		$this->assertEquals($view->getData('a'), 5);
30
	}
31
32
	public function testAddData() {
33
		$view = new View('index');
34
		$view->addData('a', 10);
35
		$this->assertEquals($view->getData('a'), 10);
36
	}
37
38 View Code Duplication
	public function testMergeData() {
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...
39
		$view = new View('index');
40
		$view->mergeData(['a' => 10, 'b' => 20]);
41
42
		$this->assertEquals($view->getData('a'), 10);
43
		$this->assertEquals($view->getData('b'), 20);
44
	}
45
46 View Code Duplication
	public function testAddDataAndMergeData() {
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...
47
		$view = new View('index');
48
		$view->addData('a', 10);
49
		$view->mergeData(['a' => 15, 'b' => 20]);
50
51
		$this->assertEquals($view->getData('a'), 15);
52
		$this->assertEquals($view->getData('b'), 20);
53
	}
54
55
	public function testParamAndMergeDataAndAddData() {
56
		$view = new View('index', ['a' => 5, 'c' => 30]);
57
		$view->mergeData(['a' => 15, 'b' => 20]);
58
		$view->addData('a', 10);
59
60
		$this->assertEquals($view->getData('a'), 10);
61
		$this->assertEquals($view->getData('b'), 20);
62
		$this->assertEquals($view->getData('c'), 30);
63
	}
64
65
}
66