/** * Verify correct dispatch of custom classes without a main method * * @return void */ public function testDispatchNotAShellWithoutMain() { $Dispatcher = new TestShellDispatcher(); $methods = get_class_methods('Object'); array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret'); $Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithoutMainNotAShell'); $Shell->expects($this->never())->method('initialize'); $Shell->expects($this->never())->method('loadTasks'); $Shell->expects($this->once())->method('startup'); $Shell->expects($this->once())->method('main')->will($this->returnValue(true)); $Dispatcher->TestShell = $Shell; $Dispatcher->args = array('mock_without_main_not_a'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); $this->assertEquals(array(), $Dispatcher->args); $Shell = new MockWithoutMainNotAShell($Dispatcher); $this->mockObjects[] = $Shell; $Shell->expects($this->once())->method('initdb')->will($this->returnValue(true)); $Shell->expects($this->once())->method('startup'); $Dispatcher->TestShell = $Shell; $Dispatcher->args = array('mock_without_main_not_a', 'initdb'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); }
/** * Verify correct dispatch of custom classes without a main method * * @return void * @access public */ function testDispatchNotAShellWithoutMain() { Mock::generate('Object', 'MockWithoutMainNotAShell', array('initDb', 'initialize', 'loadTasks', 'startup', '_secret')); $Dispatcher =& new TestShellDispatcher(); $Shell = new MockWithoutMainNotAShell(); $Shell->setReturnValue('initDb', true); $Shell->expectNever('initialize'); $Shell->expectNever('loadTasks'); $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_without_main_not_a'); $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->assertEqual($Dispatcher->args, array()); $Shell = new MockWithoutMainNotAShell(); $Shell->setReturnValue('initDb', true); $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_without_main_not_a', 'hr'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); $Shell = new MockWithoutMainNotAShell(); $Shell->setReturnValue('initDb', true); $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_without_main_not_a', 'dispatch'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); $Shell = new MockWithoutMainNotAShell(); $Shell->expectNever('startup'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_without_main_not_a', 'idontexist'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); $Shell = new MockWithoutMainNotAShell(); $Shell->expectNever('startup'); $Shell->expectNever('_secret'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_without_main_not_a', '_secret'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); }