BakeShellTest.php 3.2 KB

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