1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace hanneskod\readmetester\Runner; |
6
|
|
|
|
7
|
|
|
use hanneskod\readmetester\Attribute\Isolate; |
8
|
|
|
use hanneskod\readmetester\Example\ExampleObj; |
|
|
|
|
9
|
|
|
use hanneskod\readmetester\Example\ExampleStoreInterface; |
10
|
|
|
use hanneskod\readmetester\Utils\Loader; |
11
|
|
|
|
12
|
|
|
final class EvalRunner implements RunnerInterface |
13
|
|
|
{ |
14
|
|
|
private const ERROR_CODES = [ |
15
|
|
|
E_ERROR => 'E_ERROR', |
16
|
|
|
E_WARNING => 'E_WARNING', |
17
|
|
|
E_PARSE => 'E_PARSE', |
18
|
|
|
E_NOTICE => 'E_NOTICE', |
19
|
|
|
E_CORE_ERROR => 'E_CORE_ERROR', |
20
|
|
|
E_CORE_WARNING => 'E_CORE_WARNING', |
21
|
|
|
E_COMPILE_ERROR => 'E_COMPILE_ERROR', |
22
|
|
|
E_COMPILE_WARNING => 'E_COMPILE_WARNING', |
23
|
|
|
E_USER_ERROR => 'E_USER_ERROR', |
24
|
|
|
E_USER_WARNING => 'E_USER_WARNING', |
25
|
|
|
E_USER_NOTICE => 'E_USER_NOTICE', |
26
|
|
|
E_STRICT => 'E_STRICT', |
27
|
|
|
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', |
28
|
|
|
E_DEPRECATED => 'E_DEPRECATED', |
29
|
|
|
E_USER_DEPRECATED => 'E_USER_DEPRECATED', |
30
|
|
|
E_ALL => 'E_ALL', |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
public function setBootstrap(string $filename): void |
34
|
|
|
{ |
35
|
|
|
if ($filename) { |
36
|
|
|
require_once $filename; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function run(ExampleStoreInterface $examples): iterable |
41
|
|
|
{ |
42
|
|
|
foreach ($examples->getExamples() as $example) { |
43
|
|
|
if ($example->hasAttribute(Isolate::class)) { |
44
|
|
|
yield new SkippedOutcome($example, 'requires isolation'); |
|
|
|
|
45
|
|
|
continue; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
yield $this->runExample($example); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function runExample(ExampleObj $example): OutcomeInterface |
53
|
|
|
{ |
54
|
|
|
$errorOutput = ''; |
55
|
|
|
|
56
|
|
|
set_error_handler( |
57
|
|
|
function (int $errno, string $errstr) use (&$errorOutput) { |
58
|
|
|
if (($errno & error_reporting()) == $errno) { |
59
|
|
|
$errorOutput = sprintf( |
60
|
|
|
'%s: %s', |
61
|
|
|
self::ERROR_CODES[$errno] ?? '', |
62
|
|
|
$errstr |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return true; |
67
|
|
|
}, |
68
|
|
|
E_ALL |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
ob_start(); |
72
|
|
|
|
73
|
|
|
try { |
74
|
|
|
Loader::loadRaw($example->getCodeBlock()->getCode()); |
75
|
|
|
} catch (\Throwable $exception) { |
76
|
|
|
restore_error_handler(); |
77
|
|
|
ob_end_clean(); |
78
|
|
|
return new ErrorOutcome($example, (string)$exception); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
restore_error_handler(); |
82
|
|
|
|
83
|
|
|
$output = ob_get_clean(); |
84
|
|
|
|
85
|
|
|
if ($errorOutput) { |
86
|
|
|
return new ErrorOutcome($example, $errorOutput); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if ($output) { |
90
|
|
|
return new OutputOutcome($example, $output); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return new VoidOutcome($example); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths