/** * Verify correct dispatch of custom classes with a main method * * @return void */ public function testDispatchNotAShellWithMain() { $Dispatcher = new TestShellDispatcher(); $methods = get_class_methods('Object'); array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret'); $Shell = $this->getMock('Object', $methods, array(), 'MockWithMainNotAShell'); $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_with_main_not_a'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); $this->assertEquals(array(), $Dispatcher->args); $Shell = new MockWithMainNotAShell($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_with_main_not_a', 'initdb'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); }
/** * Verify correct dispatch of custom classes with a main method * * @return void * @access public */ function testDispatchNotAShellWithMain() { Mock::generate('Object', 'MockWithMainNotAShell', array('main', 'initialize', 'loadTasks', 'startup', '_secret')); $Dispatcher =& new TestShellDispatcher(); $Shell = new MockWithMainNotAShell(); $Shell->setReturnValue('main', true); $Shell->expectNever('initialize'); $Shell->expectNever('loadTasks'); $Shell->expectOnce('startup'); $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_with_main_not_a'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); $this->assertEqual($Dispatcher->args, array()); $Shell = new MockWithMainNotAShell(); $Shell->setReturnValue('main', true); $Shell->expectOnce('startup'); $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_with_main_not_a', 'initdb'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); $this->assertEqual($Dispatcher->args, array('initdb')); $Shell = new MockWithMainNotAShell(); $Shell->setReturnValue('main', true); $Shell->expectOnce('startup'); $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_with_main_not_a', 'hr'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); $this->assertEqual($Dispatcher->args, array('hr')); $Shell = new MockWithMainNotAShell(); $Shell->setReturnValue('main', true); $Shell->expectOnce('startup'); $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_with_main_not_a', 'dispatch'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); $this->assertEqual($Dispatcher->args, array('dispatch')); $Shell = new MockWithMainNotAShell(); $Shell->setReturnValue('main', true); $Shell->expectOnce('startup'); $Shell->expectOnce('main'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_with_main_not_a', 'idontexist'); $result = $Dispatcher->dispatch(); $this->assertTrue($result); $this->assertEqual($Dispatcher->args, array('idontexist')); $Shell = new MockWithMainNotAShell(); $Shell->expectNever('startup'); $Shell->expectNever('main'); $Shell->expectNever('_secret'); $Dispatcher->TestShell =& $Shell; $Dispatcher->args = array('mock_with_main_not_a', '_secret'); $result = $Dispatcher->dispatch(); $this->assertFalse($result); }