TestsuiteShell.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Test Suite Shell
  4. *
  5. * This is a bc wrapper for the newer Test shell
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://book.cakephp.org/2.0/en/development/testing.html
  16. * @since CakePHP(tm) v 1.2.0.4433
  17. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  18. */
  19. App::uses('TestShell', 'Console/Command');
  20. App::uses('AppShell', 'Console/Command');
  21. App::uses('CakeTestSuiteDispatcher', 'TestSuite');
  22. App::uses('CakeTestSuiteCommand', 'TestSuite');
  23. App::uses('CakeTestLoader', 'TestSuite');
  24. /**
  25. * Provides a CakePHP wrapper around PHPUnit.
  26. * Adds in CakePHP's fixtures and gives access to plugin, app and core test cases
  27. *
  28. * @package Cake.Console.Command
  29. */
  30. class TestsuiteShell extends TestShell {
  31. /**
  32. * get the option parser for the test suite.
  33. *
  34. * @return void
  35. */
  36. public function getOptionParser() {
  37. $parser = parent::getOptionParser();
  38. $parser->description(array(
  39. __d('cake_console', 'The CakePHP Testsuite allows you to run test cases from the command line'),
  40. __d('cake_console', "<warning>This shell is for backwards-compatibility only</warning>\nuse the test shell instead"),
  41. ));
  42. return $parser;
  43. }
  44. /**
  45. * Parse the CLI options into an array CakeTestDispatcher can use.
  46. *
  47. * @return array Array of params for CakeTestDispatcher
  48. */
  49. protected function _parseArgs() {
  50. if (empty($this->args)) {
  51. return;
  52. }
  53. $params = array(
  54. 'core' => false,
  55. 'app' => false,
  56. 'plugin' => null,
  57. 'output' => 'text',
  58. );
  59. $category = $this->args[0];
  60. if ($category === 'core') {
  61. $params['core'] = true;
  62. } elseif ($category === 'app') {
  63. $params['app'] = true;
  64. } elseif ($category !== 'core') {
  65. $params['plugin'] = $category;
  66. }
  67. if (isset($this->args[1])) {
  68. $params['case'] = $this->args[1];
  69. }
  70. return $params;
  71. }
  72. /**
  73. * Main entry point to this shell
  74. *
  75. * @return void
  76. */
  77. public function main() {
  78. $this->out(__d('cake_console', 'CakePHP Test Shell'));
  79. $this->hr();
  80. $args = $this->_parseArgs();
  81. if (empty($args['case'])) {
  82. return $this->available();
  83. }
  84. $this->_run($args, $this->_runnerOptions());
  85. }
  86. }