/** * The entry method. * * @return int */ public function main() { $directories = []; $files = []; $namespaces = []; $filter = []; $debug = false; $php = null; $concurrentProcesses = 2; while (false !== ($c = $this->getOption($v))) { switch ($c) { case 'a': $iterator = new File\Finder(); $iterator->in(resolve('hoa://Library/', true, true))->directories()->maxDepth(1); foreach ($iterator as $fileinfo) { $libraryName = $fileinfo->getBasename(); if (true === Consistency::isKeyword($libraryName)) { continue; } $pathname = resolve('hoa://Library/' . $libraryName); $tests = $pathname . DS . 'Test' . DS; $manualTests = $tests . 'Unit'; $automaticTests = $tests . 'Praspel' . DS . 'Unit'; if (is_dir($manualTests)) { $directories[] = $manualTests; } if (is_dir($automaticTests)) { $directories[] = $automaticTests; } } break; case 'l': foreach ($this->parser->parseSpecialValue($v) as $library) { $libraryName = ucfirst(strtolower($library)); $pathname = resolve('hoa://Library/' . $libraryName); $tests = $pathname . DS . 'Test'; if (!is_dir($tests)) { throw new Console\Exception('Library %s does not exist or has no test.', 0, $libraryName); } $directories[] = $tests; $namespaces[] = 'Hoa\\' . $libraryName; } break; case 'n': foreach ($this->parser->parseSpecialValue($v) as $namespace) { $namespace = str_replace('.', '\\', $namespace); $parts = explode('\\', $namespace); if (2 > count($parts)) { throw new Console\Exception('Namespace %s is too short.', 1, $namespace); } $head = resolve('hoa://Library/' . $parts[1]); $tail = implode(DS, array_slice($parts, 2)); $namespaceDirectory = $head . DS . $tail; if (!is_dir($namespaceDirectory)) { throw new Console\Exception('Namespace %s does not exist.', 2, $namespace); } $tests = $head . DS . 'Test' . DS; $manualTests = $tests . 'Unit' . DS . $tail; $automaticTests = $tests . 'Praspel' . DS . 'Unit' . DS . $tail; if (is_dir($manualTests)) { $directories[] = $manualTests; } if (is_dir($automaticTests)) { $directories[] = $automaticTests; } $namespaces[] = $namespace; } break; case 'd': foreach ($this->parser->parseSpecialValue($v) as $directory) { if (!is_dir($directory)) { throw new Console\Exception('Directory %s does not exist.', 3, $directory); } $directories[] = $directory; } break; case 'f': foreach ($this->parser->parseSpecialValue($v) as $file) { if (!file_exists($file)) { throw new Console\Exception('File %s does not exist.', 4, $file); } $files[] = $file; } break; case 'F': $filter = $v; break; case 'D': $debug = $v; break; case 'p': $php = $v; break; case 'P': $concurrentProcesses = intval($v); break; case '__ambiguous': $this->resolveOptionAmbiguity($v); break; case 'h': case '?': default: return $this->usage(); break; } } $atoum = 'atoum'; if (WITH_COMPOSER) { $atoum = __DIR__ . DS . '..' . DS . '..' . DS . '..' . DS . 'bin' . DS . 'atoum'; } elseif (isset($_SERVER['HOA_ATOUM_BIN'])) { $atoum = $_SERVER['HOA_ATOUM_BIN']; } $command = $atoum . ' --configurations ' . resolve('hoa://Library/Test/.atoum.php') . ' --bootstrap-file ' . resolve('hoa://Library/Test/.bootstrap.atoum.php') . ' --force-terminal' . ' --max-children-number ' . $concurrentProcesses; if (true === $debug) { $command .= ' --debug'; } if (null !== $php) { $command .= ' --php ' . $php; } if (!empty($directories)) { $command .= ' --directories ' . implode(' ', $directories); } elseif (!empty($files)) { $command .= ' --files ' . implode(' ', $files); } else { return $this->usage(); } if (!empty($namespaces)) { $command .= ' --namespaces ' . implode(' ', $namespaces); } if (!empty($filter)) { $command .= ' --filter \'' . str_replace('\'', '\'"\'"\'', $filter) . '\''; } $_server = $_SERVER; $_server['HOA_PREVIOUS_CWD'] = getcwd(); $processus = new Processus($command, null, null, resolve('hoa://Library/Test/'), $_server); $processus->on('input', function ($bucket) { return false; }); $processus->on('output', function ($bucket) { $data = $bucket->getData(); echo $data['line'], "\n"; return; }); $processus->run(); return; }