1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17:
18: if (!class_exists('PHPUnit_TextUI_TestRunner')) {
19: require_once 'PHPUnit/TextUI/TestRunner.php';
20: }
21: if (class_exists('SebastianBergmann\CodeCoverage\CodeCoverage')) {
22: class_alias('SebastianBergmann\CodeCoverage\CodeCoverage', 'PHP_CodeCoverage');
23: class_alias('SebastianBergmann\CodeCoverage\Report\Text', 'PHP_CodeCoverage_Report_Text');
24: class_alias('SebastianBergmann\CodeCoverage\Report\PHP', 'PHP_CodeCoverage_Report_PHP');
25: class_alias('SebastianBergmann\CodeCoverage\Report\Clover', 'PHP_CodeCoverage_Report_Clover');
26: class_alias('SebastianBergmann\CodeCoverage\Report\Html\Facade', 'PHP_CodeCoverage_Report_HTML');
27: class_alias('SebastianBergmann\CodeCoverage\Exception', 'PHP_CodeCoverage_Exception');
28: }
29:
30: App::uses('CakeFixtureManager', 'TestSuite/Fixture');
31:
32: 33: 34: 35: 36:
37: class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
38:
39: 40: 41: 42: 43: 44:
45: public function __construct($loader, $params) {
46: parent::__construct($loader);
47: $this->_params = $params;
48: }
49:
50: 51: 52: 53: 54: 55: 56: 57: 58:
59: public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array(), $exit = true) {
60: if (isset($arguments['printer'])) {
61: static::$versionStringPrinted = true;
62: }
63:
64: $fixture = $this->_getFixtureManager($arguments);
65: $iterator = $suite->getIterator();
66: if ($iterator instanceof RecursiveIterator) {
67: $iterator = new RecursiveIteratorIterator($iterator);
68: }
69: foreach ($iterator as $test) {
70: if ($test instanceof CakeTestCase) {
71: $fixture->fixturize($test);
72: $test->fixtureManager = $fixture;
73: }
74: }
75:
76: $return = parent::doRun($suite, $arguments, $exit);
77: $fixture->shutdown();
78: return $return;
79: }
80:
81:
82: 83: 84: 85: 86:
87: protected function createTestResult() {
88: $result = new PHPUnit_Framework_TestResult;
89: if (!empty($this->_params['codeCoverage'])) {
90: if (method_exists($result, 'collectCodeCoverageInformation')) {
91: $result->collectCodeCoverageInformation(true);
92: }
93: if (method_exists($result, 'setCodeCoverage')) {
94: $result->setCodeCoverage(new PHP_CodeCoverage());
95: }
96: }
97: return $result;
98: }
99:
100:
101: 102: 103: 104: 105: 106: 107:
108: protected function _getFixtureManager($arguments) {
109: if (!empty($arguments['fixtureManager'])) {
110: App::uses($arguments['fixtureManager'], 'TestSuite');
111: if (class_exists($arguments['fixtureManager'])) {
112: return new $arguments['fixtureManager'];
113: }
114: throw new RuntimeException(__d('cake_dev', 'Could not find fixture manager %s.', $arguments['fixtureManager']));
115: }
116: App::uses('AppFixtureManager', 'TestSuite');
117: if (class_exists('AppFixtureManager')) {
118: return new AppFixtureManager();
119: }
120: return new CakeFixtureManager();
121: }
122:
123: }
124: