#!/usr/bin/env php parser = $parser; } public function afterTraverse(array $nodes) { /** @var Node\Stmt\Expression $main */ $main = array_pop($nodes); $main = $main->expr; foreach ($this->wrapCoroutine($main) as $node) { $nodes[] = $node; } return $nodes; } /** * @param PhpParser\Node\Expr\FuncCall $expr */ protected function wrapCoroutine($expr): array { $exit = array_pop($expr->name->stmts); $expr->name->stmts[] = new Return_(new Node\Expr\Variable($exit->expr->expr->name)); /** @var PhpParser\Node\Stmt\Expression[] $nodes */ $nodes = $this->parser->parse(' $argv) { // --prepend /path/to/file if ($argv === "--prepend") { unset($_SERVER["argv"][$index]); if (isset($_SERVER["argv"][$index + 1])) { $prepend = $_SERVER["argv"][$index + 1]; unset($_SERVER["argv"][$index + 1]); } break; } // --prepend=/path/to/file if (strpos($argv, "--prepend=") === 0) { $prepend = substr($argv, 10); unset($_SERVER["argv"][$index]); break; } } if ($prepend !== null && file_exists($prepend)) { require $prepend; } })(); $code = 0; Swoole\Coroutine::set(["hook_flags" => SWOOLE_HOOK_ALL, "exit_condition" => function () { return Swoole\Coroutine::stats()["coroutine_num"] === 0; }]); Swoole\Coroutine\run(function () use(&$code) { try { } catch (Swoole\ExitException $e) { $code = $e->getStatus(); } Swoole\Timer::clearAll(); Hyperf\Coordinator\CoordinatorManager::until(Hyperf\Coordinator\Constants::WORKER_EXIT)->resume(); }); die($code); '); $nodes[3]->expr->args[0]->value->stmts[0]->stmts[0] = new Node\Stmt\Expression(new Node\Expr\Assign( new Node\Expr\Variable('code'), $expr )); return $nodes; } } $parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7); $printer = new Standard(); $traverser = new NodeTraverser(); $code = file_get_contents(__DIR__ . '/../vendor/pestphp/pest/bin/pest'); $stmts = $parser->parse($code); $traverser->addVisitor(new RunInCoroutineVisitor($parser)); $stmts = $traverser->traverse($stmts); $code = $printer->prettyPrint($stmts); // TODO: Unknown reason $code = ltrim($code, '?>' . PHP_EOL); file_put_contents($coPest = __DIR__ . '/co-pest', $code); chmod($coPest, 0755); file_put_contents($coPest = __DIR__ . '/../src/testing/co-pest', $code); chmod($coPest, 0755);