Skip to content

Commit

Permalink
Fix #96 Predicate matching replaces the actual value with a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelloDuarte committed Sep 2, 2012
1 parent c73606b commit 0bf4c5e
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions src/PHPSpec/Specification/Interceptor/Object.php
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0bf4c5e

Please sign in to comment.