/** * {@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 testGetConstructorArgsWillReturnTheArgumentsList() { $fixture = new Fixture(self::USER, 'user', array('__construct' => array('create' => array('1', '2', '3'))), null); $this->assertEquals(array('1', '2', '3'), $fixture->getConstructorArgs()); }