Exemplo n.º 1
0
 /**
  * Gets the value of existing offset in the actual value
  *
  * @param mixed $offset
  *
  * @return PHPSpec\Specification\Interceptor
  */
 public function offsetGet($offset)
 {
     if (!isset($this->_actualValue[$offset])) {
         trigger_error("Undefined index: {$offset}", E_USER_NOTICE);
     }
     return InterceptorFactory::create($this->_actualValue[$offset]);
 }
Exemplo n.º 2
0
 /**
  * Aplies a closure to each of the elements of the iterator
  * 
  * @param \Closure $yield
  * @throws \PHPSpec\Exception
  * 
  * return array
  */
 public function withEach(\Closure $yield)
 {
     $elements = array();
     if (is_array($this->_value) || $this->_value instanceof \Iterator) {
         foreach ($this->_value as $key => $value) {
             $elements[] = $yield(InterceptorFactory::create($value));
         }
         return $elements;
     }
     throw new \PHPSpec\Exception('Not an traversable item');
 }
Exemplo n.º 3
0
 /**
  * Proxies call to specification and if argument is a dsl call than it calls
  * the interceptor factory for the returned value
  *
  * @param string $attribute 
  * @return mixed
  */
 public function __get($attribute)
 {
     $dslResult = parent::__get($attribute);
     if (!is_null($dslResult)) {
         return $dslResult;
     }
     if (isset($this->getActualValue()->{$attribute})) {
         return InterceptorFactory::create($this->getActualValue()->{$attribute});
     }
     trigger_error("Undefined property: " . get_class($this->getActualValue()) . "::{$attribute}", E_USER_NOTICE);
 }
Exemplo n.º 4
0
 public function spec($actualValue)
 {
     return InterceptorFactory::create($actualValue);
 }
Exemplo n.º 5
0
 /**
  * Checks whether a expectation is being invoked
  * 
  * @param string $attribute
  * 
  * @return \PHPSpec\Specification\Interceptor|mixed
  */
 public function __get($attribute)
 {
     switch ($attribute) {
         case 'should':
             $this->_expectation = self::SHOULD;
             return $this;
         case 'shouldNot':
             $this->_expectation = self::SHOULD_NOT;
             return $this;
         default:
             if (method_exists($this->_actualValue, '__get')) {
                 $parentInterceptor = new \ReflectionMethod($this->_actualValue, '__get');
                 $value = $parentInterceptor->invokeArgs($this->_actualValue, array($attribute));
                 return InterceptorFactory::create($value, $this);
             }
     }
 }
Exemplo n.º 6
0
 /**
  * Proxies call to specification and if argument is a dsl call than it calls
  * the interceptor factory for the returned value
  *
  * @param string $attribute
  * @return mixed
  */
 public function __get($attribute)
 {
     $dslResult = parent::__get($attribute);
     if (is_object($dslResult) && isset($dslResult->_expectation)) {
         return $dslResult;
     }
     return InterceptorFactory::create($this->getActualValue()->{$attribute});
 }