public static createForNonPublicConstructor ( Nelmio\Alice\FixtureInterface $fixture ) : InstantiationException | ||
$fixture | Nelmio\Alice\FixtureInterface | |
Результат | InstantiationException |
public function testTestCreateForNonPublicConstructor() { $exception = InstantiationExceptionFactory::createForNonPublicConstructor(new SimpleFixture('foo', 'Dummy', SpecificationBagFactory::create())); $this->assertEquals('Could not instantiate "foo", the constructor of "Dummy" is not public.', $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(); }