BakeShellTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 1.3.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Console\Command;
  16. use Cake\Console\Command\BakeShellShell;
  17. use Cake\Controller\Controller;
  18. use Cake\Core\App;
  19. use Cake\Core\Configure;
  20. use Cake\Core\Plugin;
  21. use Cake\TestSuite\TestCase;
  22. class BakeShellTest extends TestCase {
  23. /**
  24. * fixtures
  25. *
  26. * @var array
  27. */
  28. public $fixtures = array('core.comment');
  29. /**
  30. * setup test
  31. *
  32. * @return void
  33. */
  34. public function setUp() {
  35. parent::setUp();
  36. $out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
  37. $in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
  38. $this->Shell = $this->getMock(
  39. 'Cake\Console\Command\BakeShell',
  40. ['in', 'out', 'hr', 'err', 'createFile', '_stop'],
  41. [$out, $out, $in]
  42. );
  43. Configure::write('App.namespace', 'TestApp');
  44. }
  45. /**
  46. * tearDown method
  47. *
  48. * @return void
  49. */
  50. public function tearDown() {
  51. parent::tearDown();
  52. unset($this->Shell);
  53. }
  54. /**
  55. * test bake all
  56. *
  57. * @return void
  58. */
  59. public function testAllWithModelName() {
  60. $this->Shell->Model = $this->getMock('Cake\Console\Command\Task\ModelTask');
  61. $this->Shell->Controller = $this->getMock('Cake\Console\Command\Task\ControllerTask');
  62. $this->Shell->View = $this->getMock('Cake\Console\Command\Task\ModelTask');
  63. $this->Shell->Model->expects($this->once())
  64. ->method('bake')
  65. ->with('Comments')
  66. ->will($this->returnValue(true));
  67. $this->Shell->Controller->expects($this->once())
  68. ->method('bake')
  69. ->with('Comments')
  70. ->will($this->returnValue(true));
  71. $this->Shell->View->expects($this->once())
  72. ->method('execute');
  73. $this->Shell->expects($this->at(0))
  74. ->method('out')
  75. ->with('Bake All');
  76. $this->Shell->expects($this->at(2))
  77. ->method('out')
  78. ->with('<success>Bake All complete</success>');
  79. $this->Shell->connection = '';
  80. $this->Shell->params = [];
  81. $this->Shell->args = ['Comment'];
  82. $this->Shell->all();
  83. $this->assertEquals('Comments', $this->Shell->View->args[0]);
  84. }
  85. /**
  86. * Test the main function.
  87. *
  88. * @return void
  89. */
  90. public function testMain() {
  91. $this->Shell->expects($this->at(0))
  92. ->method('out')
  93. ->with($this->stringContains('The following commands'));
  94. $this->Shell->expects($this->at(3))
  95. ->method('out')
  96. ->with('model');
  97. $this->Shell->main();
  98. }
  99. /**
  100. * Test loading tasks from core directories.
  101. *
  102. * @return void
  103. */
  104. public function testLoadTasksCoreAndApp() {
  105. $this->Shell->loadTasks();
  106. $expected = [
  107. 'Behavior',
  108. 'Component',
  109. 'Controller',
  110. 'Fixture',
  111. 'Helper',
  112. 'Model',
  113. 'Plugin',
  114. 'Project',
  115. 'Test',
  116. 'View',
  117. 'Zerg',
  118. ];
  119. $this->assertEquals($expected, $this->Shell->tasks);
  120. }
  121. /**
  122. * Test loading tasks from plugins
  123. *
  124. * @return void
  125. */
  126. public function testLoadTasksPlugin() {
  127. Plugin::load('TestPlugin');
  128. $this->Shell->loadTasks();
  129. $this->assertContains('TestPlugin.Widget', $this->Shell->tasks);
  130. $this->assertContains('TestPlugin.Zerg', $this->Shell->tasks);
  131. }
  132. }