BakeShellTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * BakeShell Test Case
  4. *
  5. *
  6. * PHP 5
  7. *
  8. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  9. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. *
  11. * Licensed under The MIT License
  12. * For full copyright and license information, please see the LICENSE.txt
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  16. * @link http://cakephp.org CakePHP(tm) Project
  17. * @package Cake.Test.Case.Console.Command
  18. * @since CakePHP(tm) v 1.3
  19. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  20. */
  21. App::uses('ConsoleOutput', 'Console');
  22. App::uses('ConsoleInput', 'Console');
  23. App::uses('ShellDispatcher', 'Console');
  24. App::uses('Shell', 'Console');
  25. App::uses('BakeShell', 'Console/Command');
  26. App::uses('ModelTask', 'Console/Command/Task');
  27. App::uses('ControllerTask', 'Console/Command/Task');
  28. App::uses('DbConfigTask', 'Console/Command/Task');
  29. App::uses('Controller', 'Controller');
  30. if (!class_exists('UsersController')) {
  31. class UsersController extends Controller {
  32. public $name = 'Users';
  33. }
  34. }
  35. class BakeShellTest extends CakeTestCase {
  36. /**
  37. * fixtures
  38. *
  39. * @var array
  40. */
  41. public $fixtures = array('core.user');
  42. /**
  43. * setup test
  44. *
  45. * @return void
  46. */
  47. public function setUp() {
  48. parent::setUp();
  49. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  50. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  51. $this->Shell = $this->getMock(
  52. 'BakeShell',
  53. array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
  54. array($out, $out, $in)
  55. );
  56. }
  57. /**
  58. * tearDown method
  59. *
  60. * @return void
  61. */
  62. public function tearDown() {
  63. parent::tearDown();
  64. unset($this->Dispatch, $this->Shell);
  65. }
  66. /**
  67. * test bake all
  68. *
  69. * @return void
  70. */
  71. public function testAllWithModelName() {
  72. App::uses('User', 'Model');
  73. $userExists = class_exists('User');
  74. $this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`.');
  75. $this->Shell->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
  76. $this->Shell->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher));
  77. $this->Shell->View = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
  78. $this->Shell->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher));
  79. $this->Shell->DbConfig->expects($this->once())
  80. ->method('getConfig')
  81. ->will($this->returnValue('test'));
  82. $this->Shell->Model->expects($this->never())
  83. ->method('getName');
  84. $this->Shell->Model->expects($this->once())
  85. ->method('bake')
  86. ->will($this->returnValue(true));
  87. $this->Shell->Controller->expects($this->once())
  88. ->method('bake')
  89. ->will($this->returnValue(true));
  90. $this->Shell->View->expects($this->once())
  91. ->method('execute');
  92. $this->Shell->expects($this->once())->method('_stop');
  93. $this->Shell->expects($this->at(0))
  94. ->method('out')
  95. ->with('Bake All');
  96. $this->Shell->expects($this->at(5))
  97. ->method('out')
  98. ->with('<success>Bake All complete</success>');
  99. $this->Shell->connection = '';
  100. $this->Shell->params = array();
  101. $this->Shell->args = array('User');
  102. $this->Shell->all();
  103. $this->assertEquals('User', $this->Shell->View->args[0]);
  104. }
  105. }