/** * {@inheritDoc} */ public function instantiate(Fixture $fixture) { $class = $fixture->getClass(); $constructorMethod = $fixture->getConstructorMethod(); $constructorArgs = $fixture->getConstructorArgs(); $reflClass = new \ReflectionClass($class); $constructorArgs = $this->processor->process($constructorArgs, array(), $fixture->getValueForCurrent()); foreach ($constructorArgs as $index => $value) { $constructorArgs[$index] = $this->typeHintChecker->check($class, $constructorMethod, $value, $index); } if ($constructorMethod === '__construct') { $instance = $reflClass->newInstanceArgs($constructorArgs); } else { $instance = forward_static_call_array(array($class, $constructorMethod), $constructorArgs); if (!$instance instanceof $class) { throw new \UnexpectedValueException("The static constructor '{$constructorMethod}' for object '{$fixture}' returned an object that is not an instance of '{$class}'"); } } return $instance; }
public function testGetConstructorMethodWillReturnTheMethodName() { $fixture = new Fixture(self::USER, 'user', array('__construct' => array('create' => array('1', '2', '3'))), null); $this->assertEquals('create', $fixture->getConstructorMethod()); }
/** * {@inheritDoc} */ public function canInstantiate(Fixture $fixture) { $reflConstruct = new \ReflectionMethod($fixture->getClass(), '__construct'); return !$reflConstruct->isPublic() && '__construct' === $fixture->getConstructorMethod() || !$fixture->shouldUseConstructor() && !version_compare(PHP_VERSION, '5.4', '<'); }