Пример #1
0
 /**
  * ensures that the property generated for the given fixture is a unique property
  *
  * @param  Fixture            $fixture
  * @param  PropertyDefinition $property
  * @return mixed
  */
 protected function generateUnique(Fixture $fixture, PropertyDefinition $property)
 {
     $class = $fixture->getClass();
     $key = $property->getName();
     $i = $uniqueTriesLimit = 128;
     do {
         // process values
         $value = $this->processor->process($property, $fixture->getSetProperties(), $fixture->getValueForCurrent());
         if (is_object($value)) {
             $valHash = spl_object_hash($value);
         } elseif (is_array($value)) {
             $valHash = hash('md4', serialize($value));
         } else {
             $valHash = $value;
         }
     } while (--$i > 0 && isset($this->uniqueValues[$class . $key][$valHash]));
     if (isset($this->uniqueValues[$class . $key][$valHash])) {
         throw new \RuntimeException("Couldn't generate random unique value for {$class}: {$key} in {$uniqueTriesLimit} tries.");
     }
     $this->uniqueValues[$class . $key][$valHash] = true;
     return $value;
 }
Пример #2
0
 public function testWillParseFlagsOutOfName()
 {
     $definition = new PropertyDefinition('username (unique)', '<username()>');
     $this->assertEquals('username', $definition->getName());
 }