예제 #1
0
 /**
  * @return ValidationGroups
  */
 public function parse()
 {
     $validationGroups = new ValidationGroups();
     foreach (array_keys($this->configuration) as $group) {
         $validationGroups->add($group, $this->parseConstraints($this->configuration[$group]));
     }
     return $validationGroups;
 }
예제 #2
0
 /**
  * @return ValidationGroups
  */
 public function parse()
 {
     if (strtolower($this->file['extension']) != 'yml') {
         throw new InvalidFileTypeException("Extension '{$this->file['extension']}' is not allowed");
     }
     $constraints = array();
     $configuration = \Symfony\Component\Yaml\Yaml::parse($this->file['dirname'] . '/' . $this->file['basename']);
     $groups = array_keys($configuration);
     foreach ($groups as $group) {
         foreach ($configuration[$group] as $property => $string) {
             $constraints[$group][$property] = $this->parseString($string);
         }
     }
     $validationGroups = new ValidationGroups();
     foreach (array_keys($configuration) as $group) {
         $validationGroups->add($group, $this->parseConstraints($constraints[$group]));
     }
     return $validationGroups;
 }
 public function testValidationGroupsMethods()
 {
     $constraintsCollection = new ConstraintsCollection();
     $constraintsCollection->set('name', v::maxLength(50));
     $constraintsCollection->set('email', v::email()->maxLength(50));
     $validationGroups = new ValidationGroups();
     $validationGroups->add("registering", $constraintsCollection);
     $this->assertTrue($validationGroups->has("registering"));
     $this->assertInstanceOf('Melody\\Validation\\Common\\Collections\\ConstraintsCollection', $validationGroups->get("registering"));
     $validationGroups->remove("registering");
     $this->assertFalse($validationGroups->has("registering"));
     $this->setExpectedException('InvalidArgumentException');
     $this->assertInstanceOf('InvalidArgumentException', $validationGroups->get("registering"));
 }