pictcode / lib / Cake / TestSuite / CakeTestRunner.php @ 1368d528
履歴 | 表示 | アノテート | ダウンロード (3.275 KB)
| 1 |
<?php
|
|---|---|
| 2 |
/**
|
| 3 |
* TestRunner for CakePHP Test suite.
|
| 4 |
*
|
| 5 |
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
| 6 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
| 7 |
*
|
| 8 |
* Licensed under The MIT License
|
| 9 |
* For full copyright and license information, please see the LICENSE.txt
|
| 10 |
* Redistributions of files must retain the above copyright notice.
|
| 11 |
*
|
| 12 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
| 13 |
* @link http://cakephp.org CakePHP(tm) Project
|
| 14 |
* @since CakePHP(tm) v 2.0
|
| 15 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
| 16 |
*/
|
| 17 |
|
| 18 |
if (!defined('__PHPUNIT_PHAR__')) { |
| 19 |
require_once 'PHPUnit/TextUI/TestRunner.php'; |
| 20 |
} |
| 21 |
|
| 22 |
App::uses('CakeFixtureManager', 'TestSuite/Fixture'); |
| 23 |
|
| 24 |
/**
|
| 25 |
* A custom test runner for CakePHP's use of PHPUnit.
|
| 26 |
*
|
| 27 |
* @package Cake.TestSuite
|
| 28 |
*/
|
| 29 |
class CakeTestRunner extends PHPUnit_TextUI_TestRunner { |
| 30 |
|
| 31 |
/**
|
| 32 |
* Lets us pass in some options needed for CakePHP's webrunner.
|
| 33 |
*
|
| 34 |
* @param mixed $loader The test suite loader
|
| 35 |
* @param array $params list of options to be used for this run
|
| 36 |
*/
|
| 37 |
public function __construct($loader, $params) { |
| 38 |
parent::__construct($loader); |
| 39 |
$this->_params = $params; |
| 40 |
} |
| 41 |
|
| 42 |
/**
|
| 43 |
* Actually run a suite of tests. Cake initializes fixtures here using the chosen fixture manager
|
| 44 |
*
|
| 45 |
* @param PHPUnit_Framework_Test $suite The test suite to run
|
| 46 |
* @param array $arguments The CLI arguments
|
| 47 |
* @return void
|
| 48 |
*/
|
| 49 |
public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) { |
| 50 |
if (isset($arguments['printer'])) { |
| 51 |
static::$versionStringPrinted = true; |
| 52 |
} |
| 53 |
|
| 54 |
$fixture = $this->_getFixtureManager($arguments); |
| 55 |
foreach ($suite->getIterator() as $test) { |
| 56 |
if ($test instanceof CakeTestCase) { |
| 57 |
$fixture->fixturize($test); |
| 58 |
$test->fixtureManager = $fixture; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
$return = parent::doRun($suite, $arguments); |
| 63 |
$fixture->shutdown();
|
| 64 |
return $return; |
| 65 |
} |
| 66 |
|
| 67 |
// @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP
|
| 68 |
/**
|
| 69 |
* Create the test result and splice on our code coverage reports.
|
| 70 |
*
|
| 71 |
* @return PHPUnit_Framework_TestResult
|
| 72 |
*/
|
| 73 |
protected function createTestResult() { |
| 74 |
$result = new PHPUnit_Framework_TestResult; |
| 75 |
if (!empty($this->_params['codeCoverage'])) { |
| 76 |
if (method_exists($result, 'collectCodeCoverageInformation')) { |
| 77 |
$result->collectCodeCoverageInformation(true); |
| 78 |
} |
| 79 |
if (method_exists($result, 'setCodeCoverage')) { |
| 80 |
$result->setCodeCoverage(new PHP_CodeCoverage()); |
| 81 |
} |
| 82 |
} |
| 83 |
return $result; |
| 84 |
} |
| 85 |
// @codingStandardsIgnoreEnd
|
| 86 |
|
| 87 |
/**
|
| 88 |
* Get the fixture manager class specified or use the default one.
|
| 89 |
*
|
| 90 |
* @param array $arguments The CLI arguments.
|
| 91 |
* @return mixed instance of a fixture manager.
|
| 92 |
* @throws RuntimeException When fixture manager class cannot be loaded.
|
| 93 |
*/
|
| 94 |
protected function _getFixtureManager($arguments) { |
| 95 |
if (isset($arguments['fixtureManager'])) { |
| 96 |
App::uses($arguments['fixtureManager'], 'TestSuite'); |
| 97 |
if (class_exists($arguments['fixtureManager'])) { |
| 98 |
return new $arguments['fixtureManager']; |
| 99 |
} |
| 100 |
throw new RuntimeException(__d('cake_dev', 'Could not find fixture manager %s.', $arguments['fixtureManager'])); |
| 101 |
} |
| 102 |
App::uses('AppFixtureManager', 'TestSuite'); |
| 103 |
if (class_exists('AppFixtureManager')) { |
| 104 |
return new AppFixtureManager(); |
| 105 |
} |
| 106 |
return new CakeFixtureManager(); |
| 107 |
} |
| 108 |
|
| 109 |
} |