PHPUnit database configuration and Environment test

This commit is contained in:
Zarubin Stas 2011-07-11 03:25:17 +03:00
parent cf733f1f55
commit 09660a6624
2 changed files with 23 additions and 37 deletions

View File

@ -13,15 +13,22 @@
timeout="30000"/>
</selenium>
<php>
<const name="TESTSUITE_SERVER" value="localhost"/>
<const name="TESTSUITE_DATABASE" value="test_database"/>
<const name="TESTSUITE_USER" value="test_user"/>
<const name="TESTSUITE_PASSWORD" value="test_password"/>
</php>
<testsuites>
<testsuite name="Unit">
<file>test/Environment_test.php</file>
<directory suffix="_test.php">test/libraries/core</directory>
<directory suffix="_test.php">test/libraries/common</directory>
<directory suffix="_test.php">test/libraries</directory>
<file>test/Environment_test.php</file>
</testsuite>
<testsuite name="Selenium">
<directory suffix="Test.php">test/selenium</directory>
<!--<directory suffix="Test.php">test/selenium</directory>-->
</testsuite>
</testsuites>

View File

@ -24,43 +24,22 @@ class Environment_test extends PHPUnit_Framework_TestCase
public function testMySQL()
{
global $cfg;
try{
$pdo = new PDO("mysql:host=".TESTSUITE_SERVER.";dbname=".TESTSUITE_DATABASE, TESTSUITE_USER, TESTSUITE_PASSWORD);
$this->assertNull($pdo->errorCode(),"Error when trying to connect to database");
foreach($cfg['Servers'] as $i=>$server){
// Check config for the server
if (!isset($server["host"])){
$this->fail("Couldn't determine the host. Please check configuration for the server id: $i");
}
if (!isset($server["pmadb"])){
$this->markTestSkipped(); // If DB is not specified there is no reason to check connect.
}
elseif(!isset($server["controluser"])){
$this->fail("Please specify user for server $i and database ".$server["pmadb"]);
}
try{
if (!isset($server["controlpass"])){
$pdo = new PDO("mysql:host=".$server["host"].";dbname=".$server["pmadb"], $server['controluser']);
}
else{
$pdo = new PDO("mysql:host=".$server["host"].";dbname=".$server["pmadb"], $server['controluser'], $server['controlpass']);
}
$this->assertNull($pdo->errorCode());
//$pdo->beginTransaction();
$test = $pdo->exec("SHOW TABLES;");
//$pdo->commit();
$this->assertEquals(0, $pdo->errorCode());
}
catch (Exception $e){
$this->fail("Error: ".$e->getMessage());
}
// Check id MySQL server is 5 version
preg_match("/^(\d+)?\.(\d+)?\.(\*|\d+)/", $pdo->getAttribute(constant("PDO::ATTR_SERVER_VERSION")), $version_parts);
$this->assertEquals(5, $version_parts[1]);
//$pdo->beginTransaction();
$test = $pdo->exec("SHOW TABLES;");
//$pdo->commit();
$this->assertEquals(0, $pdo->errorCode(), 'Error trying to show tables for database');
}
catch (Exception $e){
$this->fail("Error: ".$e->getMessage());
}
// Check id MySQL server is 5 version
preg_match("/^(\d+)?\.(\d+)?\.(\*|\d+)/", $pdo->getAttribute(constant("PDO::ATTR_SERVER_VERSION")), $version_parts);
$this->assertEquals(5, $version_parts[1]);
}
//TODO: Think about this test