TestShellTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * TestSuiteShell test case
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, 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-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Test.Case.Console.Command
  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('TestShell', 'Console/Command');
  21. class TestTestShell extends TestShell {
  22. public function mapFileToCase($file, $category, $throwOnMissingFile = true) {
  23. return $this->_mapFileToCase($file, $category, $throwOnMissingFile);
  24. }
  25. public function mapFileToCategory($file) {
  26. return $this->_mapFileToCategory($file);
  27. }
  28. }
  29. class TestShellTest extends CakeTestCase {
  30. /**
  31. * setUp test case
  32. *
  33. * @return void
  34. */
  35. public function setUp() {
  36. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  37. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  38. $this->Shell = $this->getMock(
  39. 'TestTestShell',
  40. array('in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', '_run', 'clear'),
  41. array($out, $out, $in)
  42. );
  43. $this->Shell->OptionParser = $this->getMock('ConsoleOptionParser', array(), array(null, false));
  44. }
  45. /**
  46. * tearDown method
  47. *
  48. * @return void
  49. */
  50. public function tearDown() {
  51. unset($this->Dispatch, $this->Shell);
  52. }
  53. /**
  54. * testMapCoreFileToCategory
  55. *
  56. *
  57. * @return void
  58. */
  59. public function testMapCoreFileToCategory() {
  60. $this->Shell->startup();
  61. $return = $this->Shell->mapFileToCategory('lib/Cake/basics.php');
  62. $this->assertSame('core', $return);
  63. $return = $this->Shell->mapFileToCategory('lib/Cake/Core/App.php');
  64. $this->assertSame('core', $return);
  65. $return = $this->Shell->mapFileToCategory('lib/Cake/Some/Deeply/Nested/Structure.php');
  66. $this->assertSame('core', $return);
  67. }
  68. /**
  69. * testMapCoreFileToCase
  70. *
  71. * basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized
  72. *
  73. * @return void
  74. */
  75. public function testMapCoreFileToCase() {
  76. $this->Shell->startup();
  77. $return = $this->Shell->mapFileToCase('lib/Cake/basics.php', 'core');
  78. $this->assertSame('Basics', $return);
  79. $return = $this->Shell->mapFileToCase('lib/Cake/Core/App.php', 'core');
  80. $this->assertSame('Core/App', $return);
  81. $return = $this->Shell->mapFileToCase('lib/Cake/Some/Deeply/Nested/Structure.php', 'core', false);
  82. $this->assertSame('Some/Deeply/Nested/Structure', $return);
  83. }
  84. /**
  85. * test available list of test cases for an empty category
  86. *
  87. * @return void
  88. */
  89. public function testAvailableWithEmptyList() {
  90. $this->Shell->startup();
  91. $this->Shell->args = array('unexistant-category');
  92. $this->Shell->expects($this->at(0))->method('out')->with(__d('cake_console', "No test cases available \n\n"));
  93. $this->Shell->OptionParser->expects($this->once())->method('help');
  94. $this->Shell->available();
  95. }
  96. /**
  97. * test available list of test cases for core category
  98. *
  99. * @return void
  100. */
  101. public function testAvailableCoreCategory() {
  102. $this->Shell->startup();
  103. $this->Shell->args = array('core');
  104. $this->Shell->expects($this->at(0))->method('out')->with('Core Test Cases:');
  105. $this->Shell->expects($this->at(1))->method('out')
  106. ->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[1\].*/'));
  107. $this->Shell->expects($this->at(2))->method('out')
  108. ->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[2\].*/'));
  109. $this->Shell->expects($this->once())->method('in')
  110. ->with(__d('cake_console', 'What test case would you like to run?'), null, 'q')
  111. ->will($this->returnValue('1'));
  112. $this->Shell->expects($this->once())->method('_run');
  113. $this->Shell->available();
  114. $this->assertEquals($this->Shell->args, array('core', 'AllBehaviors'));
  115. }
  116. /**
  117. * Tests that correct option for test runner are passed
  118. *
  119. * @return void
  120. */
  121. public function testRunnerOptions() {
  122. $this->Shell->startup();
  123. $this->Shell->args = array('core', 'Basics');
  124. $this->Shell->params = array('filter' => 'myFilter', 'colors' => true, 'verbose' => true);
  125. $this->Shell->expects($this->once())->method('_run')
  126. ->with(
  127. array('app' => false, 'plugin' => null, 'core' => true, 'output' => 'text', 'case' => 'Basics'),
  128. array('--filter', 'myFilter', '--colors', '--verbose')
  129. );
  130. $this->Shell->main();
  131. }
  132. }