createForCouldNotGetConstructorData() public static method

public static createForCouldNotGetConstructorData ( Nelmio\Alice\FixtureInterface $fixture, integer $code, Throwable $previous = null ) : InstantiationException
$fixture Nelmio\Alice\FixtureInterface
$code integer
$previous Throwable
return InstantiationException
 public function testTestCreateForCouldNotGetConstructorData()
 {
     $exception = InstantiationExceptionFactory::createForCouldNotGetConstructorData(new DummyFixture('foo'));
     $this->assertEquals('Could not get the necessary data on the constructor to instantiate "foo".', $exception->getMessage());
     $this->assertEquals(0, $exception->getCode());
     $this->assertNull($exception->getPrevious());
 }
Exemplo n.º 2
0
 /**
  * @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();
 }