99 */
1010namespace PHPUnit \TextUI \Command ;
1111
12+ use const E_ALL ;
1213use const PHP_EOL ;
1314use function extension_loaded ;
15+ use function in_array ;
1416use function ini_get ;
1517use function max ;
1618use function sprintf ;
2628 */
2729final readonly class CheckPhpConfigurationCommand implements Command
2830{
29- /**
30- * @var non-empty-array<non-empty-string, array{expectedValue: non-empty-string, valueForConfiguration: non-empty-string, requiredExtensions: list<non-empty-string>}>
31- */
32- private const SETTINGS = [
33- 'display_errors ' => [
34- 'expectedValue ' => '1 ' ,
35- 'valueForConfiguration ' => 'On ' ,
36- 'requiredExtensions ' => [],
37- ],
38- 'display_startup_errors ' => [
39- 'expectedValue ' => '1 ' ,
40- 'valueForConfiguration ' => 'On ' ,
41- 'requiredExtensions ' => [],
42- ],
43- 'error_reporting ' => [
44- 'expectedValue ' => '-1 ' ,
45- 'valueForConfiguration ' => '-1 ' ,
46- 'requiredExtensions ' => [],
47- ],
48- 'xdebug.show_exception_trace ' => [
49- 'expectedValue ' => '0 ' ,
50- 'valueForConfiguration ' => '0 ' ,
51- 'requiredExtensions ' => ['xdebug ' ],
52- ],
53- 'zend.assertions ' => [
54- 'expectedValue ' => '1 ' ,
55- 'valueForConfiguration ' => '1 ' ,
56- 'requiredExtensions ' => [],
57- ],
58- 'assert.exception ' => [
59- 'expectedValue ' => '1 ' ,
60- 'valueForConfiguration ' => '1 ' ,
61- 'requiredExtensions ' => [],
62- ],
63- 'memory_limit ' => [
64- 'expectedValue ' => '-1 ' ,
65- 'valueForConfiguration ' => '-1 ' ,
66- 'requiredExtensions ' => [],
67- ],
68- ];
6931 private bool $ colorize ;
7032
7133 public function __construct ()
@@ -78,7 +40,7 @@ public function execute(): Result
7840 $ lines = [];
7941 $ shellExitCode = 0 ;
8042
81- foreach (self :: SETTINGS as $ name => $ setting ) {
43+ foreach ($ this -> settings () as $ name => $ setting ) {
8244 foreach ($ setting ['requiredExtensions ' ] as $ extension ) {
8345 if (!extension_loaded ($ extension )) {
8446 // @codeCoverageIgnoreStart
@@ -89,7 +51,7 @@ public function execute(): Result
8951
9052 $ actualValue = ini_get ($ name );
9153
92- if ($ actualValue === $ setting ['expectedValue ' ] ) {
54+ if (in_array ( $ actualValue, $ setting ['expectedValues ' ], true ) ) {
9355 $ check = $ this ->ok ();
9456 } else {
9557 $ check = $ this ->notOk ($ actualValue );
@@ -157,4 +119,48 @@ private function notOk(string $actualValue): string
157119 return Color::colorizeTextBox ('fg-red, bold ' , $ message );
158120 // @codeCoverageIgnoreEnd
159121 }
122+
123+ /**
124+ * @return non-empty-array<non-empty-string, array{expectedValues: non-empty-list<non-empty-string>, valueForConfiguration: non-empty-string, requiredExtensions: list<non-empty-string>}>
125+ */
126+ private function settings (): array
127+ {
128+ return [
129+ 'display_errors ' => [
130+ 'expectedValues ' => ['1 ' ],
131+ 'valueForConfiguration ' => 'On ' ,
132+ 'requiredExtensions ' => [],
133+ ],
134+ 'display_startup_errors ' => [
135+ 'expectedValues ' => ['1 ' ],
136+ 'valueForConfiguration ' => 'On ' ,
137+ 'requiredExtensions ' => [],
138+ ],
139+ 'error_reporting ' => [
140+ 'expectedValues ' => ['-1 ' , (string ) E_ALL ],
141+ 'valueForConfiguration ' => '-1 ' ,
142+ 'requiredExtensions ' => [],
143+ ],
144+ 'xdebug.show_exception_trace ' => [
145+ 'expectedValues ' => ['0 ' ],
146+ 'valueForConfiguration ' => '0 ' ,
147+ 'requiredExtensions ' => ['xdebug ' ],
148+ ],
149+ 'zend.assertions ' => [
150+ 'expectedValues ' => ['1 ' ],
151+ 'valueForConfiguration ' => '1 ' ,
152+ 'requiredExtensions ' => [],
153+ ],
154+ 'assert.exception ' => [
155+ 'expectedValues ' => ['1 ' ],
156+ 'valueForConfiguration ' => '1 ' ,
157+ 'requiredExtensions ' => [],
158+ ],
159+ 'memory_limit ' => [
160+ 'expectedValues ' => ['-1 ' ],
161+ 'valueForConfiguration ' => '-1 ' ,
162+ 'requiredExtensions ' => [],
163+ ],
164+ ];
165+ }
160166}
0 commit comments