Modules

abstract Kohana_Unittest_Database_TestCase
extends PHPUnit_Extensions_Database_TestCase
extends Kodoc_Missing
extends Kohana_Kodoc_Missing

This class is a transparent base class for Unittest_Database_TestCase and should not be accessed directly.

TestCase for testing a 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!

package
Kohana/UnitTest
author
Kohana Team
BRMatt [email protected]>
copyright
© 2008-2009 Kohana Team
license
http://kohanaphp.com/license

Class declared in MODPATH/unittest/classes/Kohana/Unittest/Database/TestCase.php on line 11.

Properties

protected static boolean $_assert_type_compatability

Whether we should enable work arounds to make the tests compatible with phpunit 3.4

NULL

protected string $_database_connection

The kohana database connection that PHPUnit should use for this test

Default value:
string(7) "default"

protected Kohana_Unittest_Helpers $_helpers

A set of unittest helpers that are shared between normal / database testcases

Default value:
NULL

protected boolean $backupGlobals

Make sure PHPUnit backs up globals

Default value:
bool FALSE

protected array $environmentDefault

A default set of environment to be applied before each test

Default value:
array(0) 

Methods

public static assertAttributeInstanceOf( string $expected , string $attributeName , mixed $classOrObject [, string $message = string(0) "" ] ) (defined in Kohana_Unittest_Database_TestCase)

Asserts that an attribute is of a given type.

Parameters

  • string $expected required - $expected
  • string $attributeName required - $attributeName
  • mixed $classOrObject required - $classOrObject
  • string $message = string(0) "" - $message

Tags

  • Since - Method available since Release 3.5.0

Source Code

public static function assertAttributeInstanceOf($expected, $attributeName, $classOrObject, $message = '')
{
	if(self::$_assert_type_compatability)
	{
		return self::assertAttributeType($expected, $attributeName, $classOrObject, $message);
	}

	return parent::assertAttributeInstanceOf($expected, $attributeName, $classOrObject, $message);
}

public static assertAttributeInternalType( string $expected , string $attributeName , mixed $classOrObject [, string $message = string(0) "" ] ) (defined in Kohana_Unittest_Database_TestCase)

Asserts that an attribute is of a given type.

Parameters

  • string $expected required - $expected
  • string $attributeName required - $attributeName
  • mixed $classOrObject required - $classOrObject
  • string $message = string(0) "" - $message

Tags

  • Since - Method available since Release 3.5.0

Source Code

public static function assertAttributeInternalType($expected, $attributeName, $classOrObject, $message = '')
{
	if(self::$_assert_type_compatability)
	{
		return self::assertAttributeType($expected, $attributeName, $classOrObject, $message);
	}

	return self::assertAttributeInternalType($expected, $attributeName, $classOrObject, $message);
}

public static assertAttributeNotInstanceOf( string $expected , string $attributeName , mixed $classOrObject [, string $message = string(0) "" ] ) (defined in Kohana_Unittest_Database_TestCase)

Asserts that an attribute is of a given type.

Parameters

  • string $expected required - $expected
  • string $attributeName required - $attributeName
  • mixed $classOrObject required - $classOrObject
  • string $message = string(0) "" - $message

Tags

  • Since - Method available since Release 3.5.0

Source Code

public static function assertAttributeNotInstanceOf($expected, $attributeName, $classOrObject, $message = '')
{
	if(self::$_assert_type_compatability)
	{
		return self::assertAttributeNotType($expected, $attributeName, $classOrObject, $message);
	}

	return self::assertAttributeNotInstanceOf($expected, $attributeName, $classOrObject, $message);
}

public static assertAttributeNotInternalType( string $expected , string $attributeName , mixed $classOrObject [, string $message = string(0) "" ] ) (defined in Kohana_Unittest_Database_TestCase)

Asserts that an attribute is of a given type.

Parameters

  • string $expected required - $expected
  • string $attributeName required - $attributeName
  • mixed $classOrObject required - $classOrObject
  • string $message = string(0) "" - $message

Tags

  • Since - Method available since Release 3.5.0

Source Code

public static function assertAttributeNotInternalType($expected, $attributeName, $classOrObject, $message = '')
{
	if(self::$_assert_type_compatability)
	{
		return self::assertAttributeNotType($expected, $attributeName, $classOrObject, $message);
	}

	return self::assertAttributeNotInternalType($expected, $attributeName, $classOrObject, $message);
}

public static assertInstanceOf( string $expected , mixed $actual [, string $message = string(0) "" ] ) (defined in Kohana_Unittest_Database_TestCase)

Asserts that a variable is of a given type.

Parameters

  • string $expected required - $expected
  • mixed $actual required - $actual
  • string $message = string(0) "" - $message

Tags

  • Since - Method available since Release 3.5.0

Source Code

public static function assertInstanceOf($expected, $actual, $message = '')
{
	if(self::$_assert_type_compatability)
	{
		return self::assertType($expected, $actual, $message);
	}

	return parent::assertInstanceOf($expected, $actual, $message);
}

public static assertInternalType( string $expected , mixed $actual [, string $message = string(0) "" ] ) (defined in Kohana_Unittest_Database_TestCase)

Asserts that a variable is of a given type.

Parameters

  • string $expected required - $expected
  • mixed $actual required - $actual
  • string $message = string(0) "" - $message

Tags

  • Since - Method available since Release 3.5.0

Source Code

public static function assertInternalType($expected, $actual, $message = '')
{
	if(self::$_assert_type_compatability)
	{
		return self::assertType($expected, $actual, $message);
	}
	
	return parent::assertInternalType($expected, $actual, $message);
}

public static assertNotInstanceOf( string $expected , mixed $actual [, string $message = string(0) "" ] ) (defined in Kohana_Unittest_Database_TestCase)

Asserts that a variable is not of a given type.

Parameters

  • string $expected required - $expected
  • mixed $actual required - $actual
  • string $message = string(0) "" - $message

Tags

  • Since - Method available since Release 3.5.0

Source Code

public static function assertNotInstanceOf($expected, $actual, $message = '')
{
	if(self::$_assert_type_compatability)
	{
		return self::assertNotType($expected, $actual, $message);
	}

	return self::assertNotInstanceOf($expected, $actual, $message);
}

public static assertNotInternalType( string $expected , mixed $actual [, string $message = string(0) "" ] ) (defined in Kohana_Unittest_Database_TestCase)

Asserts that a variable is not of a given type.

Parameters

  • string $expected required - $expected
  • mixed $actual required - $actual
  • string $message = string(0) "" - $message

Tags

  • Since - Method available since Release 3.5.0

Source Code

public static function assertNotInternalType($expected, $actual, $message = '')
{
	if(self::$_assert_type_compatability)
	{
		return self::assertNotType($expected, $actual, $message);
	}

	return self::assertNotInternalType($expected, $actual, $message);
}

public cleanCacheDir( ) (defined in Kohana_Unittest_Database_TestCase)

Removes all kohana related cache files in the cache directory

Source Code

public function cleanCacheDir()
{
	return Kohana_Unittest_Helpers::clean_cache_dir();
}

public dirSeparator( string $path ) (defined in Kohana_Unittest_Database_TestCase)

Helper function that replaces all occurences of '/' with the OS-specific directory separator

Parameters

  • string $path required - The path to act on

Return Values

  • string

Source Code

public function dirSeparator($path)
{
	return Kohana_Unittest_Helpers::dir_separator($path);
}

public getConnection( ) (defined in Kohana_Unittest_Database_TestCase)

Creates a connection to the unittesting database

Return Values

  • PDO

Source Code

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']);
}

public getKohanaConnection( ) (defined in Kohana_Unittest_Database_TestCase)

Gets a connection to the unittest database

Return Values

  • Kohana_Database - The database connection

Source Code

public function getKohanaConnection()
{
    return Database::instance(Kohana::$config->load('unittest')->db_connection);
}

public hasInternet( ) (defined in Kohana_Unittest_Database_TestCase)

Check for internet connectivity

Return Values

  • boolean - Whether an internet connection is available

Source Code

public function hasInternet()
{
	return Kohana_Unittest_Helpers::has_internet();
}

public setEnvironment( array $environment ) (defined in Kohana_Unittest_Database_TestCase)

Allows easy setting & backing up of enviroment config

Option types are checked in the following order:

  • Server Var
  • Static Variable
  • Config option

Parameters

  • array $environment required - List of environment to set

Source Code

public function setEnvironment(array $environment)
{
	return $this->_helpers->set_environment($environment);
}

public setUp( ) (defined in Kohana_Unittest_Database_TestCase)

Creates a predefined environment using the default environment

Extending classes that have their own setUp() should call parent::setUp()

Source Code

public function setUp()
{
	if(self::$_assert_type_compatability === NULL)
	{
		if( ! class_exists('PHPUnit_Runner_Version'))
		{
			require_once 'PHPUnit/Runner/Version.php';
		}

		self::$_assert_type_compatability = version_compare(PHPUnit_Runner_Version::id(), '3.5.0', '<=');
	}
	
	$this->_helpers = new Kohana_Unittest_Helpers;

	$this->setEnvironment($this->environmentDefault);

	return parent::setUp();
}

public tearDown( ) (defined in Kohana_Unittest_Database_TestCase)

Restores the original environment overriden with setEnvironment()

Extending classes that have their own tearDown() should call parent::tearDown()

Source Code

public function tearDown()
{
	$this->_helpers->restore_environment();

	return parent::tearDown();
}

public static create_class( string $class ) (defined in Kohana_Kodoc_Missing)

Creates classes when they are otherwise not found.

Kodoc::create_class('ThisClassDoesNotExist');

All classes created will extend Kodoc_Missing.

Parameters

  • string $class required - Class name

Tags

  • Since - 3.0.7

Return Values

  • boolean

Source Code

public static function create_class($class)
{
	if ( ! class_exists($class))
	{
		// Create a new missing class
		eval("class {$class} extends Kodoc_Missing {}");
	}

	return TRUE;
}