/** * @param FixtureInterface $fixture * @param ResolvedFixtureSet $set * @param GenerationContext $context * * @throws UnresolvableValueDuringGenerationException * * @return array */ private function resolveFixtureConstructor(FixtureInterface $fixture, ResolvedFixtureSet $set, GenerationContext $context) : array { $specs = $fixture->getSpecs(); $constructor = $specs->getConstructor(); if (null === $constructor || $constructor instanceof NoMethodCall) { return [$fixture, $set]; } if (null === $this->valueResolver) { throw ResolverNotFoundExceptionFactory::createUnexpectedCall(__METHOD__); } list($resolvedArguments, $set) = $this->resolveArguments($constructor->getArguments(), $this->valueResolver, $fixture, $set, $context); return [$fixture->withSpecs($specs->withConstructor($constructor->withArguments($resolvedArguments))), $set]; }
/** * @inheritdoc */ protected function createInstance(FixtureInterface $fixture) { $constructor = $fixture->getSpecs()->getConstructor(); list($class, $factory, $method, $arguments) = [$fixture->getClassName(), $constructor->getCaller()->getId(), $constructor->getMethod(), $constructor->getArguments()]; if (null === $arguments) { $arguments = []; } $instance = $factory::$method(...$arguments); if (false === $instance instanceof $class) { throw InstantiationExceptionFactory::createForInvalidInstanceType($fixture, $instance); } return $instance; }
/** * @inheritDoc */ public function canInstantiate(FixtureInterface $fixture) : bool { return $fixture->getSpecs()->getConstructor() instanceof NoMethodCall; }
/** * @inheritdoc */ public function getSpecs() : SpecificationBag { return $this->fixture->getSpecs(); }
/** * @inheritdoc */ public function canInstantiate(FixtureInterface $fixture) : bool { return null === $fixture->getSpecs()->getConstructor(); }
private function isObjectComplete(FixtureInterface $fixture, ObjectInterface $object, GenerationContext $context) : bool { return $object instanceof CompleteObject || $context->needsCompleteGeneration() || false === $context->isFirstPass() || false === $context->needsCompleteGeneration() && $fixture->getSpecs()->getProperties()->isEmpty() && $fixture->getSpecs()->getMethodCalls()->isEmpty(); }
/** * @inheritdoc */ protected function createInstance(FixtureInterface $fixture) { list($class, $arguments) = [$fixture->getClassName(), $fixture->getSpecs()->getConstructor()->getArguments()]; return new $class(...$arguments); }