TestsuiteShell.php 2.5 KB

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