3 use Monolog\Handler\AbstractProcessingHandler
;
5 use Peridot\Cli\Environment
;
6 use Peridot\Cli\Application
;
7 use Peridot\Configuration
;
8 use Peridot\Core\Suite
;
10 use Peridot\Plugin\Scenarios
;
12 use Symfony\Component\Console\Input\InputInterface
;
13 use Symfony\Component\Console\Output\OutputInterface
;
15 return function(\Peridot\EventEmitterInterface
$emitter) {
16 Scenarios\Plugin
::register($emitter);
18 $emitter->on("peridot.start", function(Environment
$env, Application
$app) {
19 $app->setCatchExceptions(false);
20 $definition = $env->getDefinition();
21 $definition->getArgument("path")
22 ->setDefault(implode(" ", glob("tests/*")));
25 $log = new class extends AbstractProcessingHandler
{
26 private $records = [];
27 protected function write(array $record) {
28 $this->records
[] = $record["formatted"];
33 function dump(OutputInterface
$output) {
35 $output->writeln(["\n", "Debug log:", "==========="]);
36 $output->write($this->records
);
41 $emitter->on("suite.start", function(Suite
$suite) use(&$headers, $log) {
43 if (($token = getenv("GITHUB_TOKEN"))) {
44 $headers["Authorization"] = "token $token";
45 } elseif (function_exists("posix_isatty") && defined("STDIN") && posix_isatty(STDIN
)) {
46 fprintf(STDOUT
, "GITHUB_TOKEN is not set in the environment, enter Y to continue without: ");
48 if (strncasecmp(fgets(STDIN
), "Y", 1)) {
52 throw new Exception("GITHUB_TOKEN is not set in the environment");
54 $suite->getScope()->amp
= new API(API\Future\amp
(),
55 $headers, null, null, new Logger("amp", [$log]));
56 $suite->getScope()->react
= new API(API\Future\react
(),
57 $headers, null, null, new Logger("react", [$log]));
60 $emitter->on("test.failed", function(Test
$test, \Throwable
$e) {
63 $emitter->on("test.passed", function() use($log) {
66 $emitter->on("peridot.end", function($exitCode, InputInterface
$input, OutputInterface
$output) use($log) {