TestsuiteShell.php 2.5 KB

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