PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/cases/console/libs/bake.test.php

https://github.com/msadouni/cakephp2x
PHP | 126 lines | 66 code | 17 blank | 43 comment | 3 complexity | 1b7d47eee33c1538eddb94bbb2239264 MD5 | raw file
  1. <?php
  2. /**
  3. * BakeShell Test Case
  4. *
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  9. * Copyright 2005-2009, 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-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org
  16. * @package cake
  17. * @subpackage cake.tests.cases.console.libs.tasks
  18. * @since CakePHP(tm) v 1.3
  19. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  20. */
  21. App::import('Shell', 'Shell', false);
  22. if (!defined('DISABLE_AUTO_DISPATCH')) {
  23. define('DISABLE_AUTO_DISPATCH', true);
  24. }
  25. if (!class_exists('ShellDispatcher')) {
  26. ob_start();
  27. $argv = false;
  28. require CAKE . 'console' . DS . 'cake.php';
  29. ob_end_clean();
  30. }
  31. require_once CAKE . 'console' . DS . 'libs' . DS . 'bake.php';
  32. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
  33. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php';
  34. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php';
  35. Mock::generatePartial(
  36. 'ShellDispatcher', 'BakeShellMockShellDispatcher',
  37. array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  38. );
  39. Mock::generatePartial(
  40. 'BakeShell', 'MockBakeShell',
  41. array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
  42. );
  43. Mock::generate('DbConfigTask', 'BakeShellMockDbConfigTask');
  44. Mock::generate('ModelTask', 'BakeShellMockModelTask');
  45. Mock::generate('ControllerTask', 'BakeShellMockControllerTask');
  46. if (!class_exists('UsersController')) {
  47. class UsersController extends Controller {
  48. var $name = 'Users';
  49. }
  50. }
  51. class BakeShellTestCase extends CakeTestCase {
  52. /**
  53. * fixtures
  54. *
  55. * @var array
  56. * @access public
  57. */
  58. var $fixtures = array('core.user');
  59. /**
  60. * start test
  61. *
  62. * @return void
  63. * @access public
  64. */
  65. function startTest() {
  66. $this->Dispatch =& new BakeShellMockShellDispatcher();
  67. $this->Shell =& new MockBakeShell();
  68. $this->Shell->Dispatch =& $this->Dispatch;
  69. $this->Shell->Dispatch->shellPaths = App::path('shells');
  70. }
  71. /**
  72. * endTest method
  73. *
  74. * @return void
  75. * @access public
  76. */
  77. function endTest() {
  78. unset($this->Dispatch, $this->Shell);
  79. }
  80. /**
  81. * test bake all
  82. *
  83. * @return void
  84. * @access public
  85. */
  86. function testAllWithModelName() {
  87. $this->Shell->Model =& new BakeShellMockModelTask();
  88. $this->Shell->Controller =& new BakeShellMockControllerTask();
  89. $this->Shell->View =& new BakeShellMockModelTask();
  90. $this->Shell->DbConfig =& new BakeShellMockDbConfigTask();
  91. $this->Shell->DbConfig->expectOnce('getConfig');
  92. $this->Shell->DbConfig->setReturnValue('getConfig', 'test_suite');
  93. $this->Shell->Model->setReturnValue('bake', true);
  94. $this->Shell->Model->expectNever('getName');
  95. $this->Shell->Model->expectOnce('bake');
  96. $this->Shell->Controller->expectOnce('bake');
  97. $this->Shell->Controller->setReturnValue('bake', true);
  98. $this->Shell->View->expectOnce('execute');
  99. $this->Shell->expectAt(0, 'out', array('Bake All'));
  100. $this->Shell->expectAt(1, 'out', array('User Model was baked.'));
  101. $this->Shell->expectAt(2, 'out', array('User Controller was baked.'));
  102. $this->Shell->expectAt(3, 'out', array('User Views were baked.'));
  103. $this->Shell->expectAt(4, 'out', array('Bake All complete'));
  104. $this->Shell->params = array();
  105. $this->Shell->args = array('User');
  106. $this->Shell->all();
  107. }
  108. }
  109. ?>