From 6c82e777e11c799190117803f2a9c08be25bbaa2 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 18 Oct 2012 22:09:48 +0200 Subject: [PATCH] added Nette\Tester --- .gitignore | 2 + composer.json | 6 + tests/DibiFluent.cloning.phpt | 45 +--- tests/NetteTest/Assert.php | 138 ----------- tests/NetteTest/RunTests.php | 43 ---- tests/NetteTest/TestCase.php | 400 -------------------------------- tests/NetteTest/TestHelpers.php | 312 ------------------------- tests/NetteTest/TestRunner.php | 230 ------------------ tests/bootstrap.php | 18 ++ tests/initialize.php | 26 --- 10 files changed, 34 insertions(+), 1186 deletions(-) create mode 100644 .gitignore delete mode 100644 tests/NetteTest/Assert.php delete mode 100644 tests/NetteTest/RunTests.php delete mode 100644 tests/NetteTest/TestCase.php delete mode 100644 tests/NetteTest/TestHelpers.php delete mode 100644 tests/NetteTest/TestRunner.php create mode 100644 tests/bootstrap.php delete mode 100644 tests/initialize.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..85f9bc68 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/tools +/composer.lock diff --git a/composer.json b/composer.json index 987da1fd..c49f44b6 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,12 @@ "homepage": "http://davidgrudl.com" } ], + "require-dev": { + "nette/tester": "@dev" + }, + "config": { + "vendor-dir": "tools" + }, "autoload": { "classmap": ["dibi/"] } diff --git a/tests/DibiFluent.cloning.phpt b/tests/DibiFluent.cloning.phpt index 95dcb4bf..fd075994 100644 --- a/tests/DibiFluent.cloning.phpt +++ b/tests/DibiFluent.cloning.phpt @@ -4,17 +4,15 @@ * Test: Cloning of DibiFluent * * @author David Grudl - * @category Dibi - * @subpackage UnitTests */ -require dirname(__FILE__) . '/initialize.php'; +require dirname(__FILE__) . '/bootstrap.php'; -dibi::connect($config['sqlite']); +dibi::connect($config['sqlite3']); $fluent = new DibiFluent(dibi::getConnection()); @@ -23,8 +21,8 @@ $dolly = clone $fluent; $dolly->where('y=1'); $dolly->clause('FOO'); -$fluent->test(); -$dolly->test(); +Assert::same( 'SELECT * FROM [table] WHERE x=1', (string) $fluent ); +Assert::same( 'SELECT * FROM [table] WHERE x=1 AND y=1 FOO', (string) $dolly ); @@ -32,8 +30,8 @@ $fluent = dibi::select('id')->from('table')->where('id = %i',1); $dolly = clone $fluent; $dolly->where('cd = %i',5); -$fluent->test(); -$dolly->test(); +Assert::same( 'SELECT [id] FROM [table] WHERE id = 1', (string) $fluent ); +Assert::same( 'SELECT [id] FROM [table] WHERE id = 1 AND cd = 5', (string) $dolly ); @@ -41,32 +39,5 @@ $fluent = dibi::select("*")->from("table"); $dolly = clone $fluent; $dolly->removeClause("select")->select("count(*)"); -$fluent->test(); -$dolly->test(); - - - -__halt_compiler() ?> - -------EXPECT------ -SELECT * -FROM [table] -WHERE x=1 - -SELECT * -FROM [table] -WHERE x=1 AND y=1 FOO - -SELECT [id] -FROM [table] -WHERE id = 1 - -SELECT [id] -FROM [table] -WHERE id = 1 AND cd = 5 - -SELECT * -FROM [table] - -SELECT count(*) -FROM [table] +Assert::same( 'SELECT * FROM [table]', (string) $fluent ); +Assert::same( 'SELECT count(*) FROM [table]', (string) $dolly ); diff --git a/tests/NetteTest/Assert.php b/tests/NetteTest/Assert.php deleted file mode 100644 index 0e63e2fa..00000000 --- a/tests/NetteTest/Assert.php +++ /dev/null @@ -1,138 +0,0 @@ -getCode() ? '#' . $var->getCode() . ' ' : '') . $var->getMessage(); - - } elseif (is_object($var)) { - $arr = (array) $var; - return "object(" . get_class($var) . ") (" . count($arr) . ")"; - - } elseif (is_resource($var)) { - return "resource(" . get_resource_type($var) . ")"; - - } else { - return "unknown type"; - } - } - - - - /** - * Returns message and file and line from call stack. - * @param string - * @return void - */ - private static function note($message) - { - echo $message; - $trace = debug_backtrace(); - if (isset($trace[1]['file'], $trace[1]['line'])) { - echo ' in file ' . $trace[1]['file'] . ' on line ' . $trace[1]['line']; - } - echo "\n\n"; - } - -} diff --git a/tests/NetteTest/RunTests.php b/tests/NetteTest/RunTests.php deleted file mode 100644 index d2d641ed..00000000 --- a/tests/NetteTest/RunTests.php +++ /dev/null @@ -1,43 +0,0 @@ - -Nette Test Framework (v0.3) ---------------------------- - -Usage: - php RunTests.php [options] [file or directory] - -Options: - -p Specify PHP-CGI executable to run. - -c Look for php.ini in directory or use as php.ini. - -d key=val Define INI entry 'key' with value 'val'. - -l Specify path to shared library files (LD_LIBRARY_PATH) - -e Load php environment - -s Show information about skipped tests - -parseConfigFile(); - $manager->parseArguments(); - $res = $manager->run(); - die($res ? 0 : 1); - -} catch (Exception $e) { - echo 'Error: ', $e->getMessage(), "\n"; - die(2); -} diff --git a/tests/NetteTest/TestCase.php b/tests/NetteTest/TestCase.php deleted file mode 100644 index aa02b272..00000000 --- a/tests/NetteTest/TestCase.php +++ /dev/null @@ -1,400 +0,0 @@ -file = (string) $testFile; - $this->sections = self::parseSections($this->file); - } - - - - /** - * Runs single test. - * @return void - */ - public function run() - { - // pre-skip? - $options = $this->sections['options']; - if (isset($options['skip'])) { - $message = $options['skip'] ? $options['skip'] : 'No message.'; - throw new TestCaseException($message, TestCaseException::SKIPPED); - - } elseif (isset($options['phpversion'])) { - $operator = '>='; - if (preg_match('#^(<=|le|<|lt|==|=|eq|!=|<>|ne|>=|ge|>|gt)#', $options['phpversion'], $matches)) { - $options['phpversion'] = trim(substr($options['phpversion'], strlen($matches[1]))); - $operator = $matches[1]; - } - if (version_compare($options['phpversion'], $this->phpVersion, $operator)) { - throw new TestCaseException("Requires PHP $operator $options[phpversion].", TestCaseException::SKIPPED); - } - } - - $this->execute(); - $output = $this->output; - $headers = array_change_key_case(self::parseLines($this->headers, ':'), CASE_LOWER); - $tests = 0; - - // post-skip? - if (isset($headers['x-nette-test-skip'])) { - throw new TestCaseException($headers['x-nette-test-skip'], TestCaseException::SKIPPED); - } - - // compare output - $expectedOutput = $this->getExpectedOutput(); - if ($expectedOutput !== NULL) { - $tests++; - $binary = (bool) preg_match('#[\x00-\x08\x0B\x0C\x0E-\x1F]#', $expectedOutput); - if ($binary) { - if ($expectedOutput !== $output) { - throw new TestCaseException("Binary output doesn't match."); - } - } else { - $output = self::normalize($output, isset($options['keeptrailingspaces'])); - $expectedOutput = self::normalize($expectedOutput, isset($options['keeptrailingspaces'])); - if (!$this->compare($output, $expectedOutput)) { - throw new TestCaseException("Output doesn't match."); - } - } - } - - // compare headers - $expectedHeaders = $this->getExpectedHeaders(); - if ($expectedHeaders !== NULL) { - $tests++; - $expectedHeaders = self::normalize($expectedHeaders, FALSE); - $expectedHeaders = array_change_key_case(self::parseLines($expectedHeaders, ':'), CASE_LOWER); - foreach ($expectedHeaders as $name => $header) { - if (!isset($headers[$name])) { - throw new TestCaseException("Missing header '$name'."); - - } elseif (!$this->compare($headers[$name], $header)) { - throw new TestCaseException("Header '$name' doesn't match."); - } - } - } - - if (!$tests) { // expecting no output - if (trim($output) !== '') { - throw new TestCaseException("Empty output doesn't match."); - } - } - } - - - - /** - * Sets PHP command line. - * @param string - * @param string - * @param string - * @return TestCase provides a fluent interface - */ - public function setPhp($binary, $args, $environment) - { - if (isset(self::$cachedPhp[$binary])) { - $this->phpVersion = self::$cachedPhp[$binary]; - - } else { - exec($environment . escapeshellarg($binary) . ' -v', $output, $res); - if ($res !== 0 && $res !== 255) { - throw new Exception("Unable to execute '$binary -v'."); - } - - if (!preg_match('#^PHP (\S+).*cli#i', $output[0], $matches)) { - throw new Exception("Unable to detect PHP version (output: $output[0])."); - } - - $this->phpVersion = self::$cachedPhp[$binary] = $matches[1]; - } - - $this->cmdLine = $environment . escapeshellarg($binary) . $args; - return $this; - } - - - - /** - * Execute test. - * @return array - */ - private function execute() - { - $this->headers = $this->output = NULL; - - $tempFile = tempnam('', 'tmp'); - if (!$tempFile) { - throw new Exception("Unable to create temporary file."); - } - - $command = $this->cmdLine; - if (isset($this->sections['options']['phpini'])) { - foreach (explode(';', $this->sections['options']['phpini']) as $item) { - $command .= " -d " . escapeshellarg(trim($item)); - } - } - $command .= ' ' . escapeshellarg($this->file) . ' > ' . escapeshellarg($tempFile); - - chdir(dirname($this->file)); - exec($command, $foo, $res); - if ($res === 255) { - // exit_status 255 => parse or fatal error - - } elseif ($res !== 0) { - throw new Exception("Unable to execute '$command'."); - - } - - $this->output = file_get_contents($tempFile); - unlink($tempFile); - } - - - - /** - * Returns test file section. - * @return string - */ - public function getSection($name) - { - return isset($this->sections[$name]) ? $this->sections[$name] : NULL; - } - - - - /** - * Returns test name. - * @return string - */ - public function getName() - { - return $this->sections['options']['name']; - } - - - - /** - * Returns test output. - * @return string - */ - public function getOutput() - { - return $this->output; - } - - - - /** - * Returns output headers. - * @return string - */ - public function getHeaders() - { - return $this->headers; - } - - - - /** - * Returns expected output. - * @return string - */ - public function getExpectedOutput() - { - if (isset($this->sections['expect'])) { - return $this->sections['expect']; - - } elseif (is_file($expFile = str_replace('.phpt', '', $this->file) . '.expect')) { - return file_get_contents($expFile); - - } else { - return NULL; - } - } - - - - /** - * Returns expected headers. - * @return string - */ - public function getExpectedHeaders() - { - return $this->getSection('expectheaders'); - } - - - - /********************* helpers ****************d*g**/ - - - - /** - * Splits file into sections. - * @param string file - * @return array - */ - public static function parseSections($testFile) - { - $content = file_get_contents($testFile); - $sections = array( - 'options' => array(), - ); - - // phpDoc - $phpDoc = preg_match('#^/\*\*(.*?)\*/#ms', $content, $matches) ? trim($matches[1]) : ''; - preg_match_all('#^\s*\*\s*@(\S+)(.*)#mi', $phpDoc, $matches, PREG_SET_ORDER); - foreach ($matches as $match) { - $sections['options'][strtolower($match[1])] = isset($match[2]) ? trim($match[2]) : TRUE; - } - $sections['options']['name'] = preg_match('#^\s*\*\s*TEST:(.*)#mi', $phpDoc, $matches) ? trim($matches[1]) : $testFile; - - // file parts - $tmp = preg_split('#^-{3,}([^\s-]+)-{1,}(?:\r?\n|$)#m', $content, -1, PREG_SPLIT_DELIM_CAPTURE); - $i = 1; - while (isset($tmp[$i])) { - $sections[strtolower($tmp[$i])] = $tmp[$i+1]; - $i += 2; - } - return $sections; - } - - - - /** - * Splits HTTP headers into array. - * @param string - * @param string - * @return array - */ - public static function parseLines($raw, $separator) - { - $headers = array(); - foreach (explode("\r\n", $raw) as $header) { - $a = strpos($header, $separator); - if ($a !== FALSE) { - $headers[trim(substr($header, 0, $a))] = (string) trim(substr($header, $a + 1)); - } - } - return $headers; - } - - - - /** - * Compares results. - * @param string - * @param string - * @return bool - */ - public static function compare($left, $right) - { - $right = strtr($right, array( - '%a%' => '[^\r\n]+', // one or more of anything except the end of line characters - '%a?%'=> '[^\r\n]*', // zero or more of anything except the end of line characters - '%A%' => '.+', // one or more of anything including the end of line characters - '%A?%'=> '.*', // zero or more of anything including the end of line characters - '%s%' => '[\t ]+', // one or more white space characters except the end of line characters - '%s?%'=> '[\t ]*', // zero or more white space characters except the end of line characters - '%S%' => '\S+', // one or more of characters except the white space - '%S?%'=> '\S*', // zero or more of characters except the white space - '%c%' => '[^\r\n]', // a single character of any sort (except the end of line) - '%d%' => '[0-9]+', // one or more digits - '%d?%'=> '[0-9]*', // zero or more digits - '%i%' => '[+-]?[0-9]+', // signed integer value - '%f%' => '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', // floating point number - '%h%' => '[0-9a-fA-F]+',// one or more HEX digits - '%ns%'=> '(?:[_0-9a-zA-Z\\\\]+\\\\|N)?',// PHP namespace - '%[^' => '[^', // reg-exp - '%[' => '[', // reg-exp - ']%' => ']+', // reg-exp - - '.' => '\.', '\\' => '\\\\', '+' => '\+', '*' => '\*', '?' => '\?', '[' => '\[', '^' => '\^', ']' => '\]', '$' => '\$', '(' => '\(', ')' => '\)', // preg quote - '{' => '\{', '}' => '\}', '=' => '\=', '!' => '\!', '>' => '\>', '<' => '\<', '|' => '\|', ':' => '\:', '-' => '\-', "\x00" => '\000', '#' => '\#', // preg quote - )); - - return (bool) preg_match("#^$right$#s", $left); - } - - - - /** - * Normalizes whitespace - * @param string - * @param bool - * @return string - */ - public static function normalize($s, $keepTrailingSpaces) - { - $s = str_replace("\n", PHP_EOL, str_replace("\r\n", "\n", $s)); // normalize EOL - if (!$keepTrailingSpaces) { - $s = preg_replace("#[\t ]+(\r?\n)#", '$1', $s); // multiline right trim - $s = rtrim($s); // ending trim - } - return $s; - } - -} - - - -/** - * Single test exception. - * - * @author David Grudl - * @package Nette\Test - */ -class TestCaseException extends Exception -{ - const SKIPPED = 1; - -} diff --git a/tests/NetteTest/TestHelpers.php b/tests/NetteTest/TestHelpers.php deleted file mode 100644 index 719e8049..00000000 --- a/tests/NetteTest/TestHelpers.php +++ /dev/null @@ -1,312 +0,0 @@ -getBasename() === '.gitignore') { - // ignore - } elseif ($entry->isDir()) { - rmdir($entry); - } else { - unlink($entry); - } - } - } - - - - /** - * Returns current test section. - * @param string - * @param string - * @return mixed - */ - public static function getSection($file, $section) - { - if (!isset(self::$sections[$file])) { - self::$sections[$file] = TestCase::parseSections($file); - } - - $lowerSection = strtolower($section); - if (!isset(self::$sections[$file][$lowerSection])) { - throw new Exception("Missing section '$section' in file '$file'."); - } - - if (in_array($section, array('GET', 'POST', 'SERVER'), TRUE)) { - return TestCase::parseLines(self::$sections[$file][$lowerSection], '='); - } else { - return self::$sections[$file][$lowerSection]; - } - } - - - - /** - * Writes new message. - * @param string - * @return void - */ - public static function note($message = NULL) - { - echo $message ? "$message\n\n" : "===\n\n"; - } - - - - /** - * Dumps information about a variable in readable format. - * @param mixed variable to dump - * @param string - * @return mixed variable itself or dump - */ - public static function dump($var, $message = NULL) - { - if ($message) { - echo $message . (preg_match('#[.:?]$#', $message) ? ' ' : ': '); - } - - self::_dump($var, 0); - echo "\n"; - return $var; - } - - - - private static function _dump(& $var, $level = 0) - { - static $tableUtf, $tableBin, $reBinary = '#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u'; - if ($tableUtf === NULL) { - foreach (range("\x00", "\xFF") as $ch) { - if (ord($ch) < 32 && strpos("\r\n\t", $ch) === FALSE) $tableUtf[$ch] = $tableBin[$ch] = '\\x' . str_pad(dechex(ord($ch)), 2, '0', STR_PAD_LEFT); - elseif (ord($ch) < 127) $tableUtf[$ch] = $tableBin[$ch] = $ch; - else { $tableUtf[$ch] = $ch; $tableBin[$ch] = '\\x' . dechex(ord($ch)); } - } - $tableBin["\\"] = '\\\\'; - $tableBin["\r"] = '\\r'; - $tableBin["\n"] = '\\n'; - $tableBin["\t"] = '\\t'; - $tableUtf['\\x'] = $tableBin['\\x'] = '\\\\x'; - } - - if (is_bool($var)) { - echo ($var ? 'TRUE' : 'FALSE') . "\n"; - - } elseif ($var === NULL) { - echo "NULL\n"; - - } elseif (is_int($var)) { - echo "$var\n"; - - } elseif (is_float($var)) { - $var = (string) $var; - if (strpos($var, '.') === FALSE) $var .= '.0'; - echo "$var\n"; - - } elseif (is_string($var)) { - $s = strtr($var, preg_match($reBinary, $var) || preg_last_error() ? $tableBin : $tableUtf); - echo "\"$s\"\n"; - - } elseif (is_array($var)) { - echo "array("; - $space = str_repeat("\t", $level); - - static $marker; - if ($marker === NULL) $marker = uniqid("\x00", TRUE); - if (empty($var)) { - - } elseif (isset($var[$marker])) { - echo " *RECURSION* "; - - } elseif ($level < self::$maxDepth) { - echo "\n"; - $vector = range(0, count($var) - 1) === array_keys($var); - $var[$marker] = 0; - foreach ($var as $k => &$v) { - if ($k === $marker) continue; - if ($vector) { - echo "$space\t"; - } else { - $k = is_int($k) ? $k : '"' . strtr($k, preg_match($reBinary, $k) || preg_last_error() ? $tableBin : $tableUtf) . '"'; - echo "$space\t$k => "; - } - self::_dump($v, $level + 1); - } - unset($var[$marker]); - echo "$space"; - - } else { - echo " ... "; - } - echo ")\n"; - - } elseif ($var instanceof Exception) { - echo 'Exception ', get_class($var), ': ', ($var->getCode() ? '#' . $var->getCode() . ' ' : '') . $var->getMessage(), "\n"; - - } elseif (is_object($var)) { - $arr = (array) $var; - echo get_class($var) . "("; - $space = str_repeat("\t", $level); - - static $list = array(); - if (empty($arr)) { - - } elseif (in_array($var, $list, TRUE)) { - echo " *RECURSION* "; - - } elseif ($level < self::$maxDepth) { - echo "\n"; - $list[] = $var; - foreach ($arr as $k => &$v) { - $m = ''; - if ($k[0] === "\x00") { - $m = $k[1] === '*' ? ' protected' : ' private'; - $k = substr($k, strrpos($k, "\x00") + 1); - } - $k = strtr($k, preg_match($reBinary, $k) || preg_last_error() ? $tableBin : $tableUtf); - echo "$space\t\"$k\"$m => "; - echo self::_dump($v, $level + 1); - } - array_pop($list); - echo "$space"; - - } else { - echo " ... "; - } - echo ")\n"; - - } elseif (is_resource($var)) { - echo get_resource_type($var) . " resource\n"; - - } else { - echo "unknown type\n"; - } - } - - - - /** - * Custom exception handler. - * @param Exception - * @return void - */ - public static function exceptionHandler(Exception $exception) - { - echo 'Error: Uncaught '; - echo $exception; - } - - - - /** - * Coverage saving helper. - * @return void - */ - public static function prepareSaveCoverage() - { - register_shutdown_function(array(__CLASS__, 'saveCoverage')); - } - - - - /** - * Saves information about code coverage. - * @return void - */ - public static function saveCoverage() - { - $file = dirname(__FILE__) . '/coverage.tmp'; - $coverage = @unserialize(file_get_contents($file)); - $root = realpath(dirname(__FILE__) . '/../../Nette') . DIRECTORY_SEPARATOR; - - foreach (xdebug_get_code_coverage() as $filename => $lines) { - if (strncmp($root, $filename, strlen($root))) continue; - - foreach ($lines as $num => $val) { - if (empty($coverage[$filename][$num]) || $val > 0) { - $coverage[$filename][$num] = $val; // -1 => untested; -2 => dead code - } - } - } - - file_put_contents($file, serialize($coverage)); - } - - - - /** - * Skips this test. - * @return void - */ - public static function skip($message = 'No message.') - { - header('X-Nette-Test-Skip: '. $message); - exit; - } - -} diff --git a/tests/NetteTest/TestRunner.php b/tests/NetteTest/TestRunner.php deleted file mode 100644 index 3eebfe49..00000000 --- a/tests/NetteTest/TestRunner.php +++ /dev/null @@ -1,230 +0,0 @@ -path)) { - $files = array($this->path); - } else { - $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path)); - } - - foreach ($files as $entry) { - $entry = (string) $entry; - $info = pathinfo($entry); - if (!isset($info['extension']) || $info['extension'] !== 'phpt') { - continue; - } - - $count++; - $testCase = new TestCase($entry); - $testCase->setPhp($this->phpBinary, $this->phpArgs, $this->phpEnvironment); - - try { - $testCase->run(); - echo '.'; - $passed[] = array($testCase->getName(), $entry); - - } catch (TestCaseException $e) { - if ($e->getCode() === TestCaseException::SKIPPED) { - echo 's'; - $skipped[] = array($testCase->getName(), $entry, $e->getMessage()); - - } else { - echo 'F'; - $failed[] = array($testCase->getName(), $entry, $e->getMessage()); - - $this->log($entry, $testCase->getOutput(), self::OUTPUT); - $this->log($entry, $testCase->getExpectedOutput(), self::EXPECTED); - - if ($testCase->getExpectedHeaders() !== NULL) { - $this->log($entry, $testCase->getHeaders(), self::OUTPUT, self::HEADERS); - $this->log($entry, $testCase->getExpectedHeaders(), self::EXPECTED, self::HEADERS); - } - } - } - } - - $failedCount = count($failed); - $skippedCount = count($skipped); - - if ($this->displaySkipped && $skippedCount) { - echo "\n\nSkipped:\n"; - foreach ($skipped as $i => $item) { - list($name, $file, $message) = $item; - echo "\n", ($i + 1), ") $name\n $message\n $file\n"; - } - } - - if (!$count) { - echo "No tests found\n"; - - } elseif ($failedCount) { - echo "\n\nFailures:\n"; - foreach ($failed as $i => $item) { - list($name, $file, $message) = $item; - echo "\n", ($i + 1), ") $name\n $message\n $file\n"; - } - echo "\nFAILURES! ($count tests, $failedCount failures, $skippedCount skipped)\n"; - return FALSE; - - } else { - echo "\n\nOK ($count tests, $skippedCount skipped)\n"; - } - return TRUE; - } - - - - /** - * Returns output file for logging. - * @param string - * @param string - * @param string - * @param string - * @return void - */ - public function log($testFile, $content, $type, $section = '') - { - $file = dirname($testFile) . '/' . $type . '/' . basename($testFile, '.phpt') . ($section ? ".$section" : '') . '.raw'; - @mkdir(dirname($file)); // @ - directory may already exist - file_put_contents($file, $content); - } - - - - /** - * Parses configuration file. - * @return void - */ - public function parseConfigFile() - { - $configFile = dirname(__FILE__) . '/config.ini'; - if (file_exists($configFile)) { - $this->config = parse_ini_file($configFile, TRUE); - if ($this->config === FALSE) { - throw new Exception('Config file parsing failed.'); - } - foreach ($this->config as & $environment) { - $environment += array( - 'binary' => 'php-cgi', - 'args' => '', - 'environment' => '', - ); - // shorthand options - if (isset($environment['php.ini'])) { - $environment['args'] .= ' -c '. escapeshellarg($environment['php.ini']); - } - if (isset($environment['libraries'])) { - $environment['environment'] .= 'LD_LIBRARY_PATH='. escapeshellarg($environment['libraries']) .' '; - } - } - } - } - - - - /** - * Parses command line arguments. - * @return void - */ - public function parseArguments() - { - $this->phpBinary = 'php-cgi'; - $this->phpArgs = ''; - $this->phpEnvironment = ''; - $this->path = getcwd(); // current directory - - $args = new ArrayIterator(array_slice(isset($_SERVER['argv']) ? $_SERVER['argv'] : array(), 1)); - foreach ($args as $arg) { - if (!preg_match('#^[-/][a-z]$#', $arg)) { - if ($path = realpath($arg)) { - $this->path = $path; - } else { - throw new Exception("Invalid path '$arg'."); - } - - } else switch ($arg[1]) { - case 'p': - $args->next(); - $this->phpBinary = $args->current(); - break; - case 'c': - case 'd': - $args->next(); - $this->phpArgs .= " -$arg[1] " . escapeshellarg($args->current()); - break; - case 'l': - $args->next(); - $this->phpEnvironment .= 'LD_LIBRARY_PATH='. escapeshellarg($args->current()) . ' '; - break; - case 'e': - $args->next(); - $name = $args->current(); - if (!isset($this->config[$name])) { - throw new Exception("Unknown environment name '$name'."); - } - $this->phpBinary = $this->config[$name]['binary']; - $this->phpArgs = $this->config[$name]['args']; - $this->phpEnvironment = $this->config[$name]['environment']; - break; - case 's': - $this->displaySkipped = TRUE; - break; - default: - throw new Exception("Unknown option -$arg[1]."); - exit; - } - } - } - -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..b7174513 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,18 @@ +