예제 #1
0
 /**
  * Checks an returns the validation object
  * or null otherwise
  * @param ServerRequestInterface $request
  * @return ValidationRulesInterface
  */
 private function getValidatorObject(ServerRequestInterface $request)
 {
     $routeConfig = $this->optionsExtractor->getOptionsForRequest($request);
     if (isset($routeConfig['validation'])) {
         return $this->getValidationObjectForRequest($request, $routeConfig['validation']);
     } else {
         // No associated validation
         return null;
     }
 }
 /**
  * @covers StdLib\Validator\OptionsExtractor::getOptionsForRequest
  */
 public function testGetOptionsForRequest()
 {
     /**
      * Test no options with route match
      */
     $optionExtractor = new OptionsExtractor($this->config, $this->router);
     $optionExtractorEmptyConfig = new OptionsExtractor([], $this->router);
     $this->assertEquals([], $optionExtractorEmptyConfig->getOptionsForRequest($this->getMock(ServerRequestInterface::class)));
     $this->assertEquals([], $optionExtractor->getOptionsForRequest($this->getRequestMock(self::$url)));
     /**
      * Test options exist with route match
      */
     $this->applyValidationConfig();
     $optionExtractor = new OptionsExtractor($this->config, $this->router);
     $this->assertEquals($this->config[0]['options'], $optionExtractor->getOptionsForRequest($this->getRequestMock(self::$url)));
     /**
      * Test options exist no route match
      */
     $this->assertEquals($this->config[0]['options'], $optionExtractor->getOptionsForRequest($this->getRequestMock('')));
 }