Transparent extension for Kohana_Unittest_Database_TestCase
Provides some unittest helpers and allows a kohana database connection to be used to connect to the database[!!] This class, or a class parent, could not be found or loaded. This could be caused by a missing module or other dependancy. The documentation for class may not be complete!
Class declared in MODPATH/unittest/classes/Unittest/Database/TestCase.php on line 14.
string
$_database_connectionlink to thisThe kohana database connection that PHPUnit should use for this test
string(7) "default"
Kohana_Unittest_Helpers
$_helperslink to thisA set of unittest helpers that are shared between normal / database testcases
NULL
boolean
$backupGlobalslink to thisMake sure PHPUnit backs up globals
bool FALSE
array
$environmentDefaultlink to thisA default set of environment to be applied before each test
array(0)
Removes all kohana related cache files in the cache directory
public
function
cleanCacheDir()
{
return
Kohana_Unittest_Helpers::clean_cache_dir();
}
Helper function that replaces all occurences of '/' with the OS-specific directory separator
string
$path
required - The path to act on string
public
function
dirSeparator(
$path
)
{
return
Kohana_Unittest_Helpers::dir_separator(
$path
);
}
Creates a connection to the unittesting database
PDO
public
function
getConnection()
{
// Get the unittesting db connection
$config
= Kohana::
$config
->load(
'database.'
.
$this
->_database_connection);
if
(
strtolower
(
$config
[
'type'
]) !==
'pdo'
) {
$config
[
'connection'
][
'dsn'
] =
strtolower
(
$config
[
'type'
]) .
':'
.
'host='
.
$config
[
'connection'
][
'hostname'
] .
';'
.
'dbname='
.
$config
[
'connection'
][
'database'
];
}
$pdo
=
new
PDO(
$config
[
'connection'
][
'dsn'
],
$config
[
'connection'
][
'username'
],
$config
[
'connection'
][
'password'
]
);
return
$this
->createDefaultDBConnection(
$pdo
,
$config
[
'connection'
][
'database'
]);
}
Gets a connection to the unittest database
Kohana_Database
- The database connection
public
function
getKohanaConnection()
{
return
Database::instance(Kohana::
$config
->load(
'unittest'
)->db_connection);
}
Check for internet connectivity
boolean
- Whether an internet connection is available
public
function
hasInternet()
{
return
Kohana_Unittest_Helpers::has_internet();
}
Allows easy setting & backing up of enviroment config
Option types are checked in the following order:
array
$environment
required - List of environment to set
public
function
setEnvironment(
array
$environment
)
{
return
$this
->_helpers->set_environment(
$environment
);
}
Creates a predefined environment using the default environment
Extending classes that have their own setUp() should call parent::setUp()
public
function
setUp()
{
$this
->_helpers =
new
Kohana_Unittest_Helpers;
$this
->setEnvironment(
$this
->environmentDefault);
return
parent::setUp();
}
Restores the original environment overriden with setEnvironment()
Extending classes that have their own tearDown() should call parent::tearDown()
public
function
tearDown()
{
$this
->_helpers->restore_environment();
return
parent::tearDown();
}
Creates classes when they are otherwise not found.
Kodoc::create_class(
'ThisClassDoesNotExist'
);
All classes created will extend Kodoc_Missing.
string
$class
required - Class name boolean
public
static
function
create_class(
$class
)
{
if
(!
class_exists
(
$class
)) {
// Create a new missing class
eval
(
"class {$class} extends Kodoc_Missing {}"
);
}
return
true;
}