Permalink
Browse files

Fix #96 Predicate matching replaces the actual value with a boolean

  • Loading branch information...
MarcelloDuarte committed Sep 2, 2012
1 parent c73606b commit 0bf4c5e48d36b9e0d13376405e25cc77f052d9af
Showing with 43 additions and 3 deletions.
  1. +43 −3 src/PHPSpec/Specification/Interceptor/Object.php
@@ -41,6 +41,8 @@ class Object extends Interceptor
*/
protected $_predicate = array('be' => 'is', 'have' => 'has');
+ protected $_predicateActualValue;
+
/**
* Proxies call to specification and if method is a dsl call than it calls
* the interceptor factory for the returned value
@@ -58,7 +60,7 @@ public function __call($method, $args)
if ($this->isPredicate('have', $method, $args) ||
$this->isPredicate('be', $method, $args)) {
- $this->performMatching();
+ $this->performPredicateMatching();
return true;
}
@@ -123,7 +125,7 @@ protected function isPredicate($type, $method, $args)
$this->setExpectedValue($args);
$this->_matcher = $this->getMatcherFactory()
->create('beTrue', array(true));
- $this->setActualValue(
+ $this->setPredicateActualValue(
call_user_func_array(array($this->_actualValue, $predicate), $args)
);
return true;
@@ -154,14 +156,52 @@ public function __get($attribute)
"::$attribute", E_USER_NOTICE
);
}
-
+
+ /**
+ * Setting intercepted object public property
+ *
+ * @param string $property
+ * @param mixed $value
+ */
public function __set($property, $value)
{
if (is_object($this->getActualValue())) {
$this->getActualValue()->$property = $value;
}
}
+ /**
+ * Performs predicate matching and restores actual value
+ */
+ protected function performPredicateMatching()
+ {
+ $actual = $this->getActualValue();
+ $this->setActualValue($this->getPredicateActualValue());
+ $this->performMatching();
+
+ $this->setActualValue($actual);
+ }
+
+ /**
+ * Sets predicate actual value
+ *
+ * @param boolean $value
+ */
+ protected function setPredicateActualValue($value)
+ {
+ $this->_predicateActualValue = $value;
+ }
+
+ /**
+ * Gets the predicate actual value
+ *
+ * @return boolean
+ */
+ protected function getPredicateActualValue()
+ {
+ return $this->_predicateActualValue;
+ }
+
/**
* Access the value of a unaccessible property and returns the
* intercepted value

0 comments on commit 0bf4c5e

Please sign in to comment.