Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding test case for BakeShell and bake all
- Loading branch information
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* BakeShell Test Case | ||
* | ||
* | ||
* PHP versions 4 and 5 | ||
* | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org | ||
* @package cake | ||
* @subpackage cake.tests.cases.console.libs.tasks | ||
* @since CakePHP(tm) v 1.3 | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
App::import('Core', 'Shell'); | ||
|
||
if (!defined('DISABLE_AUTO_DISPATCH')) { | ||
define('DISABLE_AUTO_DISPATCH', true); | ||
} | ||
|
||
if (!class_exists('ShellDispatcher')) { | ||
ob_start(); | ||
$argv = false; | ||
require CAKE . 'console' . DS . 'cake.php'; | ||
ob_end_clean(); | ||
} | ||
|
||
require_once CAKE . 'console' . DS . 'libs' . DS . 'bake.php'; | ||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php'; | ||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php'; | ||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'db_config.php'; | ||
|
||
Mock::generatePartial( | ||
'ShellDispatcher', 'BakeShellMockShellDispatcher', | ||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment') | ||
); | ||
Mock::generatePartial( | ||
'BakeShell', 'MockBakeShell', | ||
array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest') | ||
); | ||
|
||
Mock::generate('DbConfigTask', 'BakeShellMockDbConfigTask'); | ||
Mock::generate('ModelTask', 'BakeShellMockModelTask'); | ||
Mock::generate('ControllerTask', 'BakeShellMockControllerTask'); | ||
|
||
if (!class_exists('ArticlesController')) { | ||
class ArticlesController extends Controller { | ||
var $name = 'Articles'; | ||
} | ||
} | ||
|
||
class BakeShellTestCase extends CakeTestCase { | ||
/** | ||
* fixtures | ||
* | ||
* @var array | ||
**/ | ||
var $fixtures = array('core.article'); | ||
/** | ||
* start test | ||
* | ||
* @return void | ||
**/ | ||
function startTest() { | ||
$this->Dispatch =& new BakeShellMockShellDispatcher(); | ||
$this->Shell =& new MockBakeShell(); | ||
$this->Shell->Dispatch =& $this->Dispatcher; | ||
$this->Shell->Dispatch->shellPaths = App::path('shells'); | ||
} | ||
/** | ||
* test bake all | ||
* | ||
* @return void | ||
**/ | ||
function testAllWithModelName() { | ||
$this->Shell->Model =& new BakeShellMockModelTask(); | ||
$this->Shell->Controller =& new BakeShellMockControllerTask(); | ||
$this->Shell->View =& new BakeShellMockModelTask(); | ||
$this->Shell->DbConfig =& new BakeShellMockDbConfigTask(); | ||
|
||
$this->Shell->DbConfig->expectOnce('getConfig'); | ||
$this->Shell->DbConfig->setReturnValue('getConfig', 'test_suite'); | ||
|
||
$this->Shell->Model->setReturnValue('bake', true); | ||
$this->Shell->Model->expectNever('getName'); | ||
$this->Shell->Model->expectOnce('bake'); | ||
|
||
$this->Shell->Controller->expectOnce('bake'); | ||
$this->Shell->Controller->setReturnValue('bake', true); | ||
|
||
$this->Shell->View->expectOnce('execute'); | ||
|
||
$this->Shell->expectAt(0, 'out', array('Bake All')); | ||
$this->Shell->expectAt(1, 'out', array('Article Model was baked.')); | ||
$this->Shell->expectAt(2, 'out', array('Article Controller was baked.')); | ||
$this->Shell->expectAt(3, 'out', array('Article Views were baked.')); | ||
$this->Shell->expectAt(4, 'out', array('Bake All complete')); | ||
|
||
$this->Shell->params = array(); | ||
$this->Shell->args = array('Article', 'exitvalue'); | ||
$this->Shell->all(); | ||
} | ||
} |