Skip to content

Commit

Permalink
Skip test if connection fails (MySQL and PostgreSQL)
Browse files Browse the repository at this point in the history
  • Loading branch information
greut committed Apr 27, 2011
1 parent 37ae390 commit 3ca3ef4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
9 changes: 7 additions & 2 deletions test/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@

use ActiveRecord\Column;
use ActiveRecord\DateTime;
use ActiveRecord\DatabaseException;

class ColumnTest extends SnakeCase_PHPUnit_Framework_TestCase
{
public function set_up()
{
$this->column = new Column();
$this->conn = ActiveRecord\ConnectionManager::get_connection(ActiveRecord\Config::instance()->get_default_connection());
try {
$this->conn = ActiveRecord\ConnectionManager::get_connection(ActiveRecord\Config::instance()->get_default_connection());
} catch (DatabaseException $e) {
$this->mark_test_skipped('failed to connect using default connection. '.$e->getMessage());
}
}

public function assert_mapped_type($type, $raw_type)
Expand Down Expand Up @@ -114,4 +119,4 @@ public function test_empty_and_null_datetime_strings_should_return_null()
$this->assert_equals(null,$column->cast('',$this->conn));
}
}
?>
?>
7 changes: 6 additions & 1 deletion test/DateTimeTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
include 'helpers/config.php';
use ActiveRecord\DateTime as DateTime;
use ActiveRecord\DatabaseException;

class DateTimeTest extends SnakeCase_PHPUnit_Framework_TestCase
{
Expand All @@ -17,7 +18,11 @@ public function tear_down()

private function assert_dirtifies($method /*, method params, ...*/)
{
$model = new Author();
try {
$model = new Author();
} catch (DatabaseException $e) {
$this->mark_test_skipped('failed to connect. '.$e->getMessage());
}
$datetime = new DateTime();
$datetime->attribute_of($model,'some_date');

Expand Down
10 changes: 8 additions & 2 deletions test/ExpressionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require '../lib/Expressions.php';

use ActiveRecord\Expressions;
use ActiveRecord\ConnectionManager;
use ActiveRecord\DatabaseException;

class ExpressionsTest extends SnakeCase_PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -131,7 +133,11 @@ public function test_substitute_escapes_quotes()

public function test_substitute_escape_quotes_with_connections_escape_method()
{
$conn = ActiveRecord\ConnectionManager::get_connection();
try {
$conn = ConnectionManager::get_connection();
} catch (DatabaseException $e) {
$this->mark_test_skipped('failed to connect. '.$e->getMessage());
}
$a = new Expressions(null,'name=?',"Tito's Guild");
$a->set_connection($conn);
$escaped = $conn->escape("Tito's Guild");
Expand Down Expand Up @@ -193,4 +199,4 @@ public function test_hash_with_array()
$this->assert_equals('id=? AND name IN(?,?)',$a->to_s());
}
}
?>
?>
6 changes: 5 additions & 1 deletion test/helpers/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public function set_up($connection_name=null)
}

$this->connection_name = $connection_name;
$this->conn = ActiveRecord\ConnectionManager::get_connection($connection_name);
try {
$this->conn = ActiveRecord\ConnectionManager::get_connection($connection_name);
} catch (ActiveRecord\DatabaseException $e) {
$this->mark_test_skipped($connection_name . ' failed to connect. '.$e->getMessage());
}

$GLOBALS['ACTIVERECORD_LOG'] = false;

Expand Down

0 comments on commit 3ca3ef4

Please sign in to comment.