Updating ShellDispatcher test case to use PHPUnit mock objects.

This commit is contained in:
mark_story 2010-05-22 13:10:01 -04:00
parent 326f33f9c6
commit 1c36c1f088

View file

@ -191,7 +191,7 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testParseParams() { public function testParseParams() {
$Dispatcher =& new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$params = array( $params = array(
'/cake/1.2.x.x/cake/console/cake.php', '/cake/1.2.x.x/cake/console/cake.php',
@ -285,14 +285,14 @@ class ShellDispatcherTest extends CakeTestCase {
); );
$expected = array( $expected = array(
'app' => 'new', 'app' => 'new',
'webroot' => 'webroot', 'dry' => true,
'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'), 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH), 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
'dry' => 1 'webroot' => 'webroot'
); );
$Dispatcher->params = $Dispatcher->args = array(); $Dispatcher->params = $Dispatcher->args = array();
$Dispatcher->parseParams($params); $Dispatcher->parseParams($params);
$this->assertEqual($expected, $Dispatcher->params); $this->assertEquals($expected, $Dispatcher->params);
$params = array( $params = array(
'./console/cake.php', './console/cake.php',
@ -311,8 +311,8 @@ class ShellDispatcherTest extends CakeTestCase {
'webroot' => 'webroot', 'webroot' => 'webroot',
'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'), 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH), 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
'dry' => 1, 'dry' => true,
'f' => 1, 'f' => true,
'name' => 'DbAcl' 'name' => 'DbAcl'
); );
$Dispatcher->params = $Dispatcher->args = array(); $Dispatcher->params = $Dispatcher->args = array();
@ -338,7 +338,7 @@ class ShellDispatcherTest extends CakeTestCase {
'webroot' => 'webroot', 'webroot' => 'webroot',
'working' => '/cake/1.2.x.x/app', 'working' => '/cake/1.2.x.x/app',
'root' => '/cake/1.2.x.x', 'root' => '/cake/1.2.x.x',
'dry' => 1, 'dry' => true,
'name' => 'DbAcl' 'name' => 'DbAcl'
); );
$Dispatcher->params = $Dispatcher->args = array(); $Dispatcher->params = $Dispatcher->args = array();
@ -449,7 +449,7 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testBuildPaths() { public function testBuildPaths() {
$Dispatcher =& new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$result = $Dispatcher->shellPaths; $result = $Dispatcher->shellPaths;
@ -474,7 +474,7 @@ class ShellDispatcherTest extends CakeTestCase {
$this->skipIf(class_exists('SampleShell'), '%s SampleShell Class already loaded'); $this->skipIf(class_exists('SampleShell'), '%s SampleShell Class already loaded');
$this->skipIf(class_exists('ExampleShell'), '%s ExampleShell Class already loaded'); $this->skipIf(class_exists('ExampleShell'), '%s ExampleShell Class already loaded');
$Dispatcher =& new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$Dispatcher->shell = 'sample'; $Dispatcher->shell = 'sample';
$Dispatcher->shellName = 'Sample'; $Dispatcher->shellName = 'Sample';
@ -483,7 +483,7 @@ class ShellDispatcherTest extends CakeTestCase {
$result = $Dispatcher->getShell(); $result = $Dispatcher->getShell();
$this->assertIsA($result, 'SampleShell'); $this->assertIsA($result, 'SampleShell');
$Dispatcher =& new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$Dispatcher->shell = 'example'; $Dispatcher->shell = 'example';
$Dispatcher->shellName = 'Example'; $Dispatcher->shellName = 'Example';
@ -499,84 +499,86 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testDispatchShellWithMain() { public function testDispatchShellWithMain() {
Mock::generate('Shell', 'MockWithMainShell', array('main', '_secret')); $Dispatcher = new TestShellDispatcher();
$methods = get_class_methods('Shell');
array_push($methods, 'main', '_secret');
$Mock = $this->getMock('Shell', $methods, array(&$Dispatcher), 'MockWithMainShell');
$Dispatcher =& new TestShellDispatcher(); $Mock->expects($this->once())->method('main')->will($this->returnValue(true));
$Mock->expects($this->once())->method('initialize');
$Shell = new MockWithMainShell(); $Mock->expects($this->once())->method('loadTasks');
$Shell->setReturnValue('main', true); $Mock->expects($this->once())->method('startup');
$Shell->expectOnce('initialize'); $Dispatcher->TestShell = $Mock;
$Shell->expectOnce('loadTasks');
$Shell->expectOnce('startup');
$Shell->expectOnce('main');
$Dispatcher->TestShell =& $Shell;
$Dispatcher->args = array('mock_with_main'); $Dispatcher->args = array('mock_with_main');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array()); $this->assertEqual($Dispatcher->args, array());
$Shell = new MockWithMainShell(); $Shell = new MockWithMainShell($Dispatcher);
$Shell->setReturnValue('main', true); $this->mockObjects[] = $Shell;
$Shell->expectOnce('startup'); $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expectOnce('main'); $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main', 'initdb'); $Dispatcher->args = array('mock_with_main', 'initdb');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('initdb')); $this->assertEqual($Dispatcher->args, array('initdb'));
$Shell = new MockWithMainShell(); $Shell = new MockWithMainShell($Dispatcher);
$Shell->setReturnValue('main', true); $this->mockObjects[] = $Shell;
$Shell->expectOnce('startup'); $Shell->expects($this->once())->method('startup');
$Shell->expectOnce('help'); $Shell->expects($this->once())->method('help');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main', 'help'); $Dispatcher->args = array('mock_with_main', 'help');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertNull($result); $this->assertNull($result);
$this->assertEqual($Dispatcher->args, array()); $this->assertEqual($Dispatcher->args, array());
$Shell = new MockWithMainShell(); $Shell = new MockWithMainShell($Dispatcher);
$Shell->setReturnValue('main', true); $this->mockObjects[] = $Shell;
$Shell->expectNever('hr');
$Shell->expectOnce('startup'); $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expectOnce('main'); $Shell->expects($this->never())->method('hr');
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->once())->method('startup');
$Shell->expects($this->once())->method('main');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main', 'hr'); $Dispatcher->args = array('mock_with_main', 'hr');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('hr')); $this->assertEqual($Dispatcher->args, array('hr'));
$Shell = new MockWithMainShell(); $Shell = new MockWithMainShell($Dispatcher);
$Shell->setReturnValue('main', true); $this->mockObjects[] = $Shell;
$Shell->expectOnce('startup'); $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expectOnce('main'); $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main', 'dispatch'); $Dispatcher->args = array('mock_with_main', 'dispatch');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('dispatch')); $this->assertEqual($Dispatcher->args, array('dispatch'));
$Shell = new MockWithMainShell(); $Shell = new MockWithMainShell($Dispather);
$Shell->setReturnValue('main', true); $this->mockObjects[] = $Shell;
$Shell->expectOnce('startup'); $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expectOnce('main'); $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main', 'idontexist'); $Dispatcher->args = array('mock_with_main', 'idontexist');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('idontexist')); $this->assertEqual($Dispatcher->args, array('idontexist'));
$Shell = new MockWithMainShell(); $Shell = new MockWithMainShell($Dispather);
$Shell->expectNever('startup'); $this->mockObjects[] = $Shell;
$Shell->expectNever('main'); $Shell->expects($this->never())->method('main');
$Shell->expectNever('_secret'); $Shell->expects($this->never())->method('startup');
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->never())->method('_secret');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main', '_secret'); $Dispatcher->args = array('mock_with_main', '_secret');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
@ -589,65 +591,69 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testDispatchShellWithoutMain() { public function testDispatchShellWithoutMain() {
Mock::generate('Shell', 'MockWithoutMainShell', array('initDb', '_secret')); $Dispatcher = new TestShellDispatcher();
$methods = get_class_methods('Shell');
array_push($methods, 'initDb', '_secret');
$Shell = $this->getMock('Shell', $methods, array(&$Dispatcher), 'MockWithoutMainShell');
$Dispatcher =& new TestShellDispatcher(); $Shell->expects($this->once())->method('initialize');
$Shell->expects($this->once())->method('loadTasks');
$Shell = new MockWithoutMainShell(); $Shell->expects($this->never())->method('startup');
$Shell->setReturnValue('initDb', true); $Dispatcher->TestShell = $Shell;
$Shell->expectOnce('initialize');
$Shell->expectOnce('loadTasks');
$Shell->expectNever('startup');
$Dispatcher->TestShell =& $Shell;
$Dispatcher->args = array('mock_without_main'); $Dispatcher->args = array('mock_without_main');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertFalse($result);
$this->assertEqual($Dispatcher->args, array()); $this->assertEqual($Dispatcher->args, array());
$Shell = new MockWithoutMainShell();
$Shell->setReturnValue('initDb', true); $Shell = new MockWithoutMainShell($Dispather);
$Shell->expectOnce('startup'); $this->mockObjects[] = $Shell;
$Shell->expectOnce('initDb'); $Shell->expects($this->once())->method('initDb')->will($this->returnValue(true));
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->once())->method('initialize');
$Shell->expects($this->once())->method('loadTasks');
$Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main', 'initdb'); $Dispatcher->args = array('mock_without_main', 'initdb');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array()); $this->assertEqual($Dispatcher->args, array());
$Shell = new MockWithoutMainShell(); $Shell = new MockWithoutMainShell($Dispather);
$Shell->setReturnValue('initDb', true); $this->mockObjects[] = $Shell;
$Shell->expectNever('startup'); $Shell->expects($this->never())->method('hr');
$Shell->expectNever('hr'); $Shell->expects($this->never())->method('startup');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main', 'hr'); $Dispatcher->args = array('mock_without_main', 'hr');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertFalse($result);
$this->assertEqual($Dispatcher->args, array('hr')); $this->assertEqual($Dispatcher->args, array('hr'));
$Shell = new MockWithoutMainShell(); $Shell = new MockWithoutMainShell($Dispather);
$Shell->setReturnValue('initDb', true); $this->mockObjects[] = $Shell;
$Shell->expectNever('startup'); $Shell->expects($this->never())->method('startup');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main', 'dispatch'); $Dispatcher->args = array('mock_without_main', 'dispatch');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertFalse($result);
$Shell = new MockWithoutMainShell(); $Shell = new MockWithoutMainShell($Dispather);
$Shell->expectNever('startup'); $this->mockObjects[] = $Shell;
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->never())->method('startup');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main', 'idontexist'); $Dispatcher->args = array('mock_without_main', 'idontexist');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertFalse($result);
$Shell = new MockWithoutMainShell(); $Shell = new MockWithoutMainShell($Dispather);
$Shell->expectNever('startup'); $this->mockObjects[] = $Shell;
$Shell->expectNever('_secret'); $Shell->expects($this->never())->method('startup');
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->never())->method('_secret');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main', '_secret'); $Dispatcher->args = array('mock_without_main', '_secret');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
@ -660,73 +666,72 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testDispatchNotAShellWithMain() { public function testDispatchNotAShellWithMain() {
Mock::generate('Object', 'MockWithMainNotAShell', $Dispatcher = new TestShellDispatcher();
array('main', 'initialize', 'loadTasks', 'startup', '_secret')); $methods = get_class_methods('Object');
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
$Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithMainNotAShell');
$Dispatcher =& new TestShellDispatcher(); $Shell->expects($this->never())->method('initialize');
$Shell->expects($this->never())->method('loadTasks');
$Shell = new MockWithMainNotAShell(); $Shell->expects($this->once())->method('startup');
$Shell->setReturnValue('main', true); $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expectNever('initialize'); $Dispatcher->TestShell = $Shell;
$Shell->expectNever('loadTasks');
$Shell->expectOnce('startup');
$Shell->expectOnce('main');
$Dispatcher->TestShell =& $Shell;
$Dispatcher->args = array('mock_with_main_not_a'); $Dispatcher->args = array('mock_with_main_not_a');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array()); $this->assertEqual($Dispatcher->args, array());
$Shell = new MockWithMainNotAShell(); $Shell = new MockWithMainNotAShell($Dispatcher);
$Shell->setReturnValue('main', true); $this->mockObjects[] = $Shell;
$Shell->expectOnce('startup'); $Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
$Shell->expectOnce('main'); $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main_not_a', 'initdb'); $Dispatcher->args = array('mock_with_main_not_a', 'initdb');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('initdb'));
$Shell = new MockWithMainNotAShell(); $Shell = new MockWithMainNotAShell($Dispatcher);
$Shell->setReturnValue('main', true); $this->mockObjects[] = $Shell;
$Shell->expectOnce('startup'); $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expectOnce('main'); $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main_not_a', 'hr'); $Dispatcher->args = array('mock_with_main_not_a', 'hr');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('hr')); $this->assertEqual($Dispatcher->args, array('hr'));
$Shell = new MockWithMainNotAShell();
$Shell->setReturnValue('main', true); $Shell = new MockWithMainNotAShell($Dispatcher);
$Shell->expectOnce('startup'); $this->mockObjects[] = $Shell;
$Shell->expectOnce('main'); $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main_not_a', 'dispatch'); $Dispatcher->args = array('mock_with_main_not_a', 'dispatch');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('dispatch')); $this->assertEqual($Dispatcher->args, array('dispatch'));
$Shell = new MockWithMainNotAShell(); $Shell = new MockWithMainNotAShell($Dispatcher);
$Shell->setReturnValue('main', true); $this->mockObjects[] = $Shell;
$Shell->expectOnce('startup'); $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expectOnce('main'); $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main_not_a', 'idontexist'); $Dispatcher->args = array('mock_with_main_not_a', 'idontexist');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('idontexist')); $this->assertEqual($Dispatcher->args, array('idontexist'));
$Shell = new MockWithMainNotAShell(); $Shell = new MockWithMainNotAShell($Dispatcher);
$Shell->expectNever('startup'); $this->mockObjects[] = $Shell;
$Shell->expectNever('main'); $Shell->expects($this->never())->method('_secret');
$Shell->expectNever('_secret'); $Shell->expects($this->never())->method('main');
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->never())->method('startup');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_with_main_not_a', '_secret'); $Dispatcher->args = array('mock_with_main_not_a', '_secret');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
@ -739,63 +744,72 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testDispatchNotAShellWithoutMain() { public function testDispatchNotAShellWithoutMain() {
Mock::generate('Object', 'MockWithoutMainNotAShell', $Dispatcher = new TestShellDispatcher();
array('initDb', 'initialize', 'loadTasks', 'startup', '_secret')); $methods = get_class_methods('Object');
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
$Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithoutMainNotAShell');
$Dispatcher =& new TestShellDispatcher(); $Shell->expects($this->never())->method('initialize');
$Shell->expects($this->never())->method('loadTasks');
$Shell = new MockWithoutMainNotAShell(); $Shell->expects($this->once())->method('startup');
$Shell->setReturnValue('initDb', true); $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expectNever('initialize'); $Dispatcher->TestShell = $Shell;
$Shell->expectNever('loadTasks');
$Shell->expectNever('startup');
$Dispatcher->TestShell =& $Shell;
$Dispatcher->args = array('mock_without_main_not_a'); $Dispatcher->args = array('mock_without_main_not_a');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result);
$Shell = new MockWithoutMainNotAShell();
$Shell->setReturnValue('initDb', true);
$Shell->expectOnce('startup');
$Shell->expectOnce('initDb');
$Dispatcher->TestShell =& $Shell;
$Dispatcher->args = array('mock_without_main_not_a', 'initdb');
$result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array()); $this->assertEqual($Dispatcher->args, array());
$Shell = new MockWithoutMainNotAShell(); $Shell = new MockWithoutMainNotAShell($Dispatcher);
$Shell->setReturnValue('initDb', true); $this->mockObjects[] = $Shell;
$Shell->expectNever('startup'); $Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main_not_a', 'initdb');
$result = $Dispatcher->dispatch();
$this->assertTrue($result);
$Shell = new MockWithoutMainNotAShell($Dispatcher);
$this->mockObjects[] = $Shell;
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main_not_a', 'hr'); $Dispatcher->args = array('mock_without_main_not_a', 'hr');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('hr'));
$Shell = new MockWithoutMainNotAShell();
$Shell->setReturnValue('initDb', true); $Shell = new MockWithoutMainNotAShell($Dispatcher);
$Shell->expectNever('startup'); $this->mockObjects[] = $Shell;
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main_not_a', 'dispatch'); $Dispatcher->args = array('mock_without_main_not_a', 'dispatch');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('dispatch'));
$Shell = new MockWithoutMainNotAShell(); $Shell = new MockWithoutMainNotAShell($Dispatcher);
$Shell->expectNever('startup'); $this->mockObjects[] = $Shell;
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->once())->method('main')->will($this->returnValue(true));
$Shell->expects($this->once())->method('startup');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main_not_a', 'idontexist'); $Dispatcher->args = array('mock_without_main_not_a', 'idontexist');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertFalse($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array('idontexist'));
$Shell = new MockWithoutMainNotAShell(); $Shell = new MockWithoutMainNotAShell($Dispatcher);
$Shell->expectNever('startup'); $this->mockObjects[] = $Shell;
$Shell->expectNever('_secret'); $Shell->expects($this->never())->method('_secret');
$Dispatcher->TestShell =& $Shell; $Shell->expects($this->never())->method('main');
$Shell->expects($this->never())->method('startup');
$Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_without_main_not_a', '_secret'); $Dispatcher->args = array('mock_without_main_not_a', '_secret');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
@ -809,41 +823,48 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testDispatchTask() { public function testDispatchTask() {
Mock::generate('Shell', 'MockWeekShell', array('main')); $Dispatcher = new TestShellDispatcher();
Mock::generate('Shell', 'MockOnSundayTask', array('execute')); $mainMethods = $executeMethods = get_class_methods('Shell');
array_push($mainMethods, 'main');
array_push($executeMethods, 'execute');
$Dispatcher =& new TestShellDispatcher(); $Week = $this->getMock('Shell', $mainMethods, array(&$Dispatcher), 'MockWeekShell');
$Sunday = $this->getMock('Shell', $executeMethods, array(&$Dispatcher), 'MockOnSundayTask');
$Shell = new MockWeekShell(); $Shell = new MockWeekShell($Dispather);
$Shell->expectOnce('initialize'); $this->mockObjects[] = $Shell;
$Shell->expectOnce('loadTasks'); $Shell->expects($this->once())->method('initialize');
$Shell->expectNever('startup'); $Shell->expects($this->once())->method('loadTasks');
$Shell->expectNever('main'); $Shell->expects($this->never())->method('startup');
$Shell->expects($this->never())->method('main');
$Task = new MockOnSundayTask(); $Task = new MockOnSundayTask($Dispatcher);
$Task->setReturnValue('execute', true); $this->mockObjects[] = $Task;
$Task->expectOnce('initialize'); $Task->expects($this->once())->method('execute')->will($this->returnValue(true));
$Task->expectOnce('loadTasks'); $Task->expects($this->once())->method('initialize');;
$Task->expectOnce('startup'); $Task->expects($this->once())->method('loadTasks');
$Task->expectOnce('execute'); $Task->expects($this->once())->method('startup');
$Task->expects($this->once())->method('execute');
$Shell->MockOnSunday =& $Task; $Shell->MockOnSunday = $Task;
$Shell->taskNames = array('MockOnSunday'); $Shell->taskNames = array('MockOnSunday');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_week', 'mock_on_sunday'); $Dispatcher->args = array('mock_week', 'mock_on_sunday');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEqual($Dispatcher->args, array()); $this->assertEqual($Dispatcher->args, array());
$Shell = new MockWeekShell(); $Shell = new MockWeekShell($Dispatcher);
$Task = new MockOnSundayTask(); $Task = new MockOnSundayTask($Dispatcher);
$Task->expectNever('execute'); array_push($this->mockObjects, $Shell, $Task);
$Task->expectOnce('help');
$Shell->MockOnSunday =& $Task; $Task->expects($this->never())->method('execute');
$Task->expects($this->once())->method('help');
$Shell->MockOnSunday = $Task;
$Shell->taskNames = array('MockOnSunday'); $Shell->taskNames = array('MockOnSunday');
$Dispatcher->TestShell =& $Shell; $Dispatcher->TestShell = $Shell;
$Dispatcher->args = array('mock_week', 'mock_on_sunday', 'help'); $Dispatcher->args = array('mock_week', 'mock_on_sunday', 'help');
$result = $Dispatcher->dispatch(); $result = $Dispatcher->dispatch();
@ -856,7 +877,7 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testShiftArgs() { public function testShiftArgs() {
$Dispatcher =& new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$Dispatcher->args = array('a', 'b', 'c'); $Dispatcher->args = array('a', 'b', 'c');
$this->assertEqual($Dispatcher->shiftArgs(), 'a'); $this->assertEqual($Dispatcher->shiftArgs(), 'a');
@ -885,7 +906,7 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testHelpCommand() { public function testHelpCommand() {
$Dispatcher =& new TestShellDispatcher(); $Dispatcher = new TestShellDispatcher();
$expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/"; $expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
$this->assertPattern($expected, $Dispatcher->stdout); $this->assertPattern($expected, $Dispatcher->stdout);