public function testToValidator()
 {
     require_once __DIR__ . '/../helpers/TestCommand.php';
     require_once __DIR__ . '/../helpers/TestCommandValidator.php';
     $translator = new CommandTranslator();
     $objectName = $translator->toValidator(new \TestCommand('', ''));
     $this->assertEquals('TestCommandValidator', $objectName);
 }
 /**
  * Execute a command.
  *
  * @param $command
  * @return mixed
  */
 public function execute($command)
 {
     $validator = $this->translator->toValidator($command);
     if (class_exists($validator)) {
         $this->app->make($validator)->validate($command);
     }
     return $this->bus->execute($command);
 }
 public function testExecuteWithDecorator()
 {
     $handler = m::mock('JildertMiedema\\Commander\\CommandHandler');
     $decorator = m::mock('JildertMiedema\\Commander\\CommandBus');
     $this->resolver->shouldReceive('resolve')->with('TestHandler')->andReturn($handler);
     $this->resolver->shouldReceive('resolve')->with('Decorator')->andReturn($decorator);
     $this->translator->shouldReceive('toCommandHandler')->once()->andReturn('TestHandler');
     $handler->shouldReceive('handle')->once()->andReturn('Result');
     $decorator->shouldReceive('execute')->once();
     $this->commandBus->decorate('Decorator');
     $command = m::mock('TestCommand');
     $result = $this->commandBus->execute($command);
     $this->assertEquals('Result', $result);
 }
 public function testExecuteWithDecorator()
 {
     $validator = m::mock('JildertMiedema\\Commander\\ValidationInterface');
     $decorator = m::mock('JildertMiedema\\Commander\\CommandBus');
     $this->resolver->shouldReceive('canResolve')->with('Validator')->andReturn(true);
     $this->resolver->shouldReceive('resolve')->with('Validator')->andReturn($validator);
     $this->resolver->shouldReceive('resolve')->with('Decorator')->andReturn($decorator);
     $this->translator->shouldReceive('toValidator')->once()->andReturn('Validator');
     $validator->shouldReceive('validate')->once()->andReturn(true);
     $this->defaultCommandBus->shouldReceive('execute')->once()->andReturn('Result');
     $decorator->shouldReceive('execute')->once();
     $this->commandBus->decorate('Decorator');
     $command = m::mock('TestCommand');
     $result = $this->commandBus->execute($command);
     $this->assertEquals('Result', $result);
 }
Exemplo n.º 5
0
 /**
  * Execute a command.
  *
  * @param $command
  * @return mixed
  */
 public function execute($command)
 {
     $handler = $this->translator->toHandler($command);
     return $this->app->make($handler)->handle($command);
 }