/** * 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]); }
/** * 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'); }
/** * 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); }
public function spec($actualValue) { return InterceptorFactory::create($actualValue); }
/** * 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); } } }
/** * 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}); }