1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHP; |
4
|
|
|
|
5
|
|
|
class ArrayDebuggerTest extends \PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
public $base = array( |
9
|
|
|
'hum' => 1, |
10
|
|
|
'dois' => 2, |
11
|
|
|
'tres' => 3 |
12
|
|
|
); |
13
|
|
|
|
14
|
|
View Code Duplication |
public function testGetter() { |
|
|
|
|
15
|
|
|
|
16
|
|
|
$array = new ArrayDebugger($this->base); |
17
|
|
|
|
18
|
|
|
$array->setLogger(function($retorno) { |
19
|
|
|
$this->assertEquals($retorno['type'], ArrayDebugger::TYPE_GET); |
20
|
|
|
}); |
21
|
|
|
|
22
|
|
|
$teste = $array['hum']; |
|
|
|
|
23
|
|
|
|
24
|
|
|
$array->setLogger(function($retorno) { |
25
|
|
|
$this->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_GET); |
26
|
|
|
}); |
27
|
|
|
|
28
|
|
|
$array['quatro'] = 4; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* offsetExists |
32
|
|
|
*/ |
33
|
|
|
isset($array['hum']); |
34
|
|
|
/** |
35
|
|
|
* offsetUnset |
36
|
|
|
*/ |
37
|
|
|
unset($array['quatro']); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function testSetter() { |
|
|
|
|
41
|
|
|
|
42
|
|
|
$array = new ArrayDebugger($this->base); |
43
|
|
|
|
44
|
|
|
$array->setLogger(function($retorno) { |
45
|
|
|
$this->assertEquals($retorno['type'], ArrayDebugger::TYPE_SET); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$array['quatro'] = 4; |
49
|
|
|
|
50
|
|
|
$array->setLogger(function($retorno) { |
51
|
|
|
$this->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_SET); |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
$teste = $array['hum']; |
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* offsetExists |
58
|
|
|
*/ |
59
|
|
|
isset($array['hum']); |
60
|
|
|
/** |
61
|
|
|
* offsetUnset |
62
|
|
|
*/ |
63
|
|
|
unset($array['quatro']); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
public function testIsset() { |
|
|
|
|
67
|
|
|
|
68
|
|
|
$array = new ArrayDebugger($this->base); |
69
|
|
|
|
70
|
|
|
$array->setLogger(function($retorno) { |
71
|
|
|
$this->assertEquals($retorno['type'], ArrayDebugger::TYPE_EXISTS); |
72
|
|
|
}); |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* offsetExists |
77
|
|
|
*/ |
78
|
|
|
isset($array['hum']); |
79
|
|
|
|
80
|
|
|
$array->setLogger(function($retorno) { |
81
|
|
|
$this->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_EXISTS); |
82
|
|
|
}); |
83
|
|
|
|
84
|
|
|
$array['quatro'] = 4; |
85
|
|
|
|
86
|
|
|
$teste = $array['hum']; |
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* offsetUnset |
90
|
|
|
*/ |
91
|
|
|
unset($array['quatro']); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
View Code Duplication |
public function testUnset() { |
|
|
|
|
95
|
|
|
|
96
|
|
|
$array = new ArrayDebugger($this->base); |
97
|
|
|
|
98
|
|
|
$array->setLogger(function($retorno) { |
99
|
|
|
$this->assertEquals($retorno['type'], ArrayDebugger::TYPE_UNSET); |
100
|
|
|
}); |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* offsetUnset |
104
|
|
|
*/ |
105
|
|
|
unset($array['dois']); |
106
|
|
|
|
107
|
|
|
$array->setLogger(function($retorno) { |
108
|
|
|
$this->assertNotEquals($retorno['type'], ArrayDebugger::TYPE_UNSET); |
109
|
|
|
}); |
110
|
|
|
/** |
111
|
|
|
* offsetExists |
112
|
|
|
*/ |
113
|
|
|
isset($array['hum']); |
114
|
|
|
|
115
|
|
|
$array['quatro'] = 4; |
116
|
|
|
|
117
|
|
|
$teste = $array['hum']; |
|
|
|
|
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
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.