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