/** * The entry method. * * @return int */ public function main() { $dryRun = false; $classes = []; while (false !== ($c = $this->getOption($v))) { switch ($c) { case 'n': foreach ($this->parser->parseSpecialValue($v) as $namespace) { $namespace = trim(str_replace('.', '\\', $namespace), '\\'); if (false === ($pos = strpos($namespace, '\\'))) { throw new Console\Exception('Namespace %s is too short.', 0, $namespace); } $tail = substr($namespace, strpos($namespace, '\\') + 1); $root = resolve('hoa://Library/' . str_replace('\\', '/', $tail)); $classes = array_merge($classes, static::findClasses($root, $namespace)); } break; case 'c': foreach ($this->parser->parseSpecialValue($v) as $class) { $classes[] = $class; } break; case 'd': $dryRun = $v; break; case '__ambiguous': $this->resolveOptionAmbiguity($v); break; case 'h': case '?': default: return $this->usage(); } } if (empty($classes)) { return $this->usage(); } foreach ($classes as $i => $class) { $classes[$i] = str_replace('.', '\\', $class); } $generator = new \Atoum\PraspelExtension\Praspel\Generator(); $generator->setTestNamespacer(function ($namespace) { $parts = explode('\\', $namespace); return implode('\\', array_slice($parts, 0, 2)) . '\\Test\\Praspel\\Unit' . (isset($parts[2]) ? '\\' . implode('\\', array_slice($parts, 2)) : ''); }); $phpBinary = Consistency::getPHPBinary() ?: Console\Processus::localte('php'); $envVariable = '__HOA_ATOUM_PRASPEL_EXTENSION_' . md5(Consistency::uuid()); $reflection = null; $buffer = null; $reflectionner = new Console\Processus($phpBinary); $reflectionner->on('input', function (Event\Bucket $bucket) use($envVariable) { $bucket->getSource()->writeAll('<?php' . "\n" . 'require_once \'' . dirname(__DIR__) . DS . '.bootstrap.atoum.php\';' . "\n" . '$class = getenv(\'' . $envVariable . '\');' . "\n" . 'if (class_exists(\'\\mageekguy\\atoum\\scripts\\runner\', false)) {' . "\n" . ' \\atoum\\scripts\\runner::disableAutorun();' . "\n" . '}' . "\n" . '$reflection = new \\Atoum\\PraspelExtension\\Praspel\\Reflection\\RClass($class);' . "\n" . 'echo serialize($reflection), "\\n";'); return false; }); $reflectionner->on('output', function (Event\Bucket $bucket) use(&$buffer) { $data = $bucket->getData(); $buffer .= $data['line'] . "\n"; return; }); $reflectionner->on('stop', function () use(&$buffer, &$reflection) { $handle = @unserialize($buffer); if (false === $handle) { echo $buffer, "\n"; return; } $reflection = $handle; return; }); foreach ($classes as $class) { $status = $class . ' (in '; echo ' ⌛ ', $status; putenv($envVariable . '=' . $class); $buffer = null; $reflection = null; $reflectionner->run(); $output = $generator->generate($reflection); $parts = explode('\\', $class); $paths = resolve('hoa://Library/' . $parts[1] . '/' . 'Test/Praspel/Unit/' . implode('/', array_slice($parts, 2)) . '.php', false, true); $max = 0; $thePath = 0; foreach ($paths as $path) { $length = Ustring\Search::lcp($reflection->getFilename(), $path); if ($length > $max) { $thePath = $path; } } $statusTail = (40 < strlen($thePath) ? '…' . substr($thePath, -39) : $thePath) . ')'; echo $statusTail; $status .= $statusTail; if (false === $reflection->isInstantiable()) { Console\Cursor::clear('↔'); echo ' ⚡️ ', $status, '; not instantiable.', "\n"; continue; } $dirname = dirname($thePath); if (false === is_dir($dirname)) { if (false === $dryRun) { mkdir($dirname, 0755, true); } else { echo "\n", static::info('Creating directory: ' . $dirname . '.'); } } if (false === $dryRun) { file_put_contents($thePath, $output); } else { echo "\n", static::info('Content of the ' . $thePath . ':'), "\n"; Console\Cursor::colorize('foreground(yellow)'); echo ' ┏', "\n", ' ┃ ', str_replace("\n", "\n" . ' ┃ ', trim($output)), "\n", ' ┗', "\n"; Console\Cursor::colorize('foreground(normal)'); } Console\Cursor::clear('↔'); echo ' ', Console\Chrome\Text::colorize('✔︎', 'foreground(green)'), ' ', $status, "\n"; } return; }