/**
  * @covers StdLib\Validator\Validator::validate
  */
 public function testValidateValidationAppliedWithErrors()
 {
     /**
      * Apply the validation to the config
      */
     $this->applyValidationConfig();
     $optionExtractor = $this->getMockBuilder(OptionsExtractor::class)->disableOriginalConstructor()->getMock();
     $entityManagerMock = $this->getMockBuilder(EntityManagerInterface::class)->getMock();
     $validator = new Validator($optionExtractor, $this->router, $entityManagerMock);
     /**
      * @var ValidationResultInterface $validationResult
      */
     $validationResult = $validator->validate($this->createRequest(static::$urlInvalid));
     $exceptionValidator = new ValidationFailedException();
     $exceptionValidator->setValidationResult($validationResult);
     $this->assertEquals($exceptionValidator->getValidationResult(), $validationResult);
 }
 /**
  * Validates the request
  * @param Request $request
  * @param Response $response
  * @param callable|null $out
  * @inheritdoc
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     /**
      * @var ValidationResult $validationResult
      */
     $validationResult = $this->validator->validate($request);
     if (!is_bool($validationResult) && $validationResult->notValid()) {
         $validationException = new ValidationFailedException();
         $validationException->setValidationResult($validationResult);
         throw $validationException;
     } elseif (!is_bool($validationResult)) {
         // Valid
         return $out($validationResult->getRequest(), $response);
     } else {
         return $out($request, $response);
     }
 }
 public function testValidateValidationAppliedWithErrors()
 {
     /**
      * Apply the validation to the config
      */
     $this->applyValidationConfig();
     $router = $this->getMock(FastRouteRouter::class);
     $router->expects($this->any())->method('match')->willReturn(RouteResult::fromRouteMatch($this->config[0]['path'], function () {
     }, []));
     $optionExtractor = new OptionsExtractor($this->config, $router);
     $validator = new Validator($optionExtractor, $router, $this->getEntityManagerMock());
     /**
      * @var ValidationResultInterface $validationResult
      */
     $validationResult = $validator->validate($this->createRequest(static::$urlInvalid));
     /**
      * Should not be valid
      */
     $this->assertInstanceOf(ValidationResultInterface::class, $validationResult);
     $this->assertFalse($validationResult->valid());
     $this->assertTrue($validationResult->notValid());
     $this->assertNotEmpty($validationResult->getMessages());
     $this->assertEmpty($validationResult->getData());
     $this->assertGreaterThan(0, count($validationResult->getMessages()));
     $this->assertContains('Please provide an id for the agreement', $validationResult->getMessages());
 }