Esempio n. 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');
 }
Esempio n. 2
0
 function it_passes_the_created_subject_to_expectation(WrappedObject $wrappedObject, ExpectationFactory $expectationFactory, Expectation $expectation)
 {
     $expectation->match(Argument::cetera())->willReturn(true);
     $wrappedObject->getClassName()->willReturn('spec\\PhpSpec\\Wrapper\\Everything');
     $expectationFactory->create(Argument::cetera())->willReturn($expectation);
     $this->callOnWrappedObject('shouldBeAlright');
     $expectationFactory->create(Argument::any(), Argument::type('spec\\PhpSpec\\Wrapper\\Everything'), Argument::any())->shouldHaveBeenCalled();
 }
Esempio n. 3
0
 /**
  * @param string $method
  * @param array  $arguments
  *
  * @return mixed
  */
 public function during($method, array $arguments = array())
 {
     if ($method === '__construct') {
         $this->subject->beAnInstanceOf($this->wrappedObject->getClassname(), $arguments);
         $instantiator = new Instantiator();
         $object = $instantiator->instantiate($this->wrappedObject->getClassname());
     } else {
         $object = $this->wrappedObject->instantiate();
     }
     return $this->runDuring($object, $method, $arguments);
 }
Esempio n. 4
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. 5
0
 /**
  * @param string        $alias
  * @param mixed         $subject
  * @param array         $arguments
  * @param WrappedObject $wrappedObject
  *
  * @return boolean
  *
  * @throws \Exception
  * @throws \PhpSpec\Exception\Example\ErrorException
  * @throws \Exception
  * @throws \PhpSpec\Exception\Fracture\FractureException
  */
 public function match($alias, $subject, array $arguments = array(), WrappedObject $wrappedObject = null)
 {
     try {
         $wrapped = $subject->getWrappedObject();
     } catch (ErrorException $e) {
         throw $e;
     } catch (FractureException $e) {
         throw $e;
     } catch (Exception $e) {
         if (null !== $wrappedObject && $wrappedObject->getClassName()) {
             $instantiator = new Instantiator();
             $wrapped = $instantiator->instantiate($wrappedObject->getClassName());
         }
     }
     return $this->getExpectation()->match($alias, $wrapped, $arguments);
 }
Esempio n. 6
0
 /**
  * @return object
  */
 private function makeSureWeHaveASubject()
 {
     if (null === $this->subject && $this->wrappedObject->getClassname()) {
         $instantiator = new Instantiator();
         return $instantiator->instantiate($this->wrappedObject->getClassname());
     }
     return $this->subject;
 }
Esempio n. 7
0
 /**
  * @param string $property
  * @return bool
  */
 public function constantDefined($property)
 {
     return defined($this->wrappedObject->getClassName() . '::' . $property);
 }
Esempio n. 8
0
 /**
  * @param array|string $factoryMethod
  * @param array $arguments
  */
 public function beConstructedThrough($factoryMethod, array $arguments = array())
 {
     $this->wrappedObject->beConstructedThrough($factoryMethod, $arguments);
 }
 function it_ignores_any_other_exception(Subject $subject, WrappedObject $wrapped)
 {
     $subject->callOnWrappedObject('getWrappedObject', array())->willThrow('\\Exception');
     $wrapped->getClassName()->willReturn('\\stdClass');
     $this->shouldNotThrow('\\Exception')->duringMatch('be', $subject, array(), $wrapped);
 }