PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Cake/TestSuite/CakeTestRunner.php

https://bitbucket.org/udeshika/fake_twitter
PHP | 98 lines | 49 code | 6 blank | 43 comment | 8 complexity | e675587f602c3b5c7f0d368c1653215d MD5 | raw file
  1. <?php
  2. /**
  3. * TestRunner for CakePHP Test suite.
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @since CakePHP(tm) v 2.0
  16. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  17. */
  18. require_once 'PHPUnit/TextUI/TestRunner.php';
  19. /**
  20. * A custom test runner for Cake's use of PHPUnit.
  21. *
  22. * @package Cake.TestSuite
  23. */
  24. class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
  25. /**
  26. * Lets us pass in some options needed for cake's webrunner.
  27. *
  28. * @return void
  29. */
  30. public function __construct($loader, $params) {
  31. parent::__construct($loader);
  32. $this->_params = $params;
  33. }
  34. /**
  35. * Actually run a suite of tests. Cake initializes fixtures here using the chosen fixture manager
  36. *
  37. * @param PHPUnit_Framework_Test $suite
  38. * @param array $arguments
  39. * @return void
  40. */
  41. public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) {
  42. if (isset($arguments['printer'])) {
  43. self::$versionStringPrinted = true;
  44. }
  45. $fixture = $this->_getFixtureManager($arguments);
  46. foreach ($suite->getIterator() as $test) {
  47. if ($test instanceof CakeTestCase) {
  48. $fixture->fixturize($test);
  49. $test->fixtureManager = $fixture;
  50. }
  51. }
  52. $return = parent::doRun($suite, $arguments);
  53. $fixture->shutdown();
  54. return $return;
  55. }
  56. /**
  57. * Create the test result and splice on our code coverage reports.
  58. *
  59. * @return PHPUnit_Framework_TestResult
  60. */
  61. protected function createTestResult() {
  62. $result = new PHPUnit_Framework_TestResult;
  63. if (!empty($this->_params['codeCoverage'])) {
  64. if (method_exists($result, 'collectCodeCoverageInformation')) {
  65. $result->collectCodeCoverageInformation(true);
  66. }
  67. if (method_exists($result, 'setCodeCoverage')) {
  68. $result->setCodeCoverage(new PHP_CodeCoverage());
  69. }
  70. }
  71. return $result;
  72. }
  73. /**
  74. * Get the fixture manager class specified or use the default one.
  75. *
  76. * @return instance of a fixture manager.
  77. */
  78. protected function _getFixtureManager($arguments) {
  79. if (isset($arguments['fixtureManager'])) {
  80. App::uses($arguments['fixtureManager'], 'TestSuite');
  81. if (class_exists($arguments['fixtureManager'])) {
  82. return new $arguments['fixtureManager'];
  83. }
  84. throw new RuntimeException(__d('cake_dev', 'Could not find fixture manager %s.', $arguments['fixtureManager']));
  85. }
  86. App::uses('AppFixtureManager', 'TestSuite');
  87. if (class_exists('AppFixtureManager')) {
  88. return new AppFixtureManager();
  89. }
  90. return new CakeFixtureManager();
  91. }
  92. }