TestsuiteShellTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * TestSuiteShell test case
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2010, 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-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package cake.tests.libs
  16. * @since CakePHP(tm) v 2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('ShellDispatcher', 'Console');
  20. App::uses('TestsuiteShell', 'Console/Command');
  21. class TestsuiteShellTest extends CakeTestCase {
  22. /**
  23. * setUp test case
  24. *
  25. * @return void
  26. */
  27. public function setUp() {
  28. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  29. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  30. $this->Shell = $this->getMock(
  31. 'TestsuiteShell',
  32. array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', 'run', 'clear'),
  33. array($out, $out, $in)
  34. );
  35. $this->Shell->OptionParser = $this->getMock('ConsoleOptionParser', array(), array(null, false));
  36. }
  37. /**
  38. * tearDown method
  39. *
  40. * @return void
  41. */
  42. public function tearDown() {
  43. unset($this->Dispatch, $this->Shell);
  44. }
  45. /**
  46. * test available list of test cases for an empty category
  47. *
  48. * @return void
  49. */
  50. public function testAvailableWithEmptyList() {
  51. $this->Shell->startup();
  52. $this->Shell->args = array('unexistant-category');
  53. $this->Shell->expects($this->at(0))->method('out')->with(__d('cake_console', "No test cases available \n\n"));
  54. $this->Shell->OptionParser->expects($this->once())->method('help');
  55. $this->Shell->available();
  56. }
  57. /**
  58. * test available list of test cases for core category
  59. *
  60. * @return void
  61. */
  62. public function testAvailableCoreCategory() {
  63. $this->Shell->startup();
  64. $this->Shell->args = array('core');
  65. $this->Shell->expects($this->at(0))->method('out')->with('Core Test Cases:');
  66. $this->Shell->expects($this->at(1))->method('out')
  67. ->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[1\].*/'));
  68. $this->Shell->expects($this->at(2))->method('out')
  69. ->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[2\].*/'));
  70. $this->Shell->expects($this->once())->method('in')
  71. ->with(__d('cake_console', 'What test case would you like to run?'), null, 'q')
  72. ->will($this->returnValue('1'));
  73. $this->Shell->expects($this->once())->method('run');
  74. $this->Shell->available();
  75. $this->assertEquals($this->Shell->args, array('core', 'AllBehaviors'));
  76. }
  77. /**
  78. * Tests that correct option for test runner are passed
  79. *
  80. * @return void
  81. */
  82. public function testRunnerOptions() {
  83. $this->Shell->startup();
  84. $this->Shell->args = array('core', 'Basics');
  85. $this->Shell->params = array('filter' => 'myFilter', 'colors' => true, 'verbose' => true);
  86. $this->Shell->expects($this->once())->method('run')
  87. ->with(
  88. array('app' => false, 'plugin' => null, 'core' => true, 'output' => 'text', 'case' => 'Basics'),
  89. array('--filter', 'myFilter', '--colors', '--verbose')
  90. );
  91. $this->Shell->main();
  92. }
  93. }