Exemplo n.º 1
0
 /**
  * Validate the options passed
  * @throws InvalidOptionException
  */
 protected function validateOptions()
 {
     $optionsPassed = array_keys($this->options);
     //check for invalid options
     $validOptions = array_keys($this->definition->getAvailableFields());
     $unknownOptions = array_diff($optionsPassed, $validOptions);
     if (count($unknownOptions) > 0) {
         throw new InvalidOptionException("Invalid option(s) [" . implode(", ", $unknownOptions) . "] passed for request [{$this->type}]");
     }
     //check for missing options
     $requiredOptions = array_keys($this->definition->getRequiredFields());
     $missingOptions = array_diff($requiredOptions, $optionsPassed);
     if (count($missingOptions) > 0) {
         throw new InvalidOptionException("Missing option(s) [" . implode(", ", $missingOptions) . "] which are required for request [{$this->type}]");
     }
     //validate each field
     foreach ($this->options as $option => $value) {
         $this->validateOption($option, $value);
     }
 }
Exemplo n.º 2
0
 public function testGetRequiredFields()
 {
     $this->assertEquals(["type" => "type", "key" => "string", "domain" => "domain"], $this->instance->getRequiredFields());
 }