BakeShellTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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-2010, 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-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP(tm) Project
  16. * @package cake.tests.cases.console.libs.tasks
  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. * @access public
  38. */
  39. public $fixtures = array('core.user');
  40. /**
  41. * setup test
  42. *
  43. * @return void
  44. */
  45. public function setUp() {
  46. parent::setUp();
  47. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  48. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  49. $this->Shell = $this->getMock(
  50. 'BakeShell',
  51. array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
  52. array($out, $out, $in)
  53. );
  54. }
  55. /**
  56. * teardown method
  57. *
  58. * @return void
  59. */
  60. public function tearDown() {
  61. parent::tearDown();
  62. unset($this->Dispatch, $this->Shell);
  63. }
  64. /**
  65. * test bake all
  66. *
  67. * @return void
  68. */
  69. public function testAllWithModelName() {
  70. App::uses('User', 'Model');
  71. $userExists = class_exists('User');
  72. if ($this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`. %s')) {
  73. return;
  74. }
  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())->method('getConfig')->will($this->returnValue('test'));
  80. $this->Shell->Model->expects($this->never())->method('getName');
  81. $this->Shell->Model->expects($this->once())->method('bake')->will($this->returnValue(true));
  82. $this->Shell->Controller->expects($this->once())->method('bake')->will($this->returnValue(true));
  83. $this->Shell->View->expects($this->once())->method('execute');
  84. $this->Shell->expects($this->once())->method('_stop');
  85. $this->Shell->expects($this->at(0))->method('out')->with('Bake All');
  86. $this->Shell->expects($this->at(5))->method('out')->with('<success>Bake All complete</success>');
  87. $this->Shell->connection = '';
  88. $this->Shell->params = array();
  89. $this->Shell->args = array('User');
  90. $this->Shell->all();
  91. }
  92. }