示例#1
0
 /**
  * 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);
     $Shell->expects($this->never())->method('initialize');
     $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 = $this->getMock('Object', $methods);
     $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);
 }
示例#2
0
 /**
  * Verify that a task is called instead of the shell if the first arg equals
  * the name of the task
  *
  * @return void
  * @access public
  */
 function testDispatchTask()
 {
     Mock::generate('Shell', 'MockWeekShell', array('main'));
     Mock::generate('Shell', 'MockOnSundayTask', array('execute'));
     $Dispatcher = new TestShellDispatcher();
     $Shell = new MockWeekShell();
     $Shell->expectOnce('initialize');
     $Shell->expectOnce('loadTasks');
     $Shell->expectNever('startup');
     $Shell->expectNever('main');
     $Task = new MockOnSundayTask();
     $Task->setReturnValue('execute', true);
     $Task->expectOnce('initialize');
     $Task->expectOnce('loadTasks');
     $Task->expectOnce('startup');
     $Task->expectOnce('execute');
     $Shell->MockOnSunday = $Task;
     $Shell->setReturnValue('tasks', array('MockOnSunday'));
     //		$Shell->taskNames = array('MockOnSunday');
     $Dispatcher->TestShell = $Shell;
     $Dispatcher->args = array('mock_week', 'mock_on_sunday');
     $result = $Dispatcher->dispatch();
     $this->assertTrue($result);
     $this->assertEqual($Dispatcher->args, array());
     $Shell = new MockWeekShell();
     $Task = new MockOnSundayTask();
     $Task->expectNever('execute');
     $Task->expectOnce('help');
     $Shell->MockOnSunday = $Task;
     $Shell->setReturnValue('tasks', array('MockOnSunday'));
     //		$Shell->taskNames = array('MockOnSunday');
     $Dispatcher->TestShell = $Shell;
     $Dispatcher->args = array('mock_week', 'mock_on_sunday', 'help');
     $result = $Dispatcher->dispatch();
     $this->assertTrue($result);
 }