X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=peridot.php;fp=peridot.php;h=e4ce997c19d1fe9209e4c3772e1ef94780595a89;hb=8ef054b51c681e7822133b38f7c5ed9dd2a0f29c;hp=0000000000000000000000000000000000000000;hpb=3ed732562787562d0115a3cbef3f0f5129473b7d;p=m6w6%2Fseekat diff --git a/peridot.php b/peridot.php new file mode 100644 index 0000000..e4ce997 --- /dev/null +++ b/peridot.php @@ -0,0 +1,108 @@ +register(); + + $emitter->on('peridot.reporters', function(InputInterface $input, ReporterFactory $reporterFactory) { + $reporterFactory->register( + 'seekat', + 'Spec + Text Code coverage reporter', + function(AnonymousReporter $ar) use ($reporterFactory) { + + return new class($reporterFactory, $ar->getConfiguration(), $ar->getOutput(), $ar->getEventEmitter()) extends AbstractBaseReporter { + private $reporters = []; + + function __construct(ReporterFactory $factory, Configuration $configuration, OutputInterface $output, EventEmitter $eventEmitter) { + fprintf(STDERR, "Creating reporters\n"); + $this->reporters[] = $factory->create("spec"); + $this->reporters[] = $factory->create("text-code-coverage"); + parent::__construct($configuration, $output, $eventEmitter); + } + + function init() { + } + function __2call($method, array $args) { + fprintf(STDERR, "Calling %s\n", $method); + foreach ($this->reporters as $reporter) { + $output = $reporter->$method(...$args); + } + return $output; + } + }; + } + ); + }); + + $emitter->on('code-coverage.start', function (AbstractCodeCoverageReporter $reporter) { + $reporter->addDirectoryToWhitelist(__DIR__."/lib") + ->addDirectoryToWhitelist(__DIR__."/tests"); + }); + + $emitter->on("peridot.start", function(Environment $env, Application $app) { + $app->setCatchExceptions(false); + $definition = $env->getDefinition(); + $definition->getArgument("path") + ->setDefault(implode(" ", glob("tests/*"))); + $definition->getOption("reporter") + ->setDefault("seekat"); + }); + + $log = new class extends AbstractProcessingHandler { + private $records = []; + protected function write(array $record) { + $this->records[] = $record["formatted"]; + } + function clean() { + $this->records = []; + } + function dump(OutputInterface $output) { + if ($this->records) { + $output->writeln(["\n", "Debug log:", "==========="]); + $output->write($this->records); + $this->clean(); + } + } + }; + $emitter->on("suite.start", function(Suite $suite) use($log) { + $headers = []; + if (($token = getenv("GITHUB_TOKEN"))) { + $headers["Authentication"] = "token $token"; + } elseif (function_exists("posix_isatty") && defined("STDIN") && posix_isatty(STDIN)) { + fprintf(STDOUT, "GITHUB_TOKEN is not set in the environment, enter Y to continue without: "); + fflush(STDOUT); + if (strncasecmp(fgets(STDIN), "Y", 1)) { + exit; + } + } else { + throw new Exception("GITHUB_TOKEN is not set in the environment"); + } + $suite->getScope()->api = new API($headers, null, null, new Logger("seekat", [$log])); + }); + + $emitter->on("test.failed", function(Test $test, \Throwable $e) { + + }); + $emitter->on("test.passed", function() use($log) { + $log->clean(); + }); + $emitter->on("peridot.end", function($exitCode, InputInterface $input, OutputInterface $output) use($log) { + $log->dump($output); + }); +};