/**
  * Test handle method.
  */
 public function testHandle()
 {
     $this->given($resolver = new HandlerClassResolver(new FromClassNameResolver(), new MethodWithShortObjectNameResolver(), new InMemoryLocator([LoginUserMessage::class => new LoginUserMessageListener()])))->and($middleware = new MessageHandlerMiddleware($resolver))->and($command = new LoginUserMessage('*****@*****.**', 'plainpassword'))->and($callable = function (LoginUserMessage $command) {
         $command->setEmail('*****@*****.**');
     })->when($middleware->handle($command, $callable))->then()->string($command->email())->isEqualTo('*****@*****.**')->exception(function () use($middleware, $callable) {
         $middleware->handle(new \StdClass(), $callable);
     })->isInstanceOf(\InvalidArgumentException::class);
 }
Ejemplo n.º 2
0
 /**
  * Test handle method.
  */
 public function testHandle()
 {
     $this->given($middleware = new ValidatorMiddleware())->and($command = new LoginUserMessage('*****@*****.**', 'plainpassword'))->and($callable = function (LoginUserMessage $command) {
         $command->setEmail('*****@*****.**');
     })->when($middleware->handle($command, $callable))->then()->string($command->email())->isEqualTo('*****@*****.**');
     $this->given($middleware = new ValidatorMiddleware())->and($command = new LoginUserMessage('invalid.email.com', 'plainpassword'))->and($callable = function () {
     })->then()->exception(function () use($middleware, $command, $callable) {
         $middleware->handle($command, $callable);
     })->isInstanceOf(ValidationException::class);
     $this->given($middleware = new ValidatorMiddleware())->and($command = new LogoutUserMessage('invalid.email.com'))->and($callable = function (LogoutUserMessage $command) {
         $command->setEmail('*****@*****.**');
     })->when($middleware->handle($command, $callable))->then()->string($command->email())->isEqualTo('*****@*****.**');
 }
Ejemplo n.º 3
0
 /**
  * Test handle method.
  */
 public function testHandleMessage()
 {
     $this->given($middleware = new LockingMiddleware())->and($event = new LoginUserMessage('*****@*****.**'))->and($callable = function (LoginUserMessage $event) {
         $event->setEmail('*****@*****.**');
     })->when($middleware->handle($event, $callable))->then()->string($event->email())->isEqualTo('*****@*****.**');
     $this->given($middleware = new LockingMiddleware())->and($event = new LoginUserMessage('*****@*****.**'))->and($callable = function (LoginUserMessage $event) {
         $event->setEmail('*****@*****.**');
         throw new \InvalidArgumentException();
     })->then()->exception(function () use($middleware, $event, $callable) {
         $middleware->handle($event, $callable);
     })->isInstanceOf(\InvalidArgumentException::class);
     $this->given($middleware = new LockingMiddleware())->and($callable = function (LoginUserMessage $event) {
         $event->setEmail(md5($event->email()));
     })->and($listener = new TriggerMessageOnListener($middleware, $callable))->and($event = new LoginUserMessage('*****@*****.**'))->when($middleware->handle($event, function ($event) use($listener) {
         $listener->onLogin($event);
     }))->then()->string($event->email())->isEqualTo(md5(sha1('*****@*****.**')));
 }