Update Kohana to 3.1.3.1

This commit is contained in:
Deon George
2011-05-16 22:47:16 +10:00
parent 8b658b497a
commit ff2370c368
401 changed files with 14070 additions and 10213 deletions

View File

@@ -25,46 +25,12 @@ And watch the gitorious magic...
Of course, you can always download the code from the [github project](http://github.com/kohana/unittest) as an archive.
The following instructions will assume you've moved it to `modules/unittest`, if you haven't then you should update all paths accordingly.
## Running the tests
**Step 1**: Enable this module in your bootstrap file:
$ phpunit --bootstrap=modules/unittest/bootstrap.php {tests}
/**
* Enable modules. Modules are referenced by a relative or absolute path.
*/
Kohana::modules(array(
'unittest' => MODPATH.'unittest', // PHPUnit integration
));
Where `{tests}` can either be a path to a folder of tests, or a path to the the `tests.php` (`modules/unittest/tests.php`)
**Step 2**: In your app's bootstrap file modify the lines where the request is handled, which by default looks like:
Please see the guide pages for more info. An example of how we run the tests for the kohana project can be found in the [phing build script](https://github.com/kohana/kohana/blob/3.1/master/build.xml#L172).
/**
* Execute the main request using PATH_INFO. If no URI source is specified,
* the URI will be automatically detected.
*/
echo Request::instance($_SERVER['PATH_INFO'])
->execute()
->send_headers()
->response;
To:
if ( ! defined('SUPPRESS_REQUEST'))
{
/**
* Execute the main request using PATH_INFO. If no URI source is specified,
* the URI will be automatically detected.
*/
echo Request::instance($_SERVER['PATH_INFO'])
->execute()
->send_headers()
->response;
}
**Step 3**: Create a folder called `unittest` in your app's cache dir (`APPPATH/cache`). If you don't want to use this path for storing generated reports, skip this step and change the config file.
Note: make sure the settings in `config/unittest.php` are correct for your environment. If they aren't, copy the file to `application/config/unittest.php` and change the values accordingly.
**Step 4**: Start testing!
You can find more info and tutorials in the [guide/](http://github.com/kohana/unittest/tree/master/guide/) directory.
If you're looking for more info on running the core kohana tests then please see our [dev wiki](https://github.com/kohana/kohana/wiki/Unit-Testing-Kohana)

View File

@@ -57,15 +57,21 @@ define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);
// Make the application relative to the docroot
if ( ! is_dir($application) AND is_dir(DOCROOT.$application))
{
$application = DOCROOT.$application;
}
// Make the modules relative to the docroot
if ( ! is_dir($modules) AND is_dir(DOCROOT.$modules))
{
$modules = DOCROOT.$modules;
}
// Make the system relative to the docroot
if ( ! is_dir($system) AND is_dir(DOCROOT.$system))
{
$system = DOCROOT.$system;
}
// Define the absolute paths for configured directories
define('APPPATH', realpath($application).DIRECTORY_SEPARATOR);
@@ -91,23 +97,6 @@ if ( ! defined('KOHANA_START_MEMORY'))
define('KOHANA_START_MEMORY', memory_get_usage());
}
// Load the base, low-level functions
require SYSPATH.'base'.EXT;
// Load the core Kohana class
require SYSPATH.'classes/kohana/core'.EXT;
if (is_file(APPPATH.'classes/kohana'.EXT))
{
// Application extends the core
require APPPATH.'classes/kohana'.EXT;
}
else
{
// Load empty core extension
require SYSPATH.'classes/kohana'.EXT;
}
// Bootstrap the application
require APPPATH.'bootstrap'.EXT;

View File

@@ -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;

View File

@@ -2,13 +2,14 @@
/**
* TestCase for testing a database
*
* @package Kohana/Unittest
* @package Kohana/UnitTest
* @author Kohana Team
* @author BRMatt <matthew@sigswitch.com>
* @copyright (c) 2008-2009 Kohana Team
* @license http://kohanaphp.com/license
*/
Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Database_TestCase {
// @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
@@ -43,8 +44,13 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
*/
public function setUp()
{
if(self::$_assert_type_compatability === NULL)
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', '<=');
}
@@ -95,15 +101,15 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
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);
}
/**
* 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
@@ -161,10 +167,8 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
*/
public static function assertInstanceOf($expected, $actual, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertType($expected, $actual, $message);
}
return parent::assertInstanceOf($expected, $actual, $message);
}
@@ -180,10 +184,8 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
*/
public static function assertAttributeInstanceOf($expected, $attributeName, $classOrObject, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertAttributeType($expected, $attributeName, $classOrObject, $message);
}
return parent::assertAttributeInstanceOf($expected, $attributeName, $classOrObject, $message);
}
@@ -198,10 +200,8 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
*/
public static function assertNotInstanceOf($expected, $actual, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertNotType($expected, $actual, $message);
}
return self::assertNotInstanceOf($expected, $actual, $message);
}
@@ -217,10 +217,8 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
*/
public static function assertAttributeNotInstanceOf($expected, $attributeName, $classOrObject, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertAttributeNotType($expected, $attributeName, $classOrObject, $message);
}
return self::assertAttributeNotInstanceOf($expected, $attributeName, $classOrObject, $message);
}
@@ -235,10 +233,8 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
*/
public static function assertInternalType($expected, $actual, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertType($expected, $actual, $message);
}
return parent::assertInternalType($expected, $actual, $message);
}
@@ -254,10 +250,8 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
*/
public static function assertAttributeInternalType($expected, $attributeName, $classOrObject, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertAttributeType($expected, $attributeName, $classOrObject, $message);
}
return self::assertAttributeInternalType($expected, $attributeName, $classOrObject, $message);
}
@@ -272,10 +266,8 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
*/
public static function assertNotInternalType($expected, $actual, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertNotType($expected, $actual, $message);
}
return self::assertNotInternalType($expected, $actual, $message);
}
@@ -291,10 +283,8 @@ Abstract Class Kohana_Unittest_Database_TestCase extends PHPUnit_Extensions_Data
*/
public static function assertAttributeNotInternalType($expected, $attributeName, $classOrObject, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertAttributeNotType($expected, $attributeName, $classOrObject, $message);
}
return self::assertAttributeNotInternalType($expected, $attributeName, $classOrObject, $message);
}

View File

@@ -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
@@ -139,7 +132,7 @@ 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)
{

View File

@@ -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
@@ -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;
@@ -209,9 +207,7 @@ 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);
@@ -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)

View File

@@ -1,14 +1,10 @@
<?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
*/
// @codingStandardsIgnoreFile
abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
/**
@@ -44,12 +40,17 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public function setUp()
{
if(self::$_assert_type_compatability === NULL)
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->_helpers = new Unittest_Helpers;
$this->setEnvironment($this->environmentDefault);
}
@@ -70,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();
}
/**
@@ -82,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);
}
/**
@@ -108,7 +109,7 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public function hasInternet()
{
return Kohana_Unittest_Helpers::has_internet();
return Unittest_Helpers::has_internet();
}
/**
@@ -121,10 +122,8 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public static function assertInstanceOf($expected, $actual, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertType($expected, $actual, $message);
}
return parent::assertInstanceOf($expected, $actual, $message);
}
@@ -140,10 +139,8 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public static function assertAttributeInstanceOf($expected, $attributeName, $classOrObject, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertAttributeType($expected, $attributeName, $classOrObject, $message);
}
return parent::assertAttributeInstanceOf($expected, $attributeName, $classOrObject, $message);
}
@@ -158,10 +155,8 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public static function assertNotInstanceOf($expected, $actual, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertNotType($expected, $actual, $message);
}
return self::assertNotInstanceOf($expected, $actual, $message);
}
@@ -177,10 +172,8 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public static function assertAttributeNotInstanceOf($expected, $attributeName, $classOrObject, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertAttributeNotType($expected, $attributeName, $classOrObject, $message);
}
return self::assertAttributeNotInstanceOf($expected, $attributeName, $classOrObject, $message);
}
@@ -195,10 +188,8 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public static function assertInternalType($expected, $actual, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertType($expected, $actual, $message);
}
return parent::assertInternalType($expected, $actual, $message);
}
@@ -214,10 +205,8 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public static function assertAttributeInternalType($expected, $attributeName, $classOrObject, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertAttributeType($expected, $attributeName, $classOrObject, $message);
}
return self::assertAttributeInternalType($expected, $attributeName, $classOrObject, $message);
}
@@ -232,10 +221,8 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public static function assertNotInternalType($expected, $actual, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertNotType($expected, $actual, $message);
}
return self::assertNotInternalType($expected, $actual, $message);
}
@@ -251,10 +238,8 @@ abstract class Kohana_Unittest_TestCase extends PHPUnit_Framework_TestCase {
*/
public static function assertAttributeNotInternalType($expected, $attributeName, $classOrObject, $message = '')
{
if(self::$_assert_type_compatability)
{
if (self::$_assert_type_compatability)
return self::assertAttributeNotType($expected, $attributeName, $classOrObject, $message);
}
return self::assertAttributeNotInternalType($expected, $attributeName, $classOrObject, $message);
}

View File

@@ -1,16 +1,16 @@
<?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();
/**
@@ -56,7 +56,6 @@ class Kohana_Tests
{
include_once 'PHPUnit/Framework.php';
}
}
// Allow PHPUnit to handle exceptions and errors
@@ -66,13 +65,13 @@ class Kohana_Tests
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');
if ($do_whitelist AND $config->use_whitelist)
@@ -82,7 +81,7 @@ class Kohana_Tests
if ($do_blacklist AND count($config['blacklist']))
{
Kohana_Tests::blacklist($config->blacklist);
Unittest_tests::blacklist($config->blacklist);
}
}
@@ -132,7 +131,9 @@ 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)
{
@@ -159,7 +160,7 @@ class Kohana_Tests
{
require_once($file);
}
if (isset($filter))
{
$filter->addFileToBlacklist($file);
@@ -307,17 +308,17 @@ 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])
{
if (isset($filter))
{

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Unittest_Helpers extends Kohana_Unittest_Helpers {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Unittest_Runner extends Kohana_Unittest_Runner {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Unittest_TestCase extends Kohana_Unittest_TestCase {}

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Unittest_Tests extends Kohana_Unittest_Tests {}

View File

@@ -18,7 +18,7 @@ return array(
// If you don't use a whitelist then only files included during the request will be counted
// If you do, then only whitelisted items will be counted
'use_whitelist' => FALSE,
'use_whitelist' => TRUE,
// Items to whitelist, only used in cli
// Web runner ui allows user to choose which items to whitelist

View File

@@ -14,7 +14,7 @@ return array(
'name' => 'Unittest',
// A short description of this module, shown on the index page
'description' => 'Unit testing for Kohana using PHPUnit',
'description' => 'Kohana unit testing.',
// Copyright message, shown in the footer for this module
'copyright' => '&copy; 20082010 Kohana Team',

View File

@@ -1,13 +1,2 @@
# Unittest
# Unittest
Unittest is a module that provides unittesting for Kohana using [PHPUnit](http://www.phpunit.de/).
### Running from the command line
$ phpunit --bootstrap=index.php modules/unittest/tests.php
Of course, you'll need to make sure the path to the tests.php file is correct. If you want you can copy it to a more accessible location.
### Running from the web
Just navigate to `http://example.com/unittest`. You may need to use `http://example.com/index.php/unittest` if you have not enabled url rewriting in your `.htaccess`.

View File

@@ -1,41 +0,0 @@
# Installing PHPUnit
Before the Unittest module will work, you need to install PHPUnit.
## Installing on Windows/XAMPP
**(written by bitshift, see [this forum post](http://forum.kohanaframework.org/discussion/7346))**
Assuming xampp is installed to `C:\xampp`, and that you have pear installed, do the following:
1. Open a command prompt and go to C:\xampp\php
2. Type `pear update-channels` (updates channel definitions)
3. Type `pear upgrade` (upgrades all existing packages and pear)
4. Type `pear channel-discover components.ez.no` (This is needed for PHPUnit)
5. Type `pear channel-discover pear.symfony-project.com` (Also needed by PHPUnit)
6. Type `pear channel-discover pear.phpunit.de` (This is the phpunit channel)
7. Type `pear install --alldeps phpunit/PHPUnit` (This actually installs PHPUnit and all dependencies)
[!!] You may have to edit `memory_limit` in your `php.ini` if you get some sort of memory error, just set it to something really large, then back when your done.
Please see [this forum post](http://forum.kohanaframework.org/discussion/7346) for more information.
## Installing on *nix
If any of these fail, try again with sudo, most of them require root priveledges.
1. Install the 'php-pear' package.
- On Ubuntu/Debian type `sudo apt-get install php-pear`
2. Make sure Pear is up-to-date
- Type `pear update-channels`
- Type `pear upgrade`
3. Add the required channels
- Type `pear channel-discover components.ez.no`
- Type `pear channel-discover pear.symfony-project.com`
- Type `pear channel-discover pear.phpunit.de`
4. Install PHPUnit itself
- Type `pear install --alldeps phpunit/PHPUnit`
## Class 'PHPUnit_Framework_TestSuite' not found
If you get this error than it means... I don't even know.

View File

@@ -1,6 +1,5 @@
## [UnitTest]()
- [Installing PHPUnit](installing)
- [Testing](testing)
- [Mock Objects](mockobjects)
- [Troubleshooting](troubleshooting)
- [Testing workflows](workflows)
- [Testing workflows](testing_workflows)

View File

@@ -1,8 +1,18 @@
### From the command line
$ phpunit --bootstrap=index.php modules/unittest/tests.php
Of course, you'll need to make sure the path to the tests.php file is correct. If you want you can copy it to a more accessible location
### From the web
Just navigate to http://example.com/unittest. You may need to use http://example.com/index.php/unittest if you have not enabled url rewriting in your .htaccess.
## Writing tests
If you're writing a test for your application, place it in `application/tests`. Similarly, if you're writing a test for a module place it in `modules/<modulefolder>/tests`.
If you're writing a test for your application, place it in "application/tests". Similarly, if you're writing a test for a module place it in modules/[modulefolder]/tests
Rather than tell you how to write tests I'll point you in the direction of the [PHPUnit Manual](http://www.phpunit.de/manual/3.4/en/index.html). One thing you should bear in mind when writing tests is that testcases should extend [Kohana_Unittest_Testcase] rather than `PHPUnit_Framework_TestCase`.
Rather than tell you how to write tests I'll point you in the direction of the [PHPUnit Manual](http://www.phpunit.de/manual/3.4/en/index.html). One thing you should bear in mind when writing tests is that testcases should extend Unittest_Testcase rather than PHPUnit_Framework_TestCase, doing so gives you access to useful kohana specific helpers such as `setEnvironment()`.
Here's a taster of some of the cool things you can do with phpunit:
@@ -14,7 +24,7 @@ Ordinarily you could use a foreach loop to iterate over an array of test data, h
<?php
Class ReallyCoolTest extends Kohana_Unittest_TestCase
Class ReallyCoolTest extends Unittest_TestCase
{
function providerStrLen()
{
@@ -57,7 +67,7 @@ To allow users to selectively run tests you need to organise your tests into gro
* @group somegroup
* @group somegroup.morespecific
*/
Class AnotherReallyCoolTest extends Kohana_Unittest_TestCase
Class AnotherReallyCoolTest extends Unittest_TestCase
{
/**
* Tests can also be grouped too!

View File

@@ -4,7 +4,7 @@ Having unittests for your application is a nice idea, but unless you actually us
## Testing through the webui
The web ui is a fairly temporary solution, aimed at helping developers get into unittesting and code coverage. Eventually it's hoped that people migrate on to CI servers, but it's fine for calculating code coverage locally.
The web ui is a fairly temporary solution, aimed at helping developers get into unittesting and code coverage. Eventually it's hoped that people migrate on to the termainl & CI servers.
To access it goto
@@ -34,15 +34,15 @@ You can also specify a custom test suite loader (enter the path to your tests.ph
## Looping shell
I personally prefer to do all of my development in an advanced text editor such as vim/gedit/np++.
If you're developing in a text editor such as textmate, vim, gedit etc. chances are phpunit support isn't natively supported by your editor.
To test while I work I run tests in an infinte looping. It's very easy to setup and only takes a few commands to setup.
On nix you can run the following commands in the terminal:
In such situations you can run a simple bash script to loop over the tests every X seconds, here's an example script:
while(true) do clear; phpunit; sleep 8; done;
In my experience this gives you just enough time to see what's going wrong before the tests are rerun.
It's also quite handy to store common phpunit settings (like path to the bootstrap) in a a phpunit xml file to reduce the amount that has to be written in order to start a loop.
You will probably need to adjust the timeout (`sleep 8`) to suit your own workflow, but 8 seconds seems to be about enough time to see what's erroring before the tests are re-run.
In the above example we're using a phpunit.xml config file to specify all the unit testing settings & to reduce the complexity of the looping script.
## Continuous Integration (CI)

View File

@@ -1,10 +1,10 @@
# Troubleshooting
#### I get the error "Class Kohana_Tests could not be found" when testing from the CLI
## I get the error "Class Kohana_Tests could not be found" when testing from the CLI
You need to running PHPUnit >= 3.4, there is a bug in 3.3 which causes this.
#### Some of my classes aren't getting whitelisted for code coverage even though their module is
## Some of my classes aren't getting whitelisted for code coverage even though their module is
Only the "highest" files in the cascading filesystem are whitelisted for code coverage.
@@ -12,7 +12,7 @@ To test your module's file, remove the higher file from the cascading filesystem
A good way of testing is to create a "vanilla" testing environment for your module, devoid of anything that isn't required by the module.
#### I get a blank page when trying to generate a code coverage report
## I get a blank page when trying to generate a code coverage report
Try the following:

View File

@@ -3,7 +3,7 @@
// If we're on the CLI then PHPUnit will already be loaded
if (class_exists('PHPUnit_Util_Filter', FALSE) OR function_exists('phpunit_autoload'))
{
Kohana_Tests::configure_environment();
Unittest_Tests::configure_environment();
// Stop kohana from processing the request
define('SUPPRESS_REQUEST', TRUE);

View File

@@ -5,13 +5,13 @@ if ( ! class_exists('Kohana'))
die('Please include the kohana bootstrap file (see README.markdown)');
}
if ($file = Kohana::find_file('classes', 'kohana/tests'))
if ($file = Kohana::find_file('classes', 'unittest/tests'))
{
require_once $file;
// PHPUnit requires a test suite class to be in this file,
// so we create a faux one that uses the kohana base
Class TestSuite extends Kohana_Tests
Class TestSuite extends Unittest_Tests
{}
}
else

View File

@@ -2,7 +2,7 @@
<div id="header" class="results">
<fieldset id="results-options">
<legend>Options</legend>
<?php echo Form::open(NULL, array('method' => 'get'));?>
<?php echo Form::open($run_uri, array('method' => 'get'));?>
<?php echo Form::label('group', __('Switch Group')) ?>
<?php echo Form::select('group', $groups, $group, array('id' => 'group'));?>
<?php if ($xdebug_enabled): ?>