|
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() { |
|
|
|
|
|
|
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() { |
|
|
|
|
|
|
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
|
|
|
|
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.