public static createForInvalidInstanceType ( Nelmio\Alice\FixtureInterface $fixture, object $instance ) : InstantiationException | ||
$fixture | Nelmio\Alice\FixtureInterface | |
$instance | object | |
Результат | 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()); }
/** * @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; }