Modules

abstract Unittest_TestCase
extends Kohana_Unittest_TestCase
extends PHPUnit\Framework\TestCase
extends Kodoc_Missing
extends Kohana_Kodoc_Missing

A version of the stock PHPUnit testcase that includes some extra helpers and default settings[!!] 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/TestCase.php on line 3.

Properties

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 assertNotTag( array $matcher , string $actual [, string $message = string(0) "" , bool $isHtml = bool TRUE ] ) (defined in Kohana_Unittest_TestCase)

This assertion is the exact opposite of assertTag

Rather than asserting that $matcher results in a match, it asserts that $matcher does not match

NOTE: Overriding this method to remove the deprecation error when tested with PHPUnit 4.2.0+

TODO: this should be removed when phpunit-dom-assertions gets released https://github.com/phpunit/phpunit-dom-assertions

Parameters

  • array $matcher required - $matcher
  • string $actual required - $actual
  • string $message = string(0) "" - $message
  • bool $isHtml = bool TRUE - $isHtml

Tags

Source Code

public static function assertNotTag($matcher, $actual, $message = '', $isHtml = true)
{

	//trigger_error(__METHOD__ . ' is deprecated', E_USER_DEPRECATED);
       
	$matched = static::tag_match($matcher, $actual, $message, $isHtml);
	static::assertTrue($matched, $message);
}

public static assertTag( array $matcher , string $actual [, string $message = string(0) "" , bool $isHtml = bool TRUE ] ) (defined in Kohana_Unittest_TestCase)

Evaluate an HTML or XML string and assert its structure and/or contents.

NOTE: Overriding this method to remove the deprecation error when tested with PHPUnit 4.2.0+

TODO: this should be removed when phpunit-dom-assertions gets released https://github.com/phpunit/phpunit-dom-assertions

Parameters

  • array $matcher required - $matcher
  • string $actual required - $actual
  • string $message = string(0) "" - $message
  • bool $isHtml = bool TRUE - $isHtml

Tags

Source Code

public static function assertTag($matcher, $actual, $message = '', $isHtml = true)
{
	//trigger_error(__METHOD__ . ' is deprecated', E_USER_DEPRECATED);

	$matched = static::tag_match($matcher, $actual, $message, $isHtml);
	static::assertTrue($matched, $message);
}

public cleanCacheDir( ) (defined in Kohana_Unittest_TestCase)

Removes all kohana related cache files in the cache directory

Source Code

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

public dirSeparator( string $path ) (defined in Kohana_Unittest_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 Unittest_Helpers::dir_separator($path);
}

public hasInternet( ) (defined in Kohana_Unittest_TestCase)

Check for internet connectivity

Return Values

  • boolean - Whether an internet connection is available

Source Code

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

public setEnvironment( array $environment ) (defined in Kohana_Unittest_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

Tags

  • CodeCoverageIgnore -

Source Code

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

public setUp( ) (defined in Kohana_Unittest_TestCase)

Creates a predefined environment using the default environment

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

Tags

  • CodeCoverageIgnore -

Source Code

public function setUp()
{
	$this->_helpers = new Unittest_Helpers;

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

public tearDown( ) (defined in Kohana_Unittest_TestCase)

Restores the original environment overriden with setEnvironment()

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

Tags

  • CodeCoverageIgnore -

Source Code

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

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
		if (FALSE === strpos($class, '\\'))
		{
			eval("class {$class} extends Kodoc_Missing {}");
		}
		else
		{
			$namespace = explode('\\', $class);
			$class = array_pop($namespace);
			eval("namespace ".implode('\\', $namespace)."; class {$class} extends \Kodoc_Missing {}");
		}
	}

	return TRUE;
}

protected static tag_match( array $matcher , string $actual [, string $message = string(0) "" , bool $isHtml = bool TRUE ] ) (defined in Kohana_Unittest_TestCase)

Helper function to match HTML string tags against certain criteria

TODO: this should be removed when phpunit-dom-assertions gets released https://github.com/phpunit/phpunit-dom-assertions

Parameters

  • array $matcher required - $matcher
  • string $actual required - $actual
  • string $message = string(0) "" - $message
  • bool $isHtml = bool TRUE - $isHtml

Return Values

  • bool - TRUE if there is a match FALSE otherwise

Source Code

protected static function tag_match($matcher, $actual, $message = '', $isHtml = true)
{
	$dom = PHPUnit\Util\Xml::load($actual, $isHtml);
       $tags = $dom->getElementsByTagName($matcher['tag']);
       
	return count($tags) > 0 && $tags[0] instanceof DOMNode;
}