|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\EnvironmentCheck\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Phockito; |
|
6
|
|
|
use Psr\Log\LoggerInterface; |
|
7
|
|
|
use SilverStripe\Core\Config\Config; |
|
8
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
9
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
10
|
|
|
use SilverStripe\Dev\TestOnly; |
|
11
|
|
|
use SilverStripe\EnvironmentCheck\EnvironmentCheck; |
|
12
|
|
|
use SilverStripe\EnvironmentCheck\EnvironmentChecker; |
|
13
|
|
|
use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class EnvironmentCheckerTest |
|
17
|
|
|
* |
|
18
|
|
|
* @package environmentcheck |
|
19
|
|
|
*/ |
|
20
|
|
|
class EnvironmentCheckerTest extends SapphireTest |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritDoc} |
|
24
|
|
|
* @var bool |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $usesDatabase = true; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritDoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function setUpBeforeClass() |
|
32
|
|
|
{ |
|
33
|
|
|
parent::setUpBeforeClass(); |
|
34
|
|
|
|
|
35
|
|
|
Phockito::include_hamcrest(); |
|
36
|
|
|
|
|
37
|
|
|
$logger = Injector::inst()->get(LoggerInterface::class); |
|
38
|
|
|
if ($logger instanceof \Monolog\Logger) { |
|
39
|
|
|
// It logs to stderr by default - disable |
|
40
|
|
|
$logger->pushHandler(new \Monolog\Handler\NullHandler); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritDoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setUp() |
|
48
|
|
|
{ |
|
49
|
|
|
parent::setUp(); |
|
50
|
|
|
Config::nest(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritDoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
public function tearDown() |
|
57
|
|
|
{ |
|
58
|
|
|
Config::unnest(); |
|
59
|
|
|
parent::tearDown(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testOnlyLogsWithErrors() |
|
63
|
|
|
{ |
|
64
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
|
|
|
|
|
65
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
|
|
|
|
|
66
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckNoErrors()); |
|
67
|
|
|
$checker = Phockito::spy( |
|
68
|
|
|
EnvironmentChecker::class, |
|
69
|
|
|
'test suite', |
|
70
|
|
|
'test' |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
$response = $checker->index(); |
|
|
|
|
|
|
74
|
|
|
Phockito::verify($checker, 0)->log(\anything(), \anything()); |
|
75
|
|
|
EnvironmentCheckSuite::reset(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
View Code Duplication |
public function testLogsWithWarnings() |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
|
|
|
|
|
81
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
|
|
|
|
|
82
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings()); |
|
83
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors()); |
|
84
|
|
|
$checker = Phockito::spy( |
|
85
|
|
|
EnvironmentChecker::class, |
|
86
|
|
|
'test suite', |
|
87
|
|
|
'test' |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$response = $checker->index(); |
|
|
|
|
|
|
91
|
|
|
Phockito::verify($checker, 1)->log(containsString('warning'), \anything()); |
|
92
|
|
|
Phockito::verify($checker, 0)->log(containsString('error'), \anything()); |
|
93
|
|
|
EnvironmentCheckSuite::reset(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
View Code Duplication |
public function testLogsWithErrors() |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
|
|
|
|
|
99
|
|
|
Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
|
|
|
|
|
100
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings()); |
|
101
|
|
|
EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors()); |
|
102
|
|
|
$checker = Phockito::spy( |
|
103
|
|
|
EnvironmentChecker::class, |
|
104
|
|
|
'test suite', |
|
105
|
|
|
'test' |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
$response = $checker->index(); |
|
|
|
|
|
|
109
|
|
|
Phockito::verify($checker, 0)->log(containsString('warning'), \anything()); |
|
110
|
|
|
Phockito::verify($checker, 1)->log(containsString('error'), \anything()); |
|
111
|
|
|
EnvironmentCheckSuite::reset(); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
class EnvironmentCheckerTest_CheckNoErrors implements EnvironmentCheck, TestOnly |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
public function check() |
|
118
|
|
|
{ |
|
119
|
|
|
return [EnvironmentCheck::OK, '']; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
class EnvironmentCheckerTest_CheckWarnings implements EnvironmentCheck, TestOnly |
|
|
|
|
|
|
124
|
|
|
{ |
|
125
|
|
|
public function check() |
|
126
|
|
|
{ |
|
127
|
|
|
return [EnvironmentCheck::WARNING, 'test warning']; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
class EnvironmentCheckerTest_CheckErrors implements EnvironmentCheck, TestOnly |
|
|
|
|
|
|
132
|
|
|
{ |
|
133
|
|
|
public function check() |
|
134
|
|
|
{ |
|
135
|
|
|
return [EnvironmentCheck::ERROR, 'test error']; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.