createForInvalidInstanceType() public static method

public static createForInvalidInstanceType ( Nelmio\Alice\FixtureInterface $fixture, object $instance ) : InstantiationException
$fixture Nelmio\Alice\FixtureInterface
$instance object
return InstantiationException
 public function testTestCreateForInvalidInstanceType()
 {
     $exception = InstantiationExceptionFactory::createForInvalidInstanceType(new SimpleFixture('foo', 'Dummy', SpecificationBagFactory::create()), new \stdClass());
     $this->assertEquals('Instantiated fixture was expected to be an instance of "Dummy". Got "stdClass" instead.', $exception->getMessage());
     $this->assertEquals(0, $exception->getCode());
     $this->assertNull($exception->getPrevious());
 }
Exemplo n.º 2
0
 /**
  * @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;
 }