/** * @inheritdoc */ protected function createInstance(FixtureInterface $fixture) { try { return (new \ReflectionClass($fixture->getClassName()))->newInstanceWithoutConstructor(); } catch (\ReflectionException $exception) { throw InstantiationExceptionFactory::create($fixture, 0, $exception); } }
public function testTestCreate() { $code = 500; $previous = new \Error(); $exception = InstantiationExceptionFactory::create(new DummyFixture('foo'), $code, $previous); $this->assertEquals('Could not instantiate fixture "foo".', $exception->getMessage()); $this->assertEquals($code, $exception->getCode()); $this->assertSame($previous, $exception->getPrevious()); }
/** * {@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); }