These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | class EnvironmentCheckerTest extends SapphireTest |
||
3 | { |
||
4 | public function setUpOnce() |
||
5 | { |
||
6 | parent::setUpOnce(); |
||
7 | |||
8 | Phockito::include_hamcrest(); |
||
9 | } |
||
10 | |||
11 | public function setUp() |
||
12 | { |
||
13 | parent::setUp(); |
||
14 | |||
15 | Config::nest(); |
||
16 | } |
||
17 | |||
18 | public function tearDown() |
||
19 | { |
||
20 | Config::unnest(); |
||
21 | |||
22 | parent::tearDown(); |
||
23 | } |
||
24 | |||
25 | public function testOnlyLogsWithErrors() |
||
26 | { |
||
27 | Config::inst()->update('EnvironmentChecker', 'log_results_warning', true); |
||
28 | Config::inst()->update('EnvironmentChecker', 'log_results_error', true); |
||
29 | EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckNoErrors()); |
||
30 | $checker = Phockito::spy( |
||
31 | 'EnvironmentChecker', |
||
32 | 'test suite', |
||
33 | 'test' |
||
34 | ); |
||
35 | |||
36 | $response = $checker->index(); |
||
0 ignored issues
–
show
|
|||
37 | Phockito::verify($checker, 0)->log(anything(), anything()); |
||
38 | EnvironmentCheckSuite::reset(); |
||
39 | } |
||
40 | |||
41 | View Code Duplication | public function testLogsWithWarnings() |
|
42 | { |
||
43 | Config::inst()->update('EnvironmentChecker', 'log_results_warning', true); |
||
44 | Config::inst()->update('EnvironmentChecker', 'log_results_error', false); |
||
45 | EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings()); |
||
46 | EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors()); |
||
47 | $checker = Phockito::spy( |
||
48 | 'EnvironmentChecker', |
||
49 | 'test suite', |
||
50 | 'test' |
||
51 | ); |
||
52 | |||
53 | $response = $checker->index(); |
||
0 ignored issues
–
show
$response is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
54 | Phockito::verify($checker, 1)->log(containsString('warning'), anything()); |
||
55 | Phockito::verify($checker, 0)->log(containsString('error'), anything()); |
||
56 | EnvironmentCheckSuite::reset(); |
||
57 | } |
||
58 | |||
59 | View Code Duplication | public function testLogsWithErrors() |
|
60 | { |
||
61 | Config::inst()->update('EnvironmentChecker', 'log_results_error', false); |
||
62 | Config::inst()->update('EnvironmentChecker', 'log_results_error', true); |
||
63 | EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings()); |
||
64 | EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors()); |
||
65 | $checker = Phockito::spy( |
||
66 | 'EnvironmentChecker', |
||
67 | 'test suite', |
||
68 | 'test' |
||
69 | ); |
||
70 | |||
71 | $response = $checker->index(); |
||
0 ignored issues
–
show
$response is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
72 | Phockito::verify($checker, 0)->log(containsString('warning'), anything()); |
||
73 | Phockito::verify($checker, 1)->log(containsString('error'), anything()); |
||
74 | EnvironmentCheckSuite::reset(); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | class EnvironmentCheckerTest_CheckNoErrors implements EnvironmentCheck, TestOnly |
||
79 | { |
||
80 | public function check() |
||
81 | { |
||
82 | return array(EnvironmentCheck::OK, ''); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | class EnvironmentCheckerTest_CheckWarnings implements EnvironmentCheck, TestOnly |
||
87 | { |
||
88 | public function check() |
||
89 | { |
||
90 | return array(EnvironmentCheck::WARNING, "test warning"); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | class EnvironmentCheckerTest_CheckErrors implements EnvironmentCheck, TestOnly |
||
95 | { |
||
96 | public function check() |
||
97 | { |
||
98 | return array(EnvironmentCheck::ERROR, "test error"); |
||
99 | } |
||
100 | } |
||
101 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.