コード例 #1
0
 /**
  * @param string $methodName
  * @param array  $arguments
  *
  * @return mixed
  *
  * @throws MethodNotFoundException
  */
 public function dispatch($methodName, array $arguments = [])
 {
     $methodCollection = $this->getMethodCollection();
     $callable = $methodCollection->get($methodName);
     if (!is_callable($callable)) {
         throw new MethodNotFoundException(sprintf('Method "%s" is not found', $methodName));
     }
     $requestObject = $this->argumentMapper->mapToObject($callable, $arguments);
     return $this->methodInvoker->invoke($callable, $requestObject);
 }
コード例 #2
0
 public function it_should_invoke_specified_method(LoaderInterface $loader, ArgumentMapperInterface $argumentMapper, MethodInvokerInterface $methodInvoker, SampleService $sampleService)
 {
     $loader->load()->willReturn(new MethodCollection(['sampleMethod' => [$sampleService->getWrappedObject(), 'sampleMethod']]));
     $argumentMapper->mapToObject([$sampleService, 'sampleMethod'], [1, 2, 3])->willReturn([1, 2, 3])->shouldBeCalled();
     $methodInvoker->invoke([$sampleService->getWrappedObject(), 'sampleMethod'], [1, 2, 3])->willReturn(6)->shouldBeCalled();
     $this->dispatch('sampleMethod', [1, 2, 3])->shouldBe(6);
 }