BakeShellTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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-2012, 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-2012, 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('ConsoleOutput', 'Console');
  21. App::uses('ConsoleInput', 'Console');
  22. App::uses('ShellDispatcher', 'Console');
  23. App::uses('Shell', 'Console');
  24. App::uses('BakeShell', 'Console/Command');
  25. App::uses('ModelTask', 'Console/Command/Task');
  26. App::uses('ControllerTask', 'Console/Command/Task');
  27. App::uses('DbConfigTask', 'Console/Command/Task');
  28. App::uses('Controller', 'Controller');
  29. if (!class_exists('UsersController')) {
  30. class UsersController extends Controller {
  31. public $name = 'Users';
  32. }
  33. }
  34. class BakeShellTest extends CakeTestCase {
  35. /**
  36. * fixtures
  37. *
  38. * @var array
  39. */
  40. public $fixtures = array('core.user');
  41. /**
  42. * setup test
  43. *
  44. * @return void
  45. */
  46. public function setUp() {
  47. parent::setUp();
  48. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  49. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  50. $this->Shell = $this->getMock(
  51. 'BakeShell',
  52. array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
  53. array($out, $out, $in)
  54. );
  55. }
  56. /**
  57. * tearDown method
  58. *
  59. * @return void
  60. */
  61. public function tearDown() {
  62. parent::tearDown();
  63. unset($this->Dispatch, $this->Shell);
  64. }
  65. /**
  66. * test bake all
  67. *
  68. * @return void
  69. */
  70. public function testAllWithModelName() {
  71. App::uses('User', 'Model');
  72. $userExists = class_exists('User');
  73. $this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`.');
  74. $this->Shell->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
  75. $this->Shell->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher));
  76. $this->Shell->View = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
  77. $this->Shell->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher));
  78. $this->Shell->DbConfig->expects($this->once())
  79. ->method('getConfig')
  80. ->will($this->returnValue('test'));
  81. $this->Shell->Model->expects($this->never())
  82. ->method('getName');
  83. $this->Shell->Model->expects($this->once())
  84. ->method('bake')
  85. ->will($this->returnValue(true));
  86. $this->Shell->Controller->expects($this->once())
  87. ->method('bake')
  88. ->will($this->returnValue(true));
  89. $this->Shell->View->expects($this->once())
  90. ->method('execute');
  91. $this->Shell->expects($this->once())->method('_stop');
  92. $this->Shell->expects($this->at(0))
  93. ->method('out')
  94. ->with('Bake All');
  95. $this->Shell->expects($this->at(5))
  96. ->method('out')
  97. ->with('<success>Bake All complete</success>');
  98. $this->Shell->connection = '';
  99. $this->Shell->params = array();
  100. $this->Shell->args = array('User');
  101. $this->Shell->all();
  102. $this->assertEquals('User', $this->Shell->View->args[0]);
  103. }
  104. }