/** * If appropriate, validate query data. * * @param $query */ protected function validateQuery($query) { $validator = $this->queryTranslator->toValidator($query); if (class_exists($validator)) { $this->app->make($validator)->validate($query); } }
function it_handles_command_if_validation_succeeds(Application $application, QueryTranslator $translator, QueryBus $bus, ExampleQuery $query, ExampleValidator $validator) { // Own responsibility $translator->toValidator($query)->willReturn(ExampleValidator::class); $application->make(ExampleValidator::class)->willReturn($validator); // Delegated responsibility $bus->executeQuery($query)->shouldBeCalled(); $this->executeQuery($query); }