/**
  * Test handle method.
  */
 public function testHandle()
 {
     $this->given($resolver = new HandlerClassResolver(new FromQueryNamedResolver(), new MethodWithShortObjectNameResolver('Query'), new InMemoryLocator()))->and($middleware = new QueryHandlerMiddleware($resolver))->and($query = new NearByVenuesQuery($this->faker->latitude(), $this->faker->longitude()))->and($queryHandler = new VenuesQueryHandler())->and($resolver->addHandler($query->named(), $queryHandler))->and($callable = function (array $result) {
         return json_encode($result);
     })->when($result = $middleware->handle($query, $callable))->then()->string($result)->isNotEmpty()->isEqualTo(json_encode($queryHandler->aroundVenues($query)))->exception(function () use($middleware, $callable) {
         $middleware->handle(new \StdClass(), $callable);
     })->isInstanceOf(\InvalidArgumentException::class);
 }
Exemplo n.º 2
0
 /**
  * Test Resolve method.
  */
 public function testResolve()
 {
     $this->given($resolver = new HandlerClassResolver(new FromClassNameResolver(), new MethodWithShortObjectNameResolver('Message'), new InMemoryLocator([])))->and($resolver->addHandler(LoginUserMessage::class, new LoginUserMessageListener()))->when($result = $resolver->resolve(new LoginUserMessage('*****@*****.**')))->then()->object($result)->isInstanceOf(Delegate::class);
     $this->given($resolver = new HandlerClassResolver(new FromClassNameResolver(), new MethodWithShortObjectNameResolver('Message'), new InMemoryLocator([])))->and($resolver->addHandler(LoginUserMessage::class, new LoginUserMessageListener()))->then()->exception(function () use($resolver) {
         $resolver->resolve(new LogoutUserMessage('*****@*****.**'));
     })->isInstanceOf(NotFoundException::class);
     $this->given($resolver = new HandlerClassResolver(new FromClassNameResolver(), new MethodWithShortObjectNameResolver('Command'), new InMemoryLocator([LoginUserMessage::class => new LoginUserMessageListener()])))->then()->exception(function () use($resolver) {
         $resolver->resolve(new LoginUserMessage('*****@*****.**'));
     })->isInstanceOf(NotFoundException::class);
 }