function getBaseSslUrl() { $listen = getenv('TESTS_HTTPS_LISTEN'); if ($listen === FALSE) { Tester\Environment::skip("The 'TESTS_HTTPS_LISTEN' environment variable is missing. Do you use '--setup tests/setup.php' option?"); } return "https://{$listen}"; }
<?php require __DIR__ . '/../../../../../../vendor/autoload.php'; Tester\Environment::setup(); date_default_timezone_set('Europe/Prague'); $configurator = new Nette\Configurator(); //$configurator->setDebugMode(false); //Tracy\Debugger::enable(Tracy\Debugger::PRODUCTION); //$configurator->enableDebugger(__DIR__ . '/log'); $configurator->setTempDirectory(__DIR__ . '/temp'); $configurator->createRobotLoader()->addDirectory(__DIR__ . '/..')->register();
--colors [1|0] Enable or disable colors. --coverage <path> Generate code coverage report to file. --coverage-src <path> Path to source code. -h | --help This help. XX , array('-c' => array(Cmd::REALPATH => TRUE), '--watch' => array(Cmd::REPEATABLE => TRUE, Cmd::REALPATH => TRUE), '--setup' => array(Cmd::REALPATH => TRUE), 'paths' => array(Cmd::REPEATABLE => TRUE, Cmd::VALUE => getcwd()), '--debug' => array(), '--coverage-src' => array(Cmd::REALPATH => TRUE))); if (isset($_SERVER['argv']) && ($tmp = array_search('-log', $_SERVER['argv']))) { $_SERVER['argv'][$tmp] = '--log'; } $options = $cmd->parse(); Tester\Environment::$debugMode = (bool) $options['--debug']; if (isset($options['--colors'])) { Tester\Environment::$useColors = (bool) $options['--colors']; } elseif ($options['--tap']) { Tester\Environment::$useColors = FALSE; } if ($cmd->isEmpty() || $options['--help']) { $cmd->help(); exit; } $phpArgs = ''; if ($options['-c']) { $phpArgs .= ' -c ' . Tester\Helpers::escapeArg($options['-c']); } elseif (!$options['--info']) { echo "Note: No php.ini is used.\n"; } foreach ($options['-d'] as $item) { $phpArgs .= ' -d ' . Tester\Helpers::escapeArg($item); } $php = new Tester\Runner\PhpExecutable($options['-p'], $phpArgs);
require __DIR__ . '/Runner/OutputHandler.php'; require __DIR__ . '/Runner/Output/Logger.php'; require __DIR__ . '/Runner/Output/TapPrinter.php'; require __DIR__ . '/Runner/Output/ConsolePrinter.php'; require __DIR__ . '/Framework/Helpers.php'; require __DIR__ . '/Framework/Environment.php'; require __DIR__ . '/Framework/Assert.php'; require __DIR__ . '/Framework/Dumper.php'; require __DIR__ . '/Framework/DataProvider.php'; use Tester\Runner\CommandLine as Cmd; Tester\Environment::setup(); $cmd = new Cmd("\nNette Tester (v0.9.5)\n---------------------\nUsage:\n\ttester.php [options] [<test file> | <directory>]...\n\nOptions:\n\t-p <path> Specify PHP executable to run (default: php-cgi).\n\t-c <path> Look for php.ini in directory <path> or use <path> as php.ini.\n\t-log <path> Write log to file <path>.\n\t-d <key=value>... Define INI entry 'key' with value 'val'.\n\t-s Show information about skipped tests.\n\t--tap Generate Test Anything Protocol.\n\t-j <num> Run <num> jobs in parallel.\n\t-w | --watch <path> Watch directory.\n\t--colors [1|0] Enable or disable colors.\n\t-h | --help This help.\n\n", array('-c' => array(Cmd::REALPATH => TRUE), '--watch' => array(Cmd::REPEATABLE => TRUE, Cmd::REALPATH => TRUE), 'paths' => array(Cmd::REPEATABLE => TRUE, Cmd::VALUE => getcwd()), '--debug' => array())); $options = $cmd->parse(); Tester\Environment::$debugMode = (bool) $options['--debug']; if (isset($options['--colors'])) { Tester\Environment::$useColors = (bool) $options['--colors']; } if ($cmd->isEmpty() || $options['--help']) { $cmd->help(); exit; } $phpArgs = $options['-c'] ? '-n -c ' . escapeshellarg($options['-c']) : '-n'; foreach ($options['-d'] as $item) { $phpArgs .= ' -d ' . escapeshellarg($item); } $runner = new Tester\Runner\Runner(new Tester\Runner\PhpExecutable($options['-p'], $phpArgs)); $runner->paths = $options['paths']; $runner->jobCount = max(1, (int) $options['-j']); $runner->outputHandlers[] = $options['--tap'] ? new Tester\Runner\Output\TapPrinter($runner) : new Tester\Runner\Output\ConsolePrinter($runner, $options['-s']); if ($options['-log']) { echo "Log: {$options['-log']}\n";
public function prepareArguments(array $args, $testsDir) { $args = new \Nette\Iterators\CachingIterator($args); $parameters = []; //Resolve tests dir from command line input $pathToTests = NULL; $environmentVariables = []; foreach ($args as $arg) { if (in_array($arg, ['-C', '-s', '--stop-on-fail', '-i', '--info', '-h', '--help'])) { //singles $parameters[$arg] = TRUE; continue; } if (preg_match('~^-[a-z0-9_/-]+~i', $arg)) { //remember option with value if (isset($parameters[$arg])) { //e.g. multiple '-w' $previousValue = $parameters[$arg]; if (is_array($previousValue)) { $parameters[$arg][] = $args->getNextValue(); } else { unset($parameters[$arg]); $parameters[$arg][] = $previousValue; $parameters[$arg][] = $args->getNextValue(); } } else { $parameters[$arg] = $args->getNextValue(); } $args->next(); } else { //environment variables or $pathToTests if (preg_match('~[a-z0-9_]+=[a-z0-9_]+~i', $arg)) { //linux environment variable $environmentVariables[] = $arg; } else { $pathToTests = $arg; } } } //Scaffold if (array_key_exists('--scaffold', $parameters)) { if (!isset($parameters['--scaffold'])) { die("Error: specify tests bootstrap for scaffold like this: '--scaffold <bootstrap.php>'\n"); } $scaffoldBootstrap = $parameters['--scaffold']; $scaffoldDir = dirname($scaffoldBootstrap); rtrim($scaffoldDir, DIRECTORY_SEPARATOR); $outputFolderContent = glob("{$scaffoldDir}/*"); if (($key = array_search($scaffoldBootstrap, $outputFolderContent)) !== FALSE) { unset($outputFolderContent[$key]); } if (count($outputFolderContent) !== 0) { die("Error: please use different empty folder - I don't want to destroy your work\n"); } require $scaffoldBootstrap; \Nette\Utils\FileSystem::createDir($scaffoldDir . '/_temp'); $scaffold = new \Testbench\Scaffold\TestsGenerator(); $scaffold->generateTests($scaffoldDir); \Tester\Environment::$checkAssertions = FALSE; die("Tests generated to the folder '{$scaffoldDir}'\n"); } //Specify PHP interpreter to run if (!array_key_exists('-p', $parameters)) { $parameters['-p'] = 'php'; } //Show information about skipped tests if (!array_key_exists('-s', $parameters)) { $parameters['-s'] = TRUE; } //Look for php.ini file $os = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'win' : 'unix'; $iniFile = $testsDir . "/php-{$os}.ini"; if (!array_key_exists('-c', $parameters)) { if (is_file($iniFile)) { $parameters['-c'] = $iniFile; } else { $parameters['-C'] = TRUE; } } //Purge temp directory if (isset($parameters['--temp'])) { $dir = $parameters['--temp']; } else { $dir = $testsDir . '/_temp'; } unset($parameters['--temp']); if (!is_dir($dir)) { mkdir($dir); } $rdi = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS); $rii = new \RecursiveIteratorIterator($rdi, \RecursiveIteratorIterator::CHILD_FIRST); foreach ($rii as $entry) { if ($entry->isDir()) { rmdir($entry); } else { unlink($entry); } } if ($pathToTests === NULL) { $pathToTests = $testsDir; } $args = $environmentVariables; foreach ($parameters as $key => $value) { //return to the Tester format if ($value === TRUE) { //singles $args[] = $key; continue; } if (is_array($value)) { foreach ($value as $v) { $args[] = $key; $args[] = $v; } } else { $args[] = $key; $args[] = $value; } } $args[] = $pathToTests; return $args; }
/** * This method is called before a test is executed. * @return void */ protected function setUp() { parent::setUp(); Tester\Environment::lock('database', __DIR__ . '/../temp'); $this->connection->loadFile(__DIR__ . '/../DBstructure.sql'); }