diff --git a/.travis.yml b/.travis.yml index 98f6f0e..f1cff58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_install: - psql -c 'create database testing;' -U postgres - psql -U postgres -c "create extension postgis" # - mysql -e 'CREATE DATABASE testing;' - - cp tests/config.php.travis tests/config.php + - cp tests/Config.php.travis tests/Config.php script: - curl https://phar.phpunit.de/phpunit-4.8.phar -L -o phpunit.phar && chmod +x phpunit.phar diff --git a/tests/config.php.dist b/tests/Config.php.dist similarity index 98% rename from tests/config.php.dist rename to tests/Config.php.dist index e861c57..edd0064 100644 --- a/tests/config.php.dist +++ b/tests/Config.php.dist @@ -1,6 +1,6 @@ 50600) { + $capabilities |= self::GIS; + } + return $capabilities; } /** @@ -15,35 +73,17 @@ class MysqlTest extends PHP_CRUD_API_Test * * @return void */ - public function seedDatabase() + public function seedDatabase($db, $capabilities) { - if (static::$config['database']=='{{test_database}}') { - die("Configure database in 'config.php' before running tests.\n"); - } - - $fixture = __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'.sql'; - - $link = mysqli_connect( - static::$config['hostname'], - static::$config['username'], - static::$config['password'], - static::$config['database'] - ); - - if (mysqli_connect_errno()) { - die("Connect failed: ".mysqli_connect_error()."\n"); - } - - mysqli_set_charset($link,'utf8'); + $fixture = __DIR__.'/data/blog_mysql.sql'; $i=0; - if (mysqli_multi_query($link, file_get_contents($fixture))) { - do { $i++; mysqli_next_result($link); } while (mysqli_more_results($link)); - } - if (mysqli_errno($link)) { - die("Loading '$fixture' failed on statemement #$i with error:\n".mysqli_error($link)."\n"); + if (mysqli_multi_query($db, file_get_contents($fixture))) { + do { $i++; mysqli_next_result($db); } while (mysqli_more_results($db)); } - mysqli_close($link); + if (mysqli_errno($db)) { + die("Loading '$fixture' failed on statemement #$i with error:\n".mysqli_error($db)."\n"); + } } } diff --git a/tests/PostgresqlTest.php b/tests/PostgresqlTest.php index bf2ea00..4c6de91 100644 --- a/tests/PostgresqlTest.php +++ b/tests/PostgresqlTest.php @@ -1,13 +1,67 @@ $config['username'], + 'PWD' => $config['password'], + 'Database' => $config['database'], + 'CharacterSet' => 'UTF-8', + ); - if (static::$config['database']=='{{test_database}}') { - die("Configure database in 'config.php' before running tests.\n"); + $db = sqlsrv_connect($config['hostname'], $dbectionInfo); + + if (!$db) { + die("Connect failed: ".print_r( sqlsrv_errors(), true)); } - self::seedDatabase(); + return $db; } + /** + * Disconnects from the Database + * + * @return boolean Success + */ + public function disconnect($db) + { + return sqlsrv_close($db); + } + + /** + * Checks the version of the Database + * + * @return void + */ + public function checkVersion($db) + { + $major = 5; + $minor = 5; + $version = sqlsrv_server_info($db); + $v = explode('.',$version['SQLServerVersion']); + if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) { + die("Detected MySQL $v[0].$v[1], but only $major.$minor and up are supported\n"); + } + } + + /** + * Gets the capabilities of the Database + * + * @return int Capabilites + */ + public function getCapabilities($db) + { + return self::GIS; + } + + /** * Seeds the database for this connection * * @return void */ - public function seedDatabase() + public function seedDatabase($db, $capabilities) { - if (static::$config['database']=='{{test_database}}') { - die("Configure database in 'config.php' before running tests.\n"); - } - - $fixture = __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'.sql'; - - $connectionInfo = array( - 'UID' => static::$config['username'], - 'PWD' => static::$config['password'], - 'Database' => static::$config['database'], - 'CharacterSet' => 'UTF-8', - ); - - $conn = sqlsrv_connect(static::$config['hostname'], $connectionInfo); - - if (!$conn) { - die("Connect failed: ".print_r( sqlsrv_errors(), true)); - } + $fixture = __DIR__.'/data/blog_sqlserver.sql'; $queries = preg_split('/\n\s*GO\s*\n/', file_get_contents($fixture)); array_pop($queries); @@ -50,7 +82,5 @@ class SqlServerTest extends PHP_CRUD_API_Test die("Loading '$fixture' failed on statemement #$i with error:\n".print_r( sqlsrv_errors(), true)."\n"); } } - - sqlsrv_close($conn); } } diff --git a/tests/SqliteTest.php b/tests/SqliteTest.php index 76cdf69..fa36b78 100644 --- a/tests/SqliteTest.php +++ b/tests/SqliteTest.php @@ -1,13 +1,61 @@ close(); + } + + /** + * Checks the version of the Database + * + * @return void + */ + public function checkVersion($db) + { + $major = 3; + $minor = 0; + $version = SQLite3::version(); + $v = explode('.',$version['versionString']); + if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) { + die("Detected SQLite $v[0].$v[1], but only $major.$minor and up are supported\n"); + } + } + + /** + * Gets the capabilities of the Database + * + * @return int Capabilites + */ + public function getCapabilities($db) + { + $capabilities = 0; + + return $capabilities; } /** @@ -15,21 +63,9 @@ class SqliteTest extends PHP_CRUD_API_Test * * @return void */ - public function seedDatabase() + public function seedDatabase($db, $capabilities) { - if (static::$config['database']=='{{test_database}}') { - die("Configure database in 'config.php' before running tests.\n"); - } - - $database = static::$config['database']; - - $fixture = __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'.sql'; - - $db = new SQLite3($database); - - if (!$db) { - die("Could not open '$database' SQLite database: ".SQLite3::lastErrorMsg().' ('.SQLite3::lastErrorCode().")\n"); - } + $fixture = __DIR__.'/data/blog_sqlite.sql'; $queries = preg_split('/;\s*\n/', file_get_contents($fixture)); array_pop($queries); @@ -40,7 +76,5 @@ class SqliteTest extends PHP_CRUD_API_Test die("Loading '$fixture' failed on statemement #$i with error:\n".$db->lastErrorCode().': '.$db->lastErrorMsg()."\n"); } } - - $db->close(); } -} +} \ No newline at end of file diff --git a/tests/TestBase.php b/tests/TestBase.php new file mode 100644 index 0000000..49e57f0 --- /dev/null +++ b/tests/TestBase.php @@ -0,0 +1,46 @@ +