diff --git a/tests/DibiFluent.cloning.phpt b/tests/DibiFluent.cloning.phpt new file mode 100644 index 00000000..95dcb4bf --- /dev/null +++ b/tests/DibiFluent.cloning.phpt @@ -0,0 +1,72 @@ +select('*')->from('table')->where('x=1'); +$dolly = clone $fluent; +$dolly->where('y=1'); +$dolly->clause('FOO'); + +$fluent->test(); +$dolly->test(); + + + +$fluent = dibi::select('id')->from('table')->where('id = %i',1); +$dolly = clone $fluent; +$dolly->where('cd = %i',5); + +$fluent->test(); +$dolly->test(); + + + +$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] diff --git a/tests/NetteTest/Assert.php b/tests/NetteTest/Assert.php new file mode 100644 index 00000000..af0ec064 --- /dev/null +++ b/tests/NetteTest/Assert.php @@ -0,0 +1,138 @@ +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 new file mode 100644 index 00000000..d2d641ed --- /dev/null +++ b/tests/NetteTest/RunTests.php @@ -0,0 +1,43 @@ + +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 new file mode 100644 index 00000000..e84b5498 --- /dev/null +++ b/tests/NetteTest/TestCase.php @@ -0,0 +1,400 @@ +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 new file mode 100644 index 00000000..eb6a0ee7 --- /dev/null +++ b/tests/NetteTest/TestHelpers.php @@ -0,0 +1,312 @@ +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 new file mode 100644 index 00000000..ade71e09 --- /dev/null +++ b/tests/NetteTest/TestRunner.php @@ -0,0 +1,230 @@ +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/config.ini b/tests/config.ini new file mode 100644 index 00000000..8245b567 --- /dev/null +++ b/tests/config.ini @@ -0,0 +1,67 @@ +[mysql] +driver = mysql +host = localhost +username = dibi +password = dibi +database = dibi_test +charset = utf8 + +[mysqli] +driver = mysqli +host = localhost +username = dibi +password = dibi +database = dibi_test +charset = utf8 + +[sqlite] +driver = sqlite +database = DIR "/data/sample.sdb" + +[sqlite3] +driver = sqlite3 +database = DIR "/data/sample.sdb3" + +[odbc] +driver = odbc +username = dibi +password = dibi +dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" DIR "/data/sample.mdb" + +[postgresql] +driver = postgre +host = localhost +port = 5432 +username = dibi +password = dibi +database = dibi_test +persistent = TRUE + +[sqlite-pdo] +driver = pdo +dsn = "sqlite2::" DIR "/data/sample.sdb" + +[mysql-pdo] +driver = pdo +dsn = "mysql:dbname=dibi_test;host=localhost" +username = dibi +password = dibi + +[mssql] +driver = mssql +host = localhost +username = dibi +password = dibi + +[mssql2005] +driver = mssql2005 +host = "(local)" +username = dibi +password = dibi +database = dibi_test + +[oracle] +driver = oracle +username = dibi +password = dibi +database = dibi_test diff --git a/tests/data/sample.mdb b/tests/data/sample.mdb new file mode 100644 index 00000000..464a336c Binary files /dev/null and b/tests/data/sample.mdb differ diff --git a/tests/data/sample.mysql b/tests/data/sample.mysql new file mode 100644 index 00000000..3f949910 --- /dev/null +++ b/tests/data/sample.mysql @@ -0,0 +1,149 @@ +-- phpMyAdmin SQL Dump +-- version 2.11.1.2 +-- http://www.phpmyadmin.net +-- +-- Počítač: localhost +-- Vygenerováno: Neděle 02. prosince 2007, 19:49 +-- Verze MySQL: 5.0.45 +-- Verze PHP: 5.2.1 + +SET FOREIGN_KEY_CHECKS=0; + +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; + +-- +-- Databáze: `dibi` +-- + +-- -------------------------------------------------------- + +-- +-- Struktura tabulky `customers` +-- + +DROP TABLE IF EXISTS `customers`; +CREATE TABLE IF NOT EXISTS `customers` ( + `customer_id` int(11) NOT NULL auto_increment, + `name` varchar(100) default NULL, + PRIMARY KEY (`customer_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ; + +-- +-- Vypisuji data pro tabulku `customers` +-- + +INSERT INTO `customers` (`customer_id`, `name`) VALUES +(1, 'Dave Lister'), +(2, 'Arnold Rimmer'), +(3, 'The Cat'), +(4, 'Holly'), +(5, 'Kryten'), +(6, 'Kristine Kochanski'); + +-- -------------------------------------------------------- + +-- +-- Struktura tabulky `enumtest` +-- + +DROP TABLE IF EXISTS `enumtest`; +CREATE TABLE IF NOT EXISTS `enumtest` ( + `id` int(11) NOT NULL auto_increment, + `test` enum('a','b','c') NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Vypisuji data pro tabulku `enumtest` +-- + + +-- -------------------------------------------------------- + +-- +-- Struktura tabulky `orders` +-- + +DROP TABLE IF EXISTS `orders`; +CREATE TABLE IF NOT EXISTS `orders` ( + `order_id` int(11) NOT NULL, + `customer_id` int(11) NOT NULL, + `product_id` int(11) NOT NULL, + `amount` float NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- +-- Vypisuji data pro tabulku `orders` +-- + +INSERT INTO `orders` (`order_id`, `customer_id`, `product_id`, `amount`) VALUES +(1, 2, 1, 7), +(2, 2, 3, 2), +(3, 1, 2, 3), +(4, 6, 3, 5); + +-- -------------------------------------------------------- + +-- +-- Struktura tabulky `products` +-- + +DROP TABLE IF EXISTS `products`; +CREATE TABLE IF NOT EXISTS `products` ( + `product_id` int(11) NOT NULL auto_increment, + `title` varchar(100) default NULL, + PRIMARY KEY (`product_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Vypisuji data pro tabulku `products` +-- + +INSERT INTO `products` (`product_id`, `title`) VALUES +(1, 'Chair'), +(2, 'Table'), +(3, 'Computer'); + +-- -------------------------------------------------------- + +-- +-- Struktura tabulky `settest` +-- + +DROP TABLE IF EXISTS `settest`; +CREATE TABLE IF NOT EXISTS `settest` ( + `id` int(11) NOT NULL auto_increment, + `test` set('a','b','c') NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Vypisuji data pro tabulku `settest` +-- + + +-- -------------------------------------------------------- + +-- +-- Struktura tabulky `where` +-- + +DROP TABLE IF EXISTS `where`; +CREATE TABLE IF NOT EXISTS `where` ( + `select` int(11) NOT NULL, + `dot.dot` int(11) NOT NULL, + `is` int(11) NOT NULL, + `quot'n' space` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- +-- Vypisuji data pro tabulku `where` +-- + +INSERT INTO `where` (`select`, `dot.dot`, `is`, `quot'n' space`) VALUES +(1, 2, 3, 4); + +SET FOREIGN_KEY_CHECKS=1; + +SET SQL_MODE="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"; + diff --git a/tests/data/sample.sdb b/tests/data/sample.sdb new file mode 100644 index 00000000..e2069b73 Binary files /dev/null and b/tests/data/sample.sdb differ diff --git a/tests/data/sample.sdb3 b/tests/data/sample.sdb3 new file mode 100644 index 00000000..28b79df2 Binary files /dev/null and b/tests/data/sample.sdb3 differ diff --git a/tests/initialize.php b/tests/initialize.php new file mode 100644 index 00000000..f75cd9ce --- /dev/null +++ b/tests/initialize.php @@ -0,0 +1,26 @@ +