Upgrade to KH 3.1.3.1
This commit is contained in:
@@ -2,15 +2,15 @@
|
||||
/**
|
||||
* PHPUnit Kohana web based test runner
|
||||
*
|
||||
* @package Kohana/Unittest
|
||||
* @package Kohana/UnitTest
|
||||
* @author Kohana Team
|
||||
* @author BRMatt <matthew@sigswitch.com>
|
||||
* @author Paul Banks
|
||||
* @author Paul Banks
|
||||
* @copyright (c) 2008-2009 Kohana Team
|
||||
* @license http://kohanaphp.com/license
|
||||
*/
|
||||
|
||||
Class Controller_UnitTest extends Controller_Template
|
||||
class Controller_UnitTest extends Controller_Template
|
||||
{
|
||||
/**
|
||||
* Whether the archive module is available
|
||||
@@ -20,7 +20,7 @@ Class Controller_UnitTest extends Controller_Template
|
||||
|
||||
/**
|
||||
* Unittest config
|
||||
* @var Kohana_Config
|
||||
* @var Config
|
||||
*/
|
||||
protected $config = NULL;
|
||||
|
||||
@@ -55,28 +55,28 @@ Class Controller_UnitTest extends Controller_Template
|
||||
{
|
||||
parent::before();
|
||||
|
||||
if ( ! Kohana_Tests::enabled())
|
||||
if ( ! Unittest_tests::enabled())
|
||||
{
|
||||
// Pretend this is a normal 404 error...
|
||||
$this->status = 404;
|
||||
|
||||
throw new Kohana_Request_Exception('Unable to find a route to match the URI: :uri',
|
||||
array(':uri' => $this->request->uri));
|
||||
array(':uri' => $this->request->uri()));
|
||||
}
|
||||
|
||||
// Prevent the whitelist from being autoloaded, but allow the blacklist
|
||||
// to be loaded
|
||||
Kohana_Tests::configure_environment(FALSE);
|
||||
Unittest_Tests::configure_environment(FALSE);
|
||||
|
||||
$this->config = Kohana::config('unittest');
|
||||
|
||||
// This just stops some very very long lines
|
||||
$route = Route::get('unittest');
|
||||
$this->report_uri = $route->uri(array('action' => 'report'));
|
||||
$this->run_uri = $route->uri(array('action' => 'run'));
|
||||
$this->run_uri = $route->uri(array('action' => 'run'));
|
||||
|
||||
// Switch used to disable cc settings
|
||||
$this->xdebug_loaded = extension_loaded('xdebug');
|
||||
$this->xdebug_loaded = extension_loaded('xdebug');
|
||||
$this->cc_archive_enabled = class_exists('Archive');
|
||||
|
||||
Kohana_View::set_global('xdebug_enabled', $this->xdebug_loaded);
|
||||
@@ -92,7 +92,7 @@ Class Controller_UnitTest extends Controller_Template
|
||||
->set('run_uri', $this->run_uri)
|
||||
->set('report_uri', $this->report_uri)
|
||||
->set('whitelistable_items', $this->get_whitelistable_items())
|
||||
->set('groups', $this->get_groups_list(Kohana_Tests::suite()));
|
||||
->set('groups', $this->get_groups_list(Unittest_tests::suite()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,16 +102,14 @@ Class Controller_UnitTest extends Controller_Template
|
||||
{
|
||||
// Fairly foolproof
|
||||
if ( ! $this->config->cc_report_path AND ! class_exists('Archive'))
|
||||
{
|
||||
throw new Kohana_Exception('Cannot generate report');
|
||||
}
|
||||
|
||||
// We don't want to use the HTML layout, we're sending the user 100111011100110010101100
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
$suite = Kohana_Tests::suite();
|
||||
$suite = Unittest_tests::suite();
|
||||
$temp_path = rtrim($this->config->temp_path, '/').'/';
|
||||
$group = (array) Arr::get($_GET, 'group', array());
|
||||
$group = (array) Arr::get($_GET, 'group', array());
|
||||
|
||||
// Stop unittest from interpretting "all groups" as "no groups"
|
||||
if (empty($group) OR empty($group[0]))
|
||||
@@ -150,21 +148,17 @@ Class Controller_UnitTest extends Controller_Template
|
||||
else
|
||||
{
|
||||
$folder = trim($this->config->cc_report_path, '/').'/';
|
||||
$path = DOCROOT.$folder;
|
||||
$path = DOCROOT.$folder;
|
||||
|
||||
if ( ! file_exists($path))
|
||||
{
|
||||
throw new Kohana_Exception('Report directory :dir does not exist', array(':dir' => $path));
|
||||
}
|
||||
|
||||
if ( ! is_writable($path))
|
||||
{
|
||||
throw new Kohana_Exception('Script doesn\'t have permission to write to report dir :dir ', array(':dir' => $path));
|
||||
}
|
||||
|
||||
$runner->generate_report($group, $path, FALSE);
|
||||
|
||||
$this->request->redirect(URL::base(FALSE, TRUE).$folder.'index.html');
|
||||
$this->request->redirect(URL::site($folder.'index.html', $this->request));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +170,7 @@ Class Controller_UnitTest extends Controller_Template
|
||||
$this->template->body = View::factory('unittest/results');
|
||||
|
||||
// Get the test suite and work out which groups we're testing
|
||||
$suite = Kohana_Tests::suite();
|
||||
$suite = Unittest_tests::suite();
|
||||
$group = (array) Arr::get($_GET, 'group', array());
|
||||
|
||||
|
||||
@@ -220,19 +214,20 @@ Class Controller_UnitTest extends Controller_Template
|
||||
// Show some results
|
||||
$this->template->body
|
||||
->set('results', $runner->results)
|
||||
->set('totals', $runner->totals)
|
||||
->set('time', $this->nice_time($runner->time))
|
||||
->set('totals', $runner->totals)
|
||||
->set('time', $this->nice_time($runner->time))
|
||||
|
||||
// Sets group to the currently selected group, or default all groups
|
||||
->set('group', Arr::get($this->get_groups_list($suite), reset($group), 'All groups'))
|
||||
->set('group', Arr::get($this->get_groups_list($suite), reset($group), 'All groups'))
|
||||
->set('groups', $this->get_groups_list($suite))
|
||||
|
||||
->set('report_uri', $this->report_uri.url::query())
|
||||
->set('run_uri', $this->request->uri())
|
||||
->set('report_uri', $this->report_uri.url::query())
|
||||
|
||||
// Whitelist related stuff
|
||||
->set('whitelistable_items', $this->get_whitelistable_items())
|
||||
->set('whitelisted_items', isset($whitelist) ? array_keys($whitelist) : array())
|
||||
->set('whitelist', ! empty($whitelist));
|
||||
->set('whitelisted_items', isset($whitelist) ? array_keys($whitelist) : array())
|
||||
->set('whitelist', ! empty($whitelist));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,9 +257,7 @@ Class Controller_UnitTest extends Controller_Template
|
||||
static $whitelist;
|
||||
|
||||
if (count($whitelist))
|
||||
{
|
||||
return $whitelist;
|
||||
}
|
||||
|
||||
$whitelist = array();
|
||||
|
||||
@@ -308,7 +301,7 @@ Class Controller_UnitTest extends Controller_Template
|
||||
|
||||
if (count($whitelist))
|
||||
{
|
||||
Kohana_Tests::whitelist($whitelist);
|
||||
Unittest_tests::whitelist($whitelist);
|
||||
}
|
||||
|
||||
return $whitelist;
|
||||
|
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
/**
|
||||
* TestCase for testing a database
|
||||
*
|
||||
* @package Kohana/UnitTest
|
||||
* @author Kohana Team
|
||||
* @author BRMatt <matthew@sigswitch.com>
|
||||
* @copyright (c) 2008-2009 Kohana Team
|
||||
* @license http://kohanaphp.com/license
|
||||
*/
|
||||
// @codingStandardsIgnoreFile
|
||||
abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Database_TestCase {
|
||||
|
||||
/**
|
||||
* Whether we should enable work arounds to make the tests compatible with phpunit 3.4
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $_assert_type_compatability = NULL;
|
||||
|
||||
/**
|
||||
* Make sure PHPUnit backs up globals
|
||||
* @var boolean
|
||||
*/
|
||||
protected $backupGlobals = TRUE;
|
||||
|
||||
/**
|
||||
* A set of unittest helpers that are shared between normal / database
|
||||
* testcases
|
||||
* @var Kohana_Unittest_Helpers
|
||||
*/
|
||||
protected $_helpers = NULL;
|
||||
|
||||
/**
|
||||
* A default set of environment to be applied before each test
|
||||
* @var array
|
||||
*/
|
||||
protected $environmentDefault = array();
|
||||
|
||||
/**
|
||||
* Creates a predefined environment using the default environment
|
||||
*
|
||||
* Extending classes that have their own setUp() should call
|
||||
* parent::setUp()
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 a connection to the unittesting database
|
||||
*
|
||||
* @return PDO
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
// Get the unittesting db connection
|
||||
$config = Kohana::config('database')
|
||||
->{Kohana::config('unittest')->db_connection};
|
||||
|
||||
if($config['type'] !== 'pdo')
|
||||
{
|
||||
$config['connection']['dsn'] = $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
|
||||
*
|
||||
* @return Kohana_Database The database connection
|
||||
*/
|
||||
public function getKohanaConnection()
|
||||
{
|
||||
return Database::instance(Kohana::config('unittest')->db_connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param string $path The path to act on
|
||||
* @return string
|
||||
*/
|
||||
public function dirSeparator($path)
|
||||
{
|
||||
return Kohana_Unittest_Helpers::dir_separator($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows easy setting & backing up of enviroment config
|
||||
*
|
||||
* Option types are checked in the following order:
|
||||
*
|
||||
* * Server Var
|
||||
* * Static Variable
|
||||
* * Config option
|
||||
*
|
||||
* @param array $environment List of environment to set
|
||||
*/
|
||||
public function setEnvironment(array $environment)
|
||||
{
|
||||
return $this->_helpers->set_environment($environment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for internet connectivity
|
||||
*
|
||||
* @return boolean Whether an internet connection is available
|
||||
*/
|
||||
public function hasInternet()
|
||||
{
|
||||
return Kohana_Unittest_Helpers::has_internet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
public static function assertInstanceOf($expected, $actual, $message = '')
|
||||
{
|
||||
if (self::$_assert_type_compatability)
|
||||
return self::assertType($expected, $actual, $message);
|
||||
|
||||
return parent::assertInstanceOf($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an attribute is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $attributeName
|
||||
* @param mixed $classOrObject
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is not of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
public static function assertNotInstanceOf($expected, $actual, $message = '')
|
||||
{
|
||||
if (self::$_assert_type_compatability)
|
||||
return self::assertNotType($expected, $actual, $message);
|
||||
|
||||
return self::assertNotInstanceOf($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an attribute is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $attributeName
|
||||
* @param mixed $classOrObject
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
public static function assertInternalType($expected, $actual, $message = '')
|
||||
{
|
||||
if (self::$_assert_type_compatability)
|
||||
return self::assertType($expected, $actual, $message);
|
||||
|
||||
return parent::assertInternalType($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an attribute is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $attributeName
|
||||
* @param mixed $classOrObject
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is not of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
public static function assertNotInternalType($expected, $actual, $message = '')
|
||||
{
|
||||
if (self::$_assert_type_compatability)
|
||||
return self::assertNotType($expected, $actual, $message);
|
||||
|
||||
return self::assertNotInternalType($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an attribute is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $attributeName
|
||||
* @param mixed $classOrObject
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
@@ -1,16 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Unit testing helpers
|
||||
*
|
||||
* @package Kohana/Unittest
|
||||
* @author Kohana Team
|
||||
* @author BRMatt <matthew@sigswitch.com>
|
||||
* @author Paul Banks
|
||||
* @copyright (c) 2008-2009 Kohana Team
|
||||
* @license http://kohanaphp.com/license
|
||||
*/
|
||||
class Kohana_Unittest_Helpers
|
||||
{
|
||||
class Kohana_Unittest_Helpers {
|
||||
/**
|
||||
* Static variable used to work out whether we have an internet
|
||||
* connection
|
||||
@@ -57,7 +50,7 @@ class Kohana_Unittest_Helpers
|
||||
{
|
||||
$cache_dir = opendir(Kohana::$cache_dir);
|
||||
|
||||
while($dir = readdir($cache_dir))
|
||||
while ($dir = readdir($cache_dir))
|
||||
{
|
||||
// Cache files are split into directories based on first two characters of hash
|
||||
if ($dir[0] !== '.' AND strlen($dir) === 2)
|
||||
@@ -66,7 +59,7 @@ class Kohana_Unittest_Helpers
|
||||
|
||||
$cache = opendir($dir);
|
||||
|
||||
while($file = readdir($cache))
|
||||
while ($file = readdir($cache))
|
||||
{
|
||||
if ($file[0] !== '.')
|
||||
{
|
||||
@@ -116,7 +109,7 @@ class Kohana_Unittest_Helpers
|
||||
// For some reason we need to do this in order to change the superglobals
|
||||
global $$option;
|
||||
|
||||
if($backup_needed)
|
||||
if ($backup_needed)
|
||||
{
|
||||
$this->_environment_backup[$option] = $$option;
|
||||
}
|
||||
@@ -139,9 +132,9 @@ class Kohana_Unittest_Helpers
|
||||
$class->setStaticPropertyValue($var, $value);
|
||||
}
|
||||
// If this is an environment variable
|
||||
elseif (preg_match('/^[A-Z_-]+$/', $option) OR isset($_SERVER[$option]))
|
||||
elseif (preg_match('/^[A-Z_-]+$/D', $option) OR isset($_SERVER[$option]))
|
||||
{
|
||||
if($backup_needed)
|
||||
if ($backup_needed)
|
||||
{
|
||||
$this->_environment_backup[$option] = isset($_SERVER[$option]) ? $_SERVER[$option] : '';
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPUnit test runner for kohana
|
||||
*
|
||||
* @package Kohana/Unittest
|
||||
* @package Kohana/UnitTest
|
||||
* @author Kohana Team
|
||||
* @author BRMatt <matthew@sigswitch.com>
|
||||
* @author Paul Banks
|
||||
* @copyright (c) 2008-2009 Kohana Team
|
||||
* @license http://kohanaphp.com/license
|
||||
*/
|
||||
Class Kohana_Unittest_Runner implements PHPUnit_Framework_TestListener
|
||||
{
|
||||
class Kohana_Unittest_Runner implements PHPUnit_Framework_TestListener {
|
||||
/**
|
||||
* Results
|
||||
* @var array
|
||||
@@ -145,7 +145,7 @@ Class Kohana_Unittest_Runner implements PHPUnit_Framework_TestListener
|
||||
$executed += $stat['locExecuted'];
|
||||
}
|
||||
|
||||
return $executable > 0 ? ($executed / $executable) * 100 : 100;
|
||||
return ($executable > 0) ? ($executed * 100 / $executable) : 100;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
@@ -160,9 +160,7 @@ Class Kohana_Unittest_Runner implements PHPUnit_Framework_TestListener
|
||||
public function generate_report(array $groups, $temp_path, $create_sub_dir = TRUE)
|
||||
{
|
||||
if ( ! is_writable($temp_path))
|
||||
{
|
||||
throw new Kohana_Exception('Temp path :path does not exist or is not writable by the webserver', array(':path' => $temp_path));
|
||||
}
|
||||
|
||||
$folder_path = $temp_path;
|
||||
|
||||
@@ -174,11 +172,11 @@ Class Kohana_Unittest_Runner implements PHPUnit_Framework_TestListener
|
||||
do
|
||||
{
|
||||
$folder_name = date('Y-m-d_H:i:s')
|
||||
.( ! empty($groups) ? '['.implode(',', $groups).']' : '')
|
||||
.($count > 0 ? '('.$count.')' : '');
|
||||
.(empty($groups) ? '' : ('['.implode(',', $groups).']'))
|
||||
.(($count > 0) ? ('('.$count.')') : '');
|
||||
++$count;
|
||||
}
|
||||
while(is_dir($folder_path.$folder_name));
|
||||
while (is_dir($folder_path.$folder_name));
|
||||
|
||||
$folder_path .= $folder_name;
|
||||
|
||||
@@ -209,11 +207,9 @@ Class Kohana_Unittest_Runner implements PHPUnit_Framework_TestListener
|
||||
public function run(array $groups = array(), $collect_cc = FALSE)
|
||||
{
|
||||
if ($collect_cc AND ! extension_loaded('xdebug'))
|
||||
{
|
||||
throw new Kohana_Exception('Code coverage cannot be collected because the xdebug extension is not loaded');
|
||||
}
|
||||
|
||||
$this->result->collectCodeCoverageInformation((bool) $collect_cc);
|
||||
$this->result->collectCodeCoverageInformation( (bool) $collect_cc);
|
||||
|
||||
// Run the tests.
|
||||
$this->suite->run($this->result, FALSE, $groups);
|
||||
@@ -221,43 +217,54 @@ Class Kohana_Unittest_Runner implements PHPUnit_Framework_TestListener
|
||||
return $this;
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
// @codingStandardsIgnoreEnd
|
||||
{
|
||||
$this->totals['errors']++;
|
||||
$this->current['result'] = 'errors';
|
||||
$this->current['message'] = $test->getStatusMessage();
|
||||
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
// @codingStandardsIgnoreEnd
|
||||
{
|
||||
$this->totals['failures']++;
|
||||
$this->current['result'] = 'failures';
|
||||
$this->current['message'] = $test->getStatusMessage();
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
// @codingStandardsIgnoreEnd
|
||||
{
|
||||
$this->totals['incomplete']++;
|
||||
$this->current['result'] = 'incomplete';
|
||||
$this->current['message'] = $test->getStatusMessage();
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
// @codingStandardsIgnoreEnd
|
||||
{
|
||||
$this->totals['skipped']++;
|
||||
$this->current['result'] = 'skipped';
|
||||
$this->current['message'] = $test->getStatusMessage();
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
public function startTest(PHPUnit_Framework_Test $test)
|
||||
// @codingStandardsIgnoreEnd
|
||||
{
|
||||
$this->current['name'] = $test->getName(FALSE);
|
||||
$this->current['description'] = $test->toString();
|
||||
$this->current['result'] = 'passed';
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time)
|
||||
// @codingStandardsIgnoreEnd
|
||||
{
|
||||
// Add totals
|
||||
$this->totals['tests']++;
|
||||
@@ -280,11 +287,13 @@ Class Kohana_Unittest_Runner implements PHPUnit_Framework_TestListener
|
||||
$this->time += $time;
|
||||
}
|
||||
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
}
|
||||
// @codingStandardsIgnoreStart
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
// @codingStandardsIgnoreEnd
|
||||
{
|
||||
// Parse test descriptions to make them look nicer
|
||||
foreach ($this->results as $case => $testresults)
|
||||
|
@@ -1,16 +1,18 @@
|
||||
<?php
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* TestCase for unittesting
|
||||
*
|
||||
* @package Kohana/Unittest
|
||||
* @author Kohana Team
|
||||
* @author BRMatt <matthew@sigswitch.com>
|
||||
* @author Paul Banks
|
||||
* @copyright (c) 2008-2009 Kohana Team
|
||||
* @license http://kohanaphp.com/license
|
||||
* A version of the stock PHPUnit testcase that includes some extra helpers
|
||||
* and default settings
|
||||
*/
|
||||
Abstract Class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
// @codingStandardsIgnoreFile
|
||||
abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* Whether we should enable work arounds to make the tests compatible with phpunit 3.4
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $_assert_type_compatability = NULL;
|
||||
|
||||
/**
|
||||
* Make sure PHPUnit backs up globals
|
||||
* @var boolean
|
||||
@@ -38,7 +40,17 @@ Abstract Class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->_helpers = new Kohana_Unittest_Helpers;
|
||||
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 Unittest_Helpers;
|
||||
|
||||
$this->setEnvironment($this->environmentDefault);
|
||||
}
|
||||
@@ -59,7 +71,7 @@ Abstract Class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function cleanCacheDir()
|
||||
{
|
||||
return Kohana_Unittest_Helpers::clean_cache_dir();
|
||||
return Unittest_Helpers::clean_cache_dir();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +83,7 @@ Abstract Class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function dirSeparator($path)
|
||||
{
|
||||
return Kohana_Unittest_Helpers::dir_separator($path);
|
||||
return Unittest_Helpers::dir_separator($path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,6 +109,138 @@ Abstract Class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function hasInternet()
|
||||
{
|
||||
return Kohana_Unittest_Helpers::has_internet();
|
||||
return Unittest_Helpers::has_internet();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
public static function assertInstanceOf($expected, $actual, $message = '')
|
||||
{
|
||||
if (self::$_assert_type_compatability)
|
||||
return self::assertType($expected, $actual, $message);
|
||||
|
||||
return parent::assertInstanceOf($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an attribute is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $attributeName
|
||||
* @param mixed $classOrObject
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is not of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
public static function assertNotInstanceOf($expected, $actual, $message = '')
|
||||
{
|
||||
if (self::$_assert_type_compatability)
|
||||
return self::assertNotType($expected, $actual, $message);
|
||||
|
||||
return self::assertNotInstanceOf($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an attribute is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $attributeName
|
||||
* @param mixed $classOrObject
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
public static function assertInternalType($expected, $actual, $message = '')
|
||||
{
|
||||
if (self::$_assert_type_compatability)
|
||||
return self::assertType($expected, $actual, $message);
|
||||
|
||||
return parent::assertInternalType($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an attribute is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $attributeName
|
||||
* @param mixed $classOrObject
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a variable is not of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
public static function assertNotInternalType($expected, $actual, $message = '')
|
||||
{
|
||||
if (self::$_assert_type_compatability)
|
||||
return self::assertNotType($expected, $actual, $message);
|
||||
|
||||
return self::assertNotInternalType($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an attribute is of a given type.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $attributeName
|
||||
* @param mixed $classOrObject
|
||||
* @param string $message
|
||||
* @since Method available since Release 3.5.0
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,25 @@
|
||||
<?php
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* PHPUnit testsuite for kohana application
|
||||
*
|
||||
* @package Kohana/Unittest
|
||||
* @package Kohana/UnitTest
|
||||
* @author Kohana Team
|
||||
* @author BRMatt <matthew@sigswitch.com>
|
||||
* @author Paul Banks
|
||||
* @copyright (c) 2008-2009 Kohana Team
|
||||
* @license http://kohanaphp.com/license
|
||||
*/
|
||||
class Kohana_Tests
|
||||
{
|
||||
class Kohana_Unittest_Tests {
|
||||
static protected $cache = array();
|
||||
|
||||
/**
|
||||
* Flag to identify whether the installed version of phpunit
|
||||
* is greater than or equal to 3.5
|
||||
* @var boolean
|
||||
*/
|
||||
static protected $phpunit_v35 = FALSE;
|
||||
|
||||
/**
|
||||
* Loads test files if they cannot be found by kohana
|
||||
* @param <type> $class
|
||||
@@ -38,21 +45,32 @@ class Kohana_Tests
|
||||
*/
|
||||
static public function configure_environment($do_whitelist = TRUE, $do_blacklist = TRUE)
|
||||
{
|
||||
if ( ! class_exists('PHPUnit_Util_Filter', FALSE))
|
||||
// During a webui request we need to manually load PHPUnit
|
||||
if ( ! class_exists('PHPUnit_Util_Filter', FALSE) AND ! function_exists('phpunit_autoload'))
|
||||
{
|
||||
// Make sure the PHPUnit classes are available
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
try
|
||||
{
|
||||
include_once 'PHPUnit/Autoload.php';
|
||||
}
|
||||
catch (ErrorException $e)
|
||||
{
|
||||
include_once 'PHPUnit/Framework.php';
|
||||
}
|
||||
}
|
||||
|
||||
// Allow PHPUnit to handle exceptions and errors
|
||||
if (Kohana::$is_cli)
|
||||
{
|
||||
restore_exception_handler();
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
spl_autoload_register(array('Kohana_Tests', 'autoload'));
|
||||
spl_autoload_register(array('Unittest_tests', 'autoload'));
|
||||
|
||||
Kohana_Tests::$cache = ($cache = Kohana::cache('unittest_whitelist_cache')) === NULL ? array() : $cache;
|
||||
// As of PHPUnit v3.5 there are slight differences in the way files are black|whitelisted
|
||||
self::$phpunit_v35 = function_exists('phpunit_autoload');
|
||||
|
||||
Unittest_tests::$cache = (($cache = Kohana::cache('unittest_whitelist_cache')) === NULL) ? array() : $cache;
|
||||
|
||||
$config = Kohana::config('unittest');
|
||||
|
||||
@@ -63,17 +81,7 @@ class Kohana_Tests
|
||||
|
||||
if ($do_blacklist AND count($config['blacklist']))
|
||||
{
|
||||
foreach ($config->blacklist as $item)
|
||||
{
|
||||
if (is_dir($item))
|
||||
{
|
||||
PHPUnit_Util_Filter::addDirectoryToFilter($item);
|
||||
}
|
||||
else
|
||||
{
|
||||
PHPUnit_Util_Filter::addFileToFilter($item);
|
||||
}
|
||||
}
|
||||
Unittest_tests::blacklist($config->blacklist);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +116,7 @@ class Kohana_Tests
|
||||
|
||||
$files = Kohana::list_files('tests');
|
||||
|
||||
$suite = new PHPUnit_Framework_TestSuite();
|
||||
$suite = new PHPUnit_Framework_TestSuite;
|
||||
|
||||
self::addTests($suite, $files);
|
||||
|
||||
@@ -123,8 +131,15 @@ class Kohana_Tests
|
||||
* @param PHPUnit_Framework_TestSuite $suite The test suite to add to
|
||||
* @param array $files Array of files to test
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
static function addTests(PHPUnit_Framework_TestSuite $suite, array $files)
|
||||
// @codingStandardsIgnoreEnd
|
||||
{
|
||||
if (self::$phpunit_v35)
|
||||
{
|
||||
$filter = PHP_CodeCoverage_Filter::getInstance();
|
||||
}
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (is_array($file))
|
||||
@@ -146,7 +161,53 @@ class Kohana_Tests
|
||||
require_once($file);
|
||||
}
|
||||
|
||||
PHPUnit_Util_Filter::addFileToFilter($file);
|
||||
if (isset($filter))
|
||||
{
|
||||
$filter->addFileToBlacklist($file);
|
||||
}
|
||||
else
|
||||
{
|
||||
PHPUnit_Util_Filter::addFileToFilter($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blacklist a set of files in PHPUnit code coverage
|
||||
*
|
||||
* @param array A set of files to blacklist
|
||||
*/
|
||||
static public function blacklist(array $blacklist_items)
|
||||
{
|
||||
if (self::$phpunit_v35)
|
||||
{
|
||||
$filter = PHP_CodeCoverage_Filter::getInstance();
|
||||
|
||||
foreach ($blacklist_items as $item)
|
||||
{
|
||||
if (is_dir($item))
|
||||
{
|
||||
$filter->addDirectoryToBlacklist($item);
|
||||
}
|
||||
else
|
||||
{
|
||||
$filter->addFileToBlacklist($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($blacklist_items as $item)
|
||||
{
|
||||
if (is_dir($item))
|
||||
{
|
||||
PHPUnit_Util_Filter::addDirectoryToFilter($item);
|
||||
}
|
||||
else
|
||||
{
|
||||
PHPUnit_Util_Filter::addFileToFilter($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,7 +230,7 @@ class Kohana_Tests
|
||||
|
||||
if (count($directories))
|
||||
{
|
||||
foreach ($directories as &$directory)
|
||||
foreach ($directories as & $directory)
|
||||
{
|
||||
$directory = realpath($directory).'/';
|
||||
}
|
||||
@@ -234,6 +295,11 @@ class Kohana_Tests
|
||||
*/
|
||||
static protected function set_whitelist($files)
|
||||
{
|
||||
if (self::$phpunit_v35)
|
||||
{
|
||||
$filter = PHP_CodeCoverage_Filter::getInstance();
|
||||
}
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (is_array($file))
|
||||
@@ -242,19 +308,26 @@ class Kohana_Tests
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ! isset(Kohana_Tests::$cache[$file]))
|
||||
if ( ! isset(Unittest_tests::$cache[$file]))
|
||||
{
|
||||
$relative_path = substr($file, strrpos($file, 'classes'.DIRECTORY_SEPARATOR) + 8, -strlen(EXT));
|
||||
$cascading_file = Kohana::find_file('classes', $relative_path);
|
||||
|
||||
// The theory is that if this file is the highest one in the cascading filesystem
|
||||
// then it's safe to whitelist
|
||||
Kohana_Tests::$cache[$file] = ($cascading_file === $file);
|
||||
Unittest_tests::$cache[$file] = ($cascading_file === $file);
|
||||
}
|
||||
|
||||
if (Kohana_Tests::$cache[$file])
|
||||
if (Unittest_tests::$cache[$file])
|
||||
{
|
||||
PHPUnit_Util_Filter::addFileToWhitelist($file);
|
||||
if (isset($filter))
|
||||
{
|
||||
$filter->addFileToWhitelist($file);
|
||||
}
|
||||
else
|
||||
{
|
||||
PHPUnit_Util_Filter::addFileToWhitelist($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Unittest_Helpers extends Kohana_Unittest_Helpers {}
|
@@ -0,0 +1,3 @@
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Unittest_Runner extends Kohana_Unittest_Runner {}
|
@@ -0,0 +1,3 @@
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Unittest_TestCase extends Kohana_Unittest_TestCase {}
|
@@ -0,0 +1,3 @@
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Unittest_Tests extends Kohana_Unittest_Tests {}
|
Reference in New Issue
Block a user