public static createForConstructorIsMissingMandatoryParameters ( Nelmio\Alice\FixtureInterface $fixture ) : InstantiationException | ||
$fixture | Nelmio\Alice\FixtureInterface | |
return | InstantiationException |
public function testTestCreateForConstructorIsMissingMandatoryParameters() { $exception = InstantiationExceptionFactory::createForConstructorIsMissingMandatoryParameters(new DummyFixture('foo')); $this->assertEquals('Could not instantiate "foo", the constructor has mandatory parameters but no parameters has been given.', $exception->getMessage()); $this->assertEquals(0, $exception->getCode()); $this->assertNull($exception->getPrevious()); }
/** * @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(); }