BakeShellTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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\TestSuite\TestCase;
  21. class BakeShellTest extends TestCase {
  22. /**
  23. * fixtures
  24. *
  25. * @var array
  26. */
  27. public $fixtures = array('core.comment');
  28. /**
  29. * setup test
  30. *
  31. * @return void
  32. */
  33. public function setUp() {
  34. parent::setUp();
  35. $out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
  36. $in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
  37. $this->Shell = $this->getMock(
  38. 'Cake\Console\Command\BakeShell',
  39. ['in', 'out', 'hr', 'err', 'createFile', '_stop'],
  40. [$out, $out, $in]
  41. );
  42. Configure::write('App.namespace', 'TestApp');
  43. }
  44. /**
  45. * tearDown method
  46. *
  47. * @return void
  48. */
  49. public function tearDown() {
  50. parent::tearDown();
  51. unset($this->Shell);
  52. }
  53. /**
  54. * test bake all
  55. *
  56. * @return void
  57. */
  58. public function testAllWithModelName() {
  59. $this->Shell->Model = $this->getMock('Cake\Console\Command\Task\ModelTask');
  60. $this->Shell->Controller = $this->getMock('Cake\Console\Command\Task\ControllerTask');
  61. $this->Shell->View = $this->getMock('Cake\Console\Command\Task\ModelTask');
  62. $this->Shell->Model->expects($this->once())
  63. ->method('bake')
  64. ->with('Comments')
  65. ->will($this->returnValue(true));
  66. $this->Shell->Controller->expects($this->once())
  67. ->method('bake')
  68. ->with('Comments')
  69. ->will($this->returnValue(true));
  70. $this->Shell->View->expects($this->once())
  71. ->method('execute');
  72. $this->Shell->expects($this->at(0))
  73. ->method('out')
  74. ->with('Bake All');
  75. $this->Shell->expects($this->at(2))
  76. ->method('out')
  77. ->with('<success>Bake All complete</success>');
  78. $this->Shell->connection = '';
  79. $this->Shell->params = [];
  80. $this->Shell->args = ['Comment'];
  81. $this->Shell->all();
  82. $this->assertEquals('Comments', $this->Shell->View->args[0]);
  83. }
  84. /**
  85. * Test the main function.
  86. *
  87. * @return void
  88. */
  89. public function testMain() {
  90. $this->Shell->expects($this->at(0))
  91. ->method('out')
  92. ->with($this->stringContains('The following commands'));
  93. $this->Shell->expects($this->at(3))
  94. ->method('out')
  95. ->with('model');
  96. $this->Shell->main();
  97. }
  98. }