/**
  * If appropriate, validate command data.
  *
  * @param $command
  */
 protected function validateCommand($command)
 {
     $validator = $this->commandTranslator->toValidator($command);
     if (class_exists($validator)) {
         $this->app->make($validator)->validate($command);
     }
 }
 function it_handles_command_if_validation_succeeds(Application $application, CommandTranslator $translator, CommandBus $bus, ExampleCommand $command, ExampleValidator $validator)
 {
     // Own responsibility
     $translator->toValidator($command)->willReturn(ExampleValidator::class);
     $application->make(ExampleValidator::class)->willReturn($validator);
     // Delegated responsibility
     $bus->execute($command)->shouldBeCalled();
     $this->execute($command);
 }
 function it_can_trigger_decorators_before_calling_the_handler(Application $app, CommandStub $command, CommandTranslator $translator, CommandHandlerStub $handler)
 {
     $translator->toCommandHandler($command)->willReturn('CommandHandler');
     $app->make('CommandHandler')->willReturn($handler);
     $handler->handle($command)->shouldBeCalled();
     // If we specify a decorator before calling execute(), that decorator should be
     // resolved out of the container and executed first.
     $decorator = 'spec\\Laracasts\\Commander\\CommandBusDecoratorStub';
     $app->make($decorator)->shouldBeCalled()->willReturn(new CommandBusDecoratorStub());
     $this->decorate($decorator)->execute($command);
 }
Example #4
0
 /**
  * Execute the command
  *
  * @param $command
  * @return mixed
  */
 public function execute($command)
 {
     $this->executeDecorators($command);
     $handler = $this->commandTranslator->toCommandHandler($command);
     return $this->app->make($handler)->handle($command);
 }