Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
106 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
<?php | ||
use ActiveRecord\Column; | ||
|
||
include 'helpers/config.php'; | ||
require_once dirname(__FILE__) . '/../lib/adapters/MysqlAdapter.php'; | ||
|
||
class MysqlAdapterTest extends AdapterTest | ||
{ | ||
public function set_up($connection_name=null) | ||
{ | ||
parent::set_up('mysql'); | ||
} | ||
|
||
public function test_enum() | ||
{ | ||
$author_columns = $this->conn->columns('authors'); | ||
$this->assert_equals('enum',$author_columns['some_enum']->raw_type); | ||
$this->assert_equals(Column::STRING,$author_columns['some_enum']->type); | ||
$this->assert_same(null,$author_columns['some_enum']->length); | ||
} | ||
|
||
public function test_set_charset() | ||
{ | ||
$connection_string = ActiveRecord\Config::instance()->get_connection($this->connection_name); | ||
$conn = ActiveRecord\Connection::instance($connection_string . '?charset=utf8'); | ||
$this->assert_equals('SET NAMES ?',$conn->last_query); | ||
} | ||
} | ||
?> | ||
<?php | ||
use ActiveRecord\Column; | ||
|
||
include 'helpers/config.php'; | ||
require_once dirname(__FILE__) . '/../lib/adapters/MysqlAdapter.php'; | ||
|
||
class MysqlAdapterTest extends AdapterTest | ||
{ | ||
public function set_up($connection_name=null) | ||
{ | ||
parent::set_up('mysql'); | ||
} | ||
|
||
public function test_enum() | ||
{ | ||
$author_columns = $this->conn->columns('authors'); | ||
$this->assert_equals('enum',$author_columns['some_enum']->raw_type); | ||
$this->assert_equals(Column::STRING,$author_columns['some_enum']->type); | ||
$this->assert_same(null,$author_columns['some_enum']->length); | ||
} | ||
|
||
public function test_set_charset() | ||
{ | ||
$connection_string = ActiveRecord\Config::instance()->get_connection($this->connection_name); | ||
$conn = ActiveRecord\Connection::instance($connection_string . '?charset=utf8'); | ||
$this->assert_equals('SET NAMES ?',$conn->last_query); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,77 @@ | ||
<?php | ||
require_once 'DatabaseLoader.php'; | ||
|
||
class DatabaseTest extends SnakeCase_PHPUnit_Framework_TestCase | ||
{ | ||
protected $conn; | ||
public static $log = false; | ||
|
||
public function set_up($connection_name=null) | ||
{ | ||
ActiveRecord\Table::clear_cache(); | ||
|
||
$config = ActiveRecord\Config::instance(); | ||
$this->original_default_connection = $config->get_default_connection(); | ||
|
||
if ($connection_name) | ||
$config->set_default_connection($connection_name); | ||
|
||
if ($connection_name == 'sqlite' || $config->get_default_connection() == 'sqlite') | ||
{ | ||
// need to create the db. the adapter specifically does not create it for us. | ||
$this->db = substr(ActiveRecord\Config::instance()->get_connection('sqlite'),9); | ||
new SQLite3($this->db); | ||
} | ||
|
||
$this->connection_name = $connection_name; | ||
$this->conn = ActiveRecord\ConnectionManager::get_connection($connection_name); | ||
|
||
$GLOBALS['ACTIVERECORD_LOG'] = false; | ||
|
||
$loader = new DatabaseLoader($this->conn); | ||
$loader->reset_table_data(); | ||
|
||
if (self::$log) | ||
$GLOBALS['ACTIVERECORD_LOG'] = true; | ||
} | ||
|
||
public function tear_down() | ||
{ | ||
if ($this->original_default_connection) | ||
ActiveRecord\Config::instance()->set_default_connection($this->original_default_connection); | ||
} | ||
|
||
public function assert_exception_message_contains($contains, $closure) | ||
{ | ||
$message = ""; | ||
|
||
try { | ||
$closure(); | ||
} catch (ActiveRecord\UndefinedPropertyException $e) { | ||
$message = $e->getMessage(); | ||
} | ||
|
||
$this->assert_true(strpos($message,$contains) !== false); | ||
} | ||
|
||
/** | ||
* Returns true if $regex matches $actual. | ||
* | ||
* Takes database specific quotes into account by removing them. So, this won't | ||
* work if you have actual quotes in your strings. | ||
*/ | ||
public function assert_sql_has($needle, $haystack) | ||
{ | ||
$needle = str_replace(array('"','`'),'',$needle); | ||
$haystack = str_replace(array('"','`'),'',$haystack); | ||
return $this->assert_true(strpos($haystack,$needle) !== false); | ||
} | ||
|
||
public function assert_sql_doesnt_has($needle, $haystack) | ||
{ | ||
$needle = str_replace(array('"','`'),'',$needle); | ||
$haystack = str_replace(array('"','`'),'',$haystack); | ||
return $this->assert_false(strpos($haystack,$needle) !== false); | ||
} | ||
} | ||
?> | ||
<?php | ||
require_once 'DatabaseLoader.php'; | ||
|
||
class DatabaseTest extends SnakeCase_PHPUnit_Framework_TestCase | ||
{ | ||
protected $conn; | ||
public static $log = false; | ||
|
||
public function set_up($connection_name=null) | ||
{ | ||
ActiveRecord\Table::clear_cache(); | ||
|
||
$config = ActiveRecord\Config::instance(); | ||
$this->original_default_connection = $config->get_default_connection(); | ||
|
||
if ($connection_name) | ||
$config->set_default_connection($connection_name); | ||
|
||
if ($connection_name == 'sqlite' || $config->get_default_connection() == 'sqlite') | ||
{ | ||
// need to create the db. the adapter specifically does not create it for us. | ||
$this->db = substr(ActiveRecord\Config::instance()->get_connection('sqlite'),9); | ||
new SQLite3($this->db); | ||
} | ||
|
||
$this->connection_name = $connection_name; | ||
$this->conn = ActiveRecord\ConnectionManager::get_connection($connection_name); | ||
|
||
$GLOBALS['ACTIVERECORD_LOG'] = false; | ||
|
||
$loader = new DatabaseLoader($this->conn); | ||
$loader->reset_table_data(); | ||
|
||
if (self::$log) | ||
$GLOBALS['ACTIVERECORD_LOG'] = true; | ||
} | ||
|
||
public function tear_down() | ||
{ | ||
if ($this->original_default_connection) | ||
ActiveRecord\Config::instance()->set_default_connection($this->original_default_connection); | ||
} | ||
|
||
public function assert_exception_message_contains($contains, $closure) | ||
{ | ||
$message = ""; | ||
|
||
try { | ||
$closure(); | ||
} catch (ActiveRecord\UndefinedPropertyException $e) { | ||
$message = $e->getMessage(); | ||
} | ||
|
||
$this->assert_true(strpos($message,$contains) !== false); | ||
} | ||
|
||
/** | ||
* Returns true if $regex matches $actual. | ||
* | ||
* Takes database specific quotes into account by removing them. So, this won't | ||
* work if you have actual quotes in your strings. | ||
*/ | ||
public function assert_sql_has($needle, $haystack) | ||
{ | ||
$needle = str_replace(array('"','`'),'',$needle); | ||
$haystack = str_replace(array('"','`'),'',$haystack); | ||
return $this->assert_true(strpos($haystack,$needle) !== false); | ||
} | ||
|
||
public function assert_sql_doesnt_has($needle, $haystack) | ||
{ | ||
$needle = str_replace(array('"','`'),'',$needle); | ||
$haystack = str_replace(array('"','`'),'',$haystack); | ||
return $this->assert_false(strpos($haystack,$needle) !== false); | ||
} | ||
} | ||
?> |