public function testTestCreateForInstantiatorNotFoundForFixture() { $exception = InstantiationExceptionFactory::createForInstantiatorNotFoundForFixture(new DummyFixture('foo')); $this->assertEquals('No suitable instantiator found for the fixture "foo".', $exception->getMessage()); $this->assertEquals(0, $exception->getCode()); $this->assertNull($exception->getPrevious()); }
/** * @inheritdoc */ protected function createInstance(FixtureInterface $fixture) { try { return (new \ReflectionClass($fixture->getClassName()))->newInstanceWithoutConstructor(); } catch (\ReflectionException $exception) { throw InstantiationExceptionFactory::create($fixture, 0, $exception); } }
/** * @inheritdoc */ public function instantiate(FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, GenerationContext $context) : ResolvedFixtureSet { foreach ($this->instantiators as $instantiator) { if ($instantiator->canInstantiate($fixture)) { return $instantiator->instantiate($fixture, $fixtureSet, $context); } } throw InstantiationExceptionFactory::createForInstantiatorNotFoundForFixture($fixture); }
/** * {@inheritdoc} * * @throws InstantiationException */ public function instantiate(FixtureInterface $fixture, ResolvedFixtureSet $fixtureSet, GenerationContext $context) : ResolvedFixtureSet { try { $instance = $this->createInstance($fixture); } catch (InstantiationThrowable $throwable) { throw $throwable; } catch (\Throwable $throwable) { throw InstantiationExceptionFactory::create($fixture, 0, $throwable); } $objects = $fixtureSet->getObjects()->with(new SimpleObject($fixture->getId(), $instance)); return $fixtureSet->withObjects($objects); }
/** * @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 */ protected function createInstance(FixtureInterface $fixture) { $class = $fixture->getClassName(); try { $constructRefl = new \ReflectionMethod($class, '__construct'); if (false === $constructRefl->isPublic()) { throw InstantiationExceptionFactory::createForNonPublicConstructor($fixture); } if (0 === $constructRefl->getNumberOfRequiredParameters()) { return new $class(); } throw InstantiationExceptionFactory::createForConstructorIsMissingMandatoryParameters($fixture); } catch (\ReflectionException $exception) { // Thrown when __construct does not exist, i.e. is default constructor if (1 !== preg_match('/Method (.+)__construct\\(.*\\) does not exist/', $exception->getMessage())) { throw InstantiationExceptionFactory::createForCouldNotGetConstructorData($fixture, 0, $exception); } // Continue } return new $class(); }