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