Skip to content

Commit

Permalink
Adding test case for BakeShell and bake all
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 16, 2009
1 parent 1e8d019 commit 9f3a9e6
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions cake/tests/cases/console/libs/bake.test.php
@@ -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();
}
}

0 comments on commit 9f3a9e6

Please sign in to comment.