Skip to content

Commit

Permalink
Fix more failing tests in Console/Command.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 7, 2012
1 parent b825a52 commit 7762846
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
9 changes: 1 addition & 8 deletions lib/Cake/Console/Command/BakeShell.php
@@ -1,13 +1,5 @@
<?php
/**
* Command-line code generation utility to automate programmer chores.
*
* Bake is CakePHP's code generation script, which can help you kickstart
* application development by writing fully functional skeleton controllers,
* models, and views. Going further, Bake can also write Unit Tests for you.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -20,6 +12,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Console\Command;

use Cake\Console\Shell;
use Cake\Core\App;
use Cake\Core\Configure;
Expand Down
55 changes: 34 additions & 21 deletions lib/Cake/Test/TestCase/Console/Command/BakeShellTest.php
@@ -1,10 +1,5 @@
<?php
/**
* BakeShell Test Case
*
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -18,9 +13,11 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\Console\Command;

use Cake\Console\Command\BakeShellShell;
use Cake\Controller\Controller;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\TestSuite\TestCase;

class BakeShellTest extends TestCase {
Expand All @@ -30,7 +27,7 @@ class BakeShellTest extends TestCase {
*
* @var array
*/
public $fixtures = array('core.user');
public $fixtures = array('core.comment');

/**
* setup test
Expand All @@ -39,14 +36,15 @@ class BakeShellTest extends TestCase {
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
$out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
$in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);

$this->Shell = $this->getMock(
'Cake\Console\Command\BakeShell',
array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
array($out, $out, $in)
['in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'],
[$out, $out, $in]
);
Configure::write('App.namespace', 'TestApp');
}

/**
Expand All @@ -65,13 +63,26 @@ public function tearDown() {
* @return void
*/
public function testAllWithModelName() {
$userExists = App::classname('User', 'Model');
$this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`.');

$this->Shell->Model = $this->getMock('Cake\Console\Command\Task\ModelTask', array(), array(&$this->Dispatcher));
$this->Shell->Controller = $this->getMock('Cake\Console\Command\Task\ControllerTask', array(), array(&$this->Dispatcher));
$this->Shell->View = $this->getMock('Cake\Console\Command\Task\ModelTask', array(), array(&$this->Dispatcher));
$this->Shell->DbConfig = $this->getMock('Cake\Console\Command\Task\DbConfigTask', array(), array(&$this->Dispatcher));
$this->Shell->Model = $this->getMock(
'Cake\Console\Command\Task\ModelTask',
[],
[&$this->Dispatcher]
);
$this->Shell->Controller = $this->getMock(
'Cake\Console\Command\Task\ControllerTask',
[],
[&$this->Dispatcher]
);
$this->Shell->View = $this->getMock(
'Cake\Console\Command\Task\ModelTask',
[],
[&$this->Dispatcher]
);
$this->Shell->DbConfig = $this->getMock(
'Cake\Console\Command\Task\DbConfigTask',
[],
[&$this->Dispatcher]
);

$this->Shell->DbConfig->expects($this->once())
->method('getConfig')
Expand All @@ -91,20 +102,22 @@ public function testAllWithModelName() {
$this->Shell->View->expects($this->once())
->method('execute');

$this->Shell->expects($this->once())->method('_stop');
$this->Shell->expects($this->once())
->method('_stop');

$this->Shell->expects($this->at(0))
->method('out')
->with('Bake All');

$this->Shell->expects($this->at(5))
$this->Shell->expects($this->at(4))
->method('out')
->with('<success>Bake All complete</success>');

$this->Shell->connection = '';
$this->Shell->params = array();
$this->Shell->args = array('User');
$this->Shell->args = array('Comment');
$this->Shell->all();

$this->assertEquals('User', $this->Shell->View->args[0]);
$this->assertEquals('Comment', $this->Shell->View->args[0]);
}
}

0 comments on commit 7762846

Please sign in to comment.