コード例 #1
0
 public function testExceptionContainsDebuggingInfo()
 {
     $command = new CompleteTaskCommand();
     $exception = CanNotInvokeHandlerException::forCommand($command, 'Because stuff');
     $this->assertContains('League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand', $exception->getMessage());
     $this->assertContains('Because stuff', $exception->getMessage());
     $this->assertSame($command, $exception->getCommand());
     $this->assertInstanceOf('League\\Tactician\\Exception\\Exception', $exception);
 }
コード例 #2
0
 public function testExceptionContainsDebuggingInfo()
 {
     $command = new CompleteTaskCommand();
     $exception = CanNotInvokeHandlerException::forCommand($command, 'Because stuff');
     $this->assertContains(CompleteTaskCommand::class, $exception->getMessage());
     $this->assertContains('Because stuff', $exception->getMessage());
     $this->assertSame($command, $exception->getCommand());
     $this->assertInstanceOf(Exception::class, $exception);
 }
コード例 #3
0
 /**
  * Executes a command and optionally returns a value
  *
  * @param object   $command
  * @param callable $next
  *
  * @return mixed
  *
  * @throws CanNotInvokeHandlerException
  */
 public function execute($command, callable $next)
 {
     $commandName = $this->commandNameExtractor->extract($command);
     $handler = $this->handlerLocator->getHandlerForCommand($commandName);
     $methodName = $this->methodNameInflector->inflect($command, $handler);
     // is_callable is used here instead of method_exists, as method_exists
     // will fail when given a handler that relies on __call.
     if (!is_callable([$handler, $methodName])) {
         throw CanNotInvokeHandlerException::forCommand($command, "Method '{$methodName}' does not exist on handler");
     }
     return $handler->{$methodName}($command);
 }