3 use Evenement\EventEmitterInterface
as EventEmitter
;
4 use Monolog\Handler\AbstractProcessingHandler
;
6 use Peridot\Configuration
;
7 use Peridot\Console\Application
;
8 use Peridot\Console\Environment
;
9 use Peridot\Core\Suite
;
10 use Peridot\Core\Test
;
12 use Symfony\Component\Console\Input\InputInterface
;
13 use Symfony\Component\Console\Output\OutputInterface
;
14 use Peridot\Reporter\CodeCoverage\AbstractCodeCoverageReporter
;
15 use Peridot\Reporter\CodeCoverageReporters
;
16 use Peridot\Reporter\ReporterFactory
;
17 use Peridot\Reporter\AnonymousReporter
;
18 use Peridot\Reporter\AbstractBaseReporter
;
20 return function(EventEmitter
$emitter) {
21 (new CodeCoverageReporters($emitter))->register();
23 $emitter->on('peridot.reporters', function(InputInterface
$input, ReporterFactory
$reporterFactory) {
24 $reporterFactory->register(
26 'Spec + Text Code coverage reporter',
27 function(AnonymousReporter
$ar) use ($reporterFactory) {
29 return new class($reporterFactory, $ar->getConfiguration(), $ar->getOutput(), $ar->getEventEmitter()) extends AbstractBaseReporter
{
30 private $reporters = [];
32 function __construct(ReporterFactory
$factory, Configuration
$configuration, OutputInterface
$output, EventEmitter
$eventEmitter) {
33 fprintf(STDERR
, "Creating reporters\n");
34 $this->reporters
[] = $factory->create("spec");
35 $this->reporters
[] = $factory->create("text-code-coverage");
36 parent
::__construct($configuration, $output, $eventEmitter);
41 function __2call($method, array $args) {
42 fprintf(STDERR
, "Calling %s\n", $method);
43 foreach ($this->reporters
as $reporter) {
44 $output = $reporter->$method(...$args);
53 $emitter->on('code-coverage.start', function (AbstractCodeCoverageReporter
$reporter) {
54 $reporter->addDirectoryToWhitelist(__DIR__
."/lib")
55 ->addDirectoryToWhitelist(__DIR__
."/tests");
58 $emitter->on("peridot.start", function(Environment
$env, Application
$app) {
59 $app->setCatchExceptions(false);
60 $definition = $env->getDefinition();
61 $definition->getArgument("path")
62 ->setDefault(implode(" ", glob("tests/*")));
63 $definition->getOption("reporter")
64 ->setDefault("seekat");
67 $log = new class extends AbstractProcessingHandler
{
68 private $records = [];
69 protected function write(array $record) {
70 $this->records
[] = $record["formatted"];
75 function dump(OutputInterface
$output) {
77 $output->writeln(["\n", "Debug log:", "==========="]);
78 $output->write($this->records
);
83 $emitter->on("suite.start", function(Suite
$suite) use($log) {
85 if (($token = getenv("GITHUB_TOKEN"))) {
86 $headers["Authentication"] = "token $token";
87 } elseif (function_exists("posix_isatty") && defined("STDIN") && posix_isatty(STDIN
)) {
88 fprintf(STDOUT
, "GITHUB_TOKEN is not set in the environment, enter Y to continue without: ");
90 if (strncasecmp(fgets(STDIN
), "Y", 1)) {
94 throw new Exception("GITHUB_TOKEN is not set in the environment");
96 $suite->getScope()->api
= new API($headers, null, null, new Logger("seekat", [$log]));
99 $emitter->on("test.failed", function(Test
$test, \Throwable
$e) {
102 $emitter->on("test.passed", function() use($log) {
105 $emitter->on("peridot.end", function($exitCode, InputInterface
$input, OutputInterface
$output) use($log) {