getInstance() public method

public getInstance ( ) : object | null
return object | null
示例#1
0
 function it_delegates_throwing_property_not_found_exception(WrappedObject $wrappedObject, ExceptionFactory $exceptions)
 {
     $obj = new ExampleClass();
     $wrappedObject->isInstantiated()->willReturn(true);
     $wrappedObject->getInstance()->willReturn($obj);
     $exceptions->propertyNotFound($obj, 'nonExistentProperty')->willReturn(new \PhpSpec\Exception\Fracture\PropertyNotFoundException('Property "nonExistentProperty" not found.', $obj, 'nonExistentProperty'))->shouldBeCalled();
     $this->shouldThrow('\\PhpSpec\\Exception\\Fracture\\PropertyNotFoundException')->duringSet('nonExistentProperty', 'any value');
 }
示例#2
0
 /**
  * @return object
  *
  * @throws \PhpSpec\Exception\Fracture\ClassNotFoundException
  */
 public function getWrappedObject()
 {
     if ($this->wrappedObject->isInstantiated()) {
         return $this->wrappedObject->getInstance();
     }
     if (null === $this->wrappedObject->getClassName() || !is_string($this->wrappedObject->getClassName())) {
         return $this->wrappedObject->getInstance();
     }
     if (!class_exists($this->wrappedObject->getClassName())) {
         throw $this->classNotFound();
     }
     if (is_object($this->wrappedObject->getInstance())) {
         $this->wrappedObject->setInstantiated(true);
         $instance = $this->wrappedObject->getInstance();
     } else {
         $instance = $this->instantiateWrappedObject();
         $this->wrappedObject->setInstance($instance);
         $this->wrappedObject->setInstantiated(true);
     }
     return $instance;
 }