handle(RequestFactory::fromString($in)); if ($recording) { $parts[$i + 1] = $out; } else if ($out != $exp) { echo "$line1\n$exp\n$line2\n$out\n$line2\n"; $success = 0; } } if ($dirty) { file_put_contents($file, implode("===\n", $parts)); } return $success; } function loadFixture(String $dir, Config $config) { $driver = $config->getDriver(); $filename = "$dir/fixtures/blog_$driver.sql"; $file = file_get_contents($filename); $db = new GenericDB( $config->getDriver(), $config->getAddress(), $config->getPort(), $config->getDatabase(), $config->getUsername(), $config->getPassword() ); $pdo = $db->pdo(); $file = preg_replace('/--.*$/m', '', $file); if ($driver == 'sqlsrv') { $statements = preg_split('/\n\s*GO\s*\n/s', $file); } else { $statements = preg_split('/(?<=;)\n/s', $file); } foreach ($statements as $i => $statement) { $statement = trim($statement); if ($statement) { try { $pdo->exec($statement); } catch (\PDOException $e) { $error = print_r($pdo->errorInfo(), true); $statement = var_export($statement, true); echo "Loading '$filename' failed on statemement #$i:\n$statement\nwith error:\n$error\n"; exit(1); } } } } function run(array $drivers, String $dir, array $matches) { foreach ($drivers as $driver) { if (isset($matches[0])) { if (!preg_match('/' . $matches[0] . '/', $driver)) { continue; } } if (!extension_loaded("pdo_$driver")) { echo sprintf("%s: skipped, driver not loaded\n", $driver); continue; } $settings = []; include "$dir/config/base.php"; include sprintf("$dir/config/%s.php", $driver); $config = new Config($settings); loadFixture($dir, $config); $start = microtime(true); $stats = runDir($config, "$dir/functional", array_slice($matches, 1), ''); $end = microtime(true); $time = ($end - $start) * 1000; $total = $stats['total']; $failed = $stats['failed']; echo sprintf("%s: %d tests ran in %d ms, %d failed\n", $driver, $total, $time, $failed); } } run(['mysql', 'pgsql', 'sqlsrv'], __DIR__ . '/tests', array_slice($argv, 1));