ApiShellTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * ApiShellTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2012, Cake Software Foundation, Inc.
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
  14. * @link http://cakephp.org CakePHP Project
  15. * @package Cake.Test.Case.Console.Command
  16. * @since CakePHP v 1.2.0.7726
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('ConsoleOutput', 'Console');
  20. App::uses('ConsoleInput', 'Console');
  21. App::uses('ShellDispatcher', 'Console');
  22. App::uses('Shell', 'Console');
  23. App::uses('ApiShell', 'Console/Command');
  24. /**
  25. * ApiShellTest class
  26. *
  27. * @package Cake.Test.Case.Console.Command
  28. */
  29. class ApiShellTest extends CakeTestCase {
  30. /**
  31. * setUp method
  32. *
  33. * @return void
  34. */
  35. public function setUp() {
  36. parent::setUp();
  37. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  38. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  39. $this->Shell = $this->getMock(
  40. 'ApiShell',
  41. array('in', 'out', 'createFile', 'hr', '_stop'),
  42. array( $out, $out, $in)
  43. );
  44. }
  45. /**
  46. * Test that method names are detected properly including those with no arguments.
  47. *
  48. * @return void
  49. */
  50. public function testMethodNameDetection() {
  51. $this->Shell->expects($this->any())->method('in')->will($this->returnValue('q'));
  52. $this->Shell->expects($this->at(0))->method('out')->with('Controller');
  53. $expected = array(
  54. '1. afterFilter()',
  55. '2. afterScaffoldSave($method)',
  56. '3. afterScaffoldSaveError($method)',
  57. '4. beforeFilter()',
  58. '5. beforeRedirect($url, $status = NULL, $exit = true)',
  59. '6. beforeRender()',
  60. '7. beforeScaffold($method)',
  61. '8. constructClasses()',
  62. '9. disableCache()',
  63. '10. flash($message, $url, $pause = 1, $layout = \'flash\')',
  64. '11. getEventManager()',
  65. '12. header($status)',
  66. '13. httpCodes($code = NULL)',
  67. '14. implementedEvents()',
  68. '15. invokeAction($request)',
  69. '16. loadModel($modelClass = NULL, $id = NULL)',
  70. '17. paginate($object = NULL, $scope = array (), $whitelist = array ())',
  71. '18. postConditions($data = array (), $op = NULL, $bool = \'AND\', $exclusive = false)',
  72. '19. redirect($url, $status = NULL, $exit = true)',
  73. '20. referer($default = NULL, $local = false)',
  74. '21. render($view = NULL, $layout = NULL)',
  75. '22. scaffoldError($method)',
  76. '23. set($one, $two = NULL)',
  77. '24. setAction($action)',
  78. '25. setRequest($request)',
  79. '26. shutdownProcess()',
  80. '27. startupProcess()',
  81. '28. validate()',
  82. '29. validateErrors()'
  83. );
  84. $this->Shell->expects($this->at(2))->method('out')->with($expected);
  85. $this->Shell->args = array('controller');
  86. $this->Shell->paths['controller'] = CAKE . 'Controller' . DS;
  87. $this->Shell->main();
  88. }
  89. }