Exemple #1
0
 /**
  * this custom instantiator dumps the given spec
  */
 public function instantiate(Fixture $fixture)
 {
     $class = $fixture->getClass();
     $newObj = new $class();
     $newObj->uuid = uniqid();
     return $newObj;
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  */
 public function set(Fixture $fixture, $object, $property, $value)
 {
     if (!method_exists($object, $fixture->getCustomSetter())) {
         throw new \RuntimeException('Setter ' . $fixture->getCustomSetter() . ' not found in object');
     }
     $customSetter = $fixture->getCustomSetter()->getValue();
     $object->{$customSetter}($property, $value);
 }
 /**
  * {@inheritDoc}
  */
 public function instantiate(Fixture $fixture)
 {
     $tablename = substr($fixture->getClass(), 6);
     $r = new TableRecord($tablename);
     if ($this->auto_uuid_column) {
         $uuid = (string) Uuid::uuid4();
         $r->setR_uuid($uuid);
     }
     return $r;
 }
 /**
  * {@inheritDoc}
  */
 public function instantiate(Fixture $fixture)
 {
     $class = $fixture->getClass();
     $constructorMethod = $fixture->getConstructorMethod();
     $constructorArgs = $fixture->getConstructorArgs();
     $reflClass = new \ReflectionClass($class);
     $constructorArgs = $this->processor->process($constructorArgs, array(), $fixture->getValueForCurrent());
     foreach ($constructorArgs as $index => $value) {
         $constructorArgs[$index] = $this->typeHintChecker->check($class, $constructorMethod, $value, $index);
     }
     if ($constructorMethod === '__construct') {
         $instance = $reflClass->newInstanceArgs($constructorArgs);
     } else {
         $instance = forward_static_call_array(array($class, $constructorMethod), $constructorArgs);
         if (!$instance instanceof $class) {
             throw new \UnexpectedValueException("The static constructor '{$constructorMethod}' for object '{$fixture}' returned an object that is not an instance of '{$class}'");
         }
     }
     return $instance;
 }
Exemple #5
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;
 }
 /**
  * {@inheritDoc}
  */
 public function instantiate(Fixture $fixture)
 {
     $reflClass = new \ReflectionClass($fixture->getClass());
     return $reflClass->newInstanceWithoutConstructor();
 }
Exemple #7
0
 /**
  * extends this fixture by the given template
  *
  * @param Fixture $template
  */
 public function extendTemplate(Fixture $template)
 {
     if (!$template->isTemplate()) {
         throw new \InvalidArgumentException('Argument must be a template, not just a fixture.');
     }
     foreach ($template->properties as $property) {
         if (!isset($this->spec[$property->getName()])) {
             $this->addProperty($property->getName(), $property->getValue());
         }
     }
 }
Exemple #8
0
 /**
  * {@inheritDoc}
  */
 public function instantiate(Fixture $fixture)
 {
     // unserialize hack for php <5.4
     return unserialize(sprintf('O:%d:"%s":0:{}', strlen($fixture->getClass()), $fixture->getClass()));
 }
Exemple #9
0
 /**
  * {@inheritDoc}
  */
 public function instantiate(Fixture $fixture)
 {
     $class = $fixture->getClass();
     return new $class();
 }
Exemple #10
0
 public function canSet(Fixture $fixture, $object, $property, $value)
 {
     return preg_match('/Contact/', $fixture->getClass());
 }
Exemple #11
0
 public function testGetCustomSetterWillReturnTheCustomSetterValue()
 {
     $setFixture = new Fixture(self::USER, 'user', array('__set' => 'setterFunc'), null);
     $noSetFixture = new Fixture(self::USER, 'user', array(), null);
     $this->assertEquals('setterFunc', $setFixture->getCustomSetter());
     $this->assertNull($noSetFixture->getCustomSetter());
 }