1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18: require_once 'PHPUnit/TextUI/TestRunner.php';
19:
20: 21: 22: 23: 24:
25: class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
26: 27: 28: 29: 30:
31: public function __construct($loader, $params) {
32: parent::__construct($loader);
33: $this->_params = $params;
34: }
35:
36: 37: 38: 39: 40: 41: 42:
43: public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) {
44: if (isset($arguments['printer'])) {
45: self::$versionStringPrinted = true;
46: }
47:
48: $fixture = $this->_getFixtureManager($arguments);
49: foreach ($suite->getIterator() as $test) {
50: if ($test instanceof CakeTestCase) {
51: $fixture->fixturize($test);
52: $test->fixtureManager = $fixture;
53: }
54: }
55:
56: $return = parent::doRun($suite, $arguments);
57: $fixture->shutdown();
58: return $return;
59: }
60:
61: 62: 63: 64: 65:
66: protected function createTestResult() {
67: $result = new PHPUnit_Framework_TestResult;
68: if (!empty($this->_params['codeCoverage'])) {
69: if (method_exists($result, 'collectCodeCoverageInformation')) {
70: $result->collectCodeCoverageInformation(true);
71: }
72: if (method_exists($result, 'setCodeCoverage')) {
73: $result->setCodeCoverage(new PHP_CodeCoverage());
74: }
75: }
76: return $result;
77: }
78:
79: 80: 81: 82: 83:
84: protected function _getFixtureManager($arguments) {
85: if (isset($arguments['fixtureManager'])) {
86: App::uses($arguments['fixtureManager'], 'TestSuite');
87: if (class_exists($arguments['fixtureManager'])) {
88: return new $arguments['fixtureManager'];
89: }
90: throw new RuntimeException(__d('cake_dev', 'Could not find fixture manager %s.', $arguments['fixtureManager']));
91: }
92: App::uses('AppFixtureManager', 'TestSuite');
93: if (class_exists('AppFixtureManager')) {
94: return new AppFixtureManager();
95: }
96: return new CakeFixtureManager();
97: }
98: }
99: