Esempio n. 1
0
 /**
  * Creates a new instance which will no longer contain the given object.
  *
  * @param FixtureInterface|ObjectInterface $objectOrFixture
  *
  * @return self
  */
 public function without($objectOrFixture) : self
 {
     $clone = clone $this;
     unset($clone->objects[$objectOrFixture->getId()]);
     unset($clone->array[$objectOrFixture->getId()]);
     return $clone;
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function hydrate(ObjectInterface $object, ResolvedFixtureSet $fixtureSet, GenerationContext $context) : ResolvedFixtureSet
 {
     if (null === $this->resolver) {
         throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__);
     }
     $fixture = $fixtureSet->getFixtures()->get($object->getId());
     $properties = $fixture->getSpecs()->getProperties();
     $scope = ['_instances' => $fixtureSet->getObjects()->toArray()];
     foreach ($properties as $property) {
         /** @var Property $property */
         $propertyValue = $property->getValue();
         if ($propertyValue instanceof ValueInterface) {
             try {
                 $result = $this->resolver->resolve($propertyValue, $fixture, $fixtureSet, $scope, $context);
             } catch (ResolutionThrowable $throwable) {
                 throw UnresolvableValueDuringGenerationExceptionFactory::createFromResolutionThrowable($throwable);
             }
             list($propertyValue, $fixtureSet) = [$result->getValue(), $result->getSet()];
             $property = $property->withValue($propertyValue);
         }
         $scope[$property->getName()] = $propertyValue;
         $object = $this->hydrator->hydrate($object, $property, $context);
     }
     return $fixtureSet->withObjects($fixtureSet->getObjects()->with($object));
 }
 /**
  * {@inheritdoc}
  *
  * @throws NoSuchPropertyException
  * @throws InaccessiblePropertyException
  * @throws InvalidArgumentException When the typehint does not match for example
  * @throws HydrationException
  */
 public function hydrate(ObjectInterface $object, Property $property, GenerationContext $context) : ObjectInterface
 {
     $instance = $object->getInstance();
     try {
         $this->propertyAccessor->setValue($instance, $property->getName(), $property->getValue());
     } catch (SymfonyNoSuchPropertyException $exception) {
         throw HydrationExceptionFactory::createForCouldNotHydrateObjectWithProperty($object, $property, 0, $exception);
     } catch (SymfonyAccessException $exception) {
         throw HydrationExceptionFactory::createForInaccessibleProperty($object, $property, 0, $exception);
     } catch (SymfonyInvalidArgumentException $exception) {
         throw HydrationExceptionFactory::createForInvalidProperty($object, $property, 0, $exception);
     } catch (SymfonyPropertyAccessException $exception) {
         throw HydrationExceptionFactory::create($object, $property, 0, $exception);
     }
     return new SimpleObject($object->getId(), $instance);
 }
Esempio n. 4
0
 /**
  * @inheritdoc
  */
 public function getInstance()
 {
     return $this->object->getInstance();
 }
Esempio n. 5
0
 public static function createForCouldNotHydrateObjectWithProperty(ObjectInterface $object, Property $property, int $code = 0, \Throwable $previous = null) : NoSuchPropertyException
 {
     return new NoSuchPropertyException(sprintf('Could not hydrate the property "%s" of the object "%s" (class: %s).', $property->getName(), $object->getId(), get_class($object->getInstance())), $code, $previous);
 }