Fixing ShellDispatcher::parseParams tests to reflect the changes in what they do.

Adding tests for Shell::runCommand().
This commit is contained in:
mark_story 2010-10-09 23:09:19 -04:00
parent 3d351e7760
commit cea9dadaa2
2 changed files with 54 additions and 10 deletions

View file

@ -602,4 +602,55 @@ class ShellTest extends CakeTestCase {
$this->assertFalse($this->Shell->hasMethod('_secret'), '_secret is callable');
$this->assertFalse($this->Shell->hasMethod('no_access'), 'no_access is callable');
}
/**
* test run command calling main.
*
* @return void
*/
function testRunCommandMain() {
$methods = get_class_methods('Shell');
$Mock = $this->getMock('Shell', array('main', 'startup'), array(), '', false);
$Mock->expects($this->once())->method('main')->will($this->returnValue(true));
$Mock->expects($this->once())->method('startup');
$result = $Mock->runCommand(null, array());
$this->assertTrue($result);
}
/**
* test run command causing exception on Shell method.
*
* @expectedException RuntimeException
* @return void
*/
function testRunCommandBaseclassMethod() {
$methods = get_class_methods('Shell');
$Mock = $this->getMock('Shell', array('startup'), array(), '', false);
$Mock->expects($this->once())->method('startup');
$Mock->expects($this->never())->method('hr');
$result = $Mock->runCommand('hr', array());
}
/**
* test that a --help causes help to show.
*
* @return void
*/
function testHelpParamTriggeringHelp() {
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
$Parser->expects($this->once())->method('parse')
->with(array('--help'))
->will($this->returnValue(array(array('help' => true), array())));
$Parser->expects($this->once())->method('help');
$Shell = $this->getMock('Shell', array('_getOptionParser', 'out', 'startup'), array(), '', false);
$Shell->expects($this->once())->method('_getOptionParser')
->will($this->returnValue($Parser));
$Shell->expects($this->once())->method('out');
$Shell->expects($this->once())->method('startup');
$Shell->runCommand(null, array('--help'));
}
}

View file

@ -230,7 +230,6 @@ class ShellDispatcherTest extends CakeTestCase {
);
$expected = array(
'app' => 'new',
'dry' => true,
'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
'webroot' => 'webroot'
@ -256,15 +255,14 @@ class ShellDispatcherTest extends CakeTestCase {
'webroot' => 'webroot',
'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
'dry' => true,
'f' => true,
'name' => 'DbAcl'
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params);
$expected = array('./console/cake.php', 'schema', 'run', 'create');
$expected = array(
'./console/cake.php', 'schema', 'run', 'create', '-dry', '-f', '-name', 'DbAcl'
);
$this->assertEqual($expected, $Dispatcher->args);
$params = array(
@ -283,15 +281,11 @@ class ShellDispatcherTest extends CakeTestCase {
'webroot' => 'webroot',
'working' => '/cake/1.2.x.x/app',
'root' => '/cake/1.2.x.x',
'dry' => true,
'name' => 'DbAcl'
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params);
$expected = array('/cake/1.2.x.x/cake/console/cake.php', 'schema', 'run', 'create');
$this->assertEqual($expected, $Dispatcher->args);
$params = array(
'cake.php',
'-working',
@ -344,7 +338,6 @@ class ShellDispatcherTest extends CakeTestCase {
'webroot' => 'webroot',
'working' => 'C:\wamp\www\apps\cake\app',
'root' => 'C:\wamp\www\apps\cake',
'url' => 'http://example.com/some/url/with/a/path'
);
$Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params);