create() public static method

public static create ( Nelmio\Alice\FixtureInterface $fixture, integer $code, Throwable $previous ) : InstantiationException
$fixture Nelmio\Alice\FixtureInterface
$code integer
$previous Throwable
return InstantiationException
Ejemplo n.º 1
0
 /**
  * @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());
 }
Ejemplo n.º 3
0
 /**
  * {@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);
 }