getFactoryMethod() public method

public getFactoryMethod ( ) : callable | null
return callable | null
Esempio n. 1
0
 /**
  * @return mixed
  */
 public function duringInstantiation()
 {
     if ($factoryMethod = $this->wrappedObject->getFactoryMethod()) {
         $method = is_array($factoryMethod) ? $factoryMethod[1] : $factoryMethod;
     } else {
         $method = '__construct';
     }
     $instantiator = new Instantiator();
     $object = $instantiator->instantiate($this->wrappedObject->getClassName());
     return $this->runDuring($object, $method, $this->wrappedObject->getArguments());
 }
Esempio n. 2
0
 /**
  * @return mixed
  * @throws \PhpSpec\Exception\Fracture\MethodNotFoundException
  */
 private function newInstanceWithFactoryMethod()
 {
     $method = $this->wrappedObject->getFactoryMethod();
     if (!is_array($method)) {
         $className = $this->wrappedObject->getClassName();
         if (!method_exists($className, $method)) {
             throw $this->namedConstructorNotFound($method, $this->wrappedObject->getArguments());
         }
     }
     return call_user_func_array($method, $this->wrappedObject->getArguments());
 }
Esempio n. 3
0
 function it_delegates_throwing_method_not_found_exception_for_constructor(WrappedObject $wrappedObject, ExceptionFactory $exceptions, \stdClass $argument)
 {
     $obj = new ExampleClass();
     $wrappedObject->isInstantiated()->willReturn(false);
     $wrappedObject->getInstance()->willReturn(null);
     $wrappedObject->getArguments()->willReturn(array($argument));
     $wrappedObject->getClassName()->willReturn('spec\\PhpSpec\\Wrapper\\Subject\\ExampleClass');
     $wrappedObject->getFactoryMethod()->willReturn(null);
     $exceptions->methodNotFound('spec\\PhpSpec\\Wrapper\\Subject\\ExampleClass', '__construct', array($argument))->willReturn(new \PhpSpec\Exception\Fracture\MethodNotFoundException('Method "__construct" not found.', $obj, '"ExampleClass::__construct"', array()))->shouldBeCalled();
     $this->shouldThrow('\\PhpSpec\\Exception\\Fracture\\MethodNotFoundException')->duringCall('__construct');
 }
 function it_delegates_throwing_named_constructor_not_found_exception(WrappedObject $wrappedObject, ExceptionFactory $exceptions)
 {
     $obj = new \ArrayObject();
     $arguments = array('firstname', 'lastname');
     $wrappedObject->isInstantiated()->willReturn(false);
     $wrappedObject->getInstance()->willReturn(null);
     $wrappedObject->getClassName()->willReturn('ArrayObject');
     $wrappedObject->getFactoryMethod()->willReturn('register');
     $wrappedObject->getArguments()->willReturn($arguments);
     $exceptions->namedConstructorNotFound('ArrayObject', 'register', $arguments)->willReturn(new \PhpSpec\Exception\Fracture\NamedConstructorNotFoundException('Named constructor "register" not found.', $obj, '"ArrayObject::register"', array()))->shouldBeCalled();
     $this->shouldThrow('\\PhpSpec\\Exception\\Fracture\\NamedConstructorNotFoundException')->duringCall('foo');
 }
Esempio n. 5
0
 /**
  * @return object
  */
 private function newInstanceWithFactoryMethod()
 {
     return call_user_func_array($this->wrappedObject->getFactoryMethod(), $this->wrappedObject->getArguments());
 }