2010-07-07 04:40:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TestRunner for CakePHP Test suite.
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-07 04:40:28 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-07-07 04:40:28 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-07 04:40:28 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
|
* @since CakePHP(tm) v 2.0
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2010-07-07 04:40:28 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2014-11-24 19:51:36 +00:00
|
|
|
if (!defined('__PHPUNIT_PHAR__')) {
|
|
|
|
require_once 'PHPUnit/TextUI/TestRunner.php';
|
|
|
|
}
|
2010-07-07 04:40:28 +00:00
|
|
|
|
2012-10-15 02:22:46 +00:00
|
|
|
App::uses('CakeFixtureManager', 'TestSuite/Fixture');
|
|
|
|
|
2010-07-07 04:40:28 +00:00
|
|
|
/**
|
2013-09-27 17:36:43 +00:00
|
|
|
* A custom test runner for CakePHP's use of PHPUnit.
|
2010-07-07 04:40:28 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.TestSuite
|
2010-07-07 04:40:28 +00:00
|
|
|
*/
|
2011-02-12 21:08:48 +00:00
|
|
|
class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
|
2012-03-05 02:51:44 +00:00
|
|
|
|
2011-02-13 00:01:38 +00:00
|
|
|
/**
|
2013-09-27 17:36:43 +00:00
|
|
|
* Lets us pass in some options needed for CakePHP's webrunner.
|
2011-02-13 00:01:38 +00:00
|
|
|
*
|
2014-06-05 04:19:27 +00:00
|
|
|
* @param mixed $loader The test suite loader
|
2012-11-28 22:30:47 +00:00
|
|
|
* @param array $params list of options to be used for this run
|
2011-02-13 00:01:38 +00:00
|
|
|
*/
|
|
|
|
public function __construct($loader, $params) {
|
|
|
|
parent::__construct($loader);
|
|
|
|
$this->_params = $params;
|
|
|
|
}
|
2010-07-07 04:40:28 +00:00
|
|
|
|
2011-02-12 22:36:00 +00:00
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* Actually run a suite of tests. Cake initializes fixtures here using the chosen fixture manager
|
2011-02-12 22:36:00 +00:00
|
|
|
*
|
2014-06-05 04:19:27 +00:00
|
|
|
* @param PHPUnit_Framework_Test $suite The test suite to run
|
|
|
|
* @param array $arguments The CLI arguments
|
2011-02-12 22:36:00 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-02-12 21:45:26 +00:00
|
|
|
public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) {
|
2011-02-12 23:39:25 +00:00
|
|
|
if (isset($arguments['printer'])) {
|
2015-07-21 08:22:53 +00:00
|
|
|
static::$versionStringPrinted = true;
|
2011-02-12 23:39:25 +00:00
|
|
|
}
|
|
|
|
|
2011-02-12 22:36:00 +00:00
|
|
|
$fixture = $this->_getFixtureManager($arguments);
|
2011-02-12 21:45:26 +00:00
|
|
|
foreach ($suite->getIterator() as $test) {
|
|
|
|
if ($test instanceof CakeTestCase) {
|
|
|
|
$fixture->fixturize($test);
|
|
|
|
$test->fixtureManager = $fixture;
|
|
|
|
}
|
|
|
|
}
|
2011-02-12 23:39:25 +00:00
|
|
|
|
2011-02-12 22:36:00 +00:00
|
|
|
$return = parent::doRun($suite, $arguments);
|
2011-02-12 21:45:26 +00:00
|
|
|
$fixture->shutdown();
|
2011-02-12 22:36:00 +00:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2012-03-05 02:51:44 +00:00
|
|
|
// @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP
|
2011-02-13 00:01:38 +00:00
|
|
|
/**
|
|
|
|
* Create the test result and splice on our code coverage reports.
|
|
|
|
*
|
|
|
|
* @return PHPUnit_Framework_TestResult
|
|
|
|
*/
|
|
|
|
protected function createTestResult() {
|
|
|
|
$result = new PHPUnit_Framework_TestResult;
|
2011-11-05 21:29:55 +00:00
|
|
|
if (!empty($this->_params['codeCoverage'])) {
|
2011-11-05 21:46:32 +00:00
|
|
|
if (method_exists($result, 'collectCodeCoverageInformation')) {
|
|
|
|
$result->collectCodeCoverageInformation(true);
|
|
|
|
}
|
|
|
|
if (method_exists($result, 'setCodeCoverage')) {
|
|
|
|
$result->setCodeCoverage(new PHP_CodeCoverage());
|
|
|
|
}
|
2011-02-13 00:01:38 +00:00
|
|
|
}
|
|
|
|
return $result;
|
2011-12-16 06:52:07 +00:00
|
|
|
}
|
2012-03-05 02:51:44 +00:00
|
|
|
// @codingStandardsIgnoreEnd
|
2011-02-13 00:01:38 +00:00
|
|
|
|
2011-02-12 22:36:00 +00:00
|
|
|
/**
|
|
|
|
* Get the fixture manager class specified or use the default one.
|
|
|
|
*
|
2014-06-05 04:19:27 +00:00
|
|
|
* @param array $arguments The CLI arguments.
|
2012-11-28 22:30:47 +00:00
|
|
|
* @return mixed instance of a fixture manager.
|
2012-03-05 02:51:44 +00:00
|
|
|
* @throws RuntimeException When fixture manager class cannot be loaded.
|
2011-02-12 22:36:00 +00:00
|
|
|
*/
|
|
|
|
protected function _getFixtureManager($arguments) {
|
2011-02-14 00:01:53 +00:00
|
|
|
if (isset($arguments['fixtureManager'])) {
|
2011-03-12 04:57:50 +00:00
|
|
|
App::uses($arguments['fixtureManager'], 'TestSuite');
|
|
|
|
if (class_exists($arguments['fixtureManager'])) {
|
2011-02-14 00:01:53 +00:00
|
|
|
return new $arguments['fixtureManager'];
|
|
|
|
}
|
2011-03-20 15:35:43 +00:00
|
|
|
throw new RuntimeException(__d('cake_dev', 'Could not find fixture manager %s.', $arguments['fixtureManager']));
|
2011-02-12 22:36:00 +00:00
|
|
|
}
|
2011-03-11 05:20:14 +00:00
|
|
|
App::uses('AppFixtureManager', 'TestSuite');
|
|
|
|
if (class_exists('AppFixtureManager')) {
|
2011-02-14 00:01:53 +00:00
|
|
|
return new AppFixtureManager();
|
2011-02-12 22:36:00 +00:00
|
|
|
}
|
2011-02-14 00:01:53 +00:00
|
|
|
return new CakeFixtureManager();
|
2010-07-07 04:40:28 +00:00
|
|
|
}
|
2012-03-05 02:51:44 +00:00
|
|
|
|
2011-11-03 03:25:09 +00:00
|
|
|
}
|