Skip to content

Commit

Permalink
Possible to create matchers accepting more than one argument as actua…
Browse files Browse the repository at this point in the history
…l values
  • Loading branch information
MarcelloDuarte committed May 15, 2011
1 parent c4dec49 commit e2f7d1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/PHPSpec/Specification.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class Specification
*/
protected $_matcher = null;

/**
* Whether actual value is a composed value
*
* @var boolean
*/
protected $_composedActual = false;

/**
* Public static factory method to create a new Specification (DSL)
* object based on the given object or scalar value.
Expand Down Expand Up @@ -406,9 +413,11 @@ protected function _createMatcher($method)
*/
protected function _performMatching()
{
$args = $this->getActualValue();
if (!is_array($this->getActualValue())) {
$args = array($this->getActualValue());
$actual = $this->getActualValue();
if (is_array($actual) && $this->_composedActual) {
$args = $actual;
} else {
$args = array($actual);
}
$result = call_user_func_array(
array($this->_matcher, 'matches'), $args
Expand Down
1 change: 1 addition & 0 deletions src/PHPSpec/Specification/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function __construct(\Closure $closure = null)
} catch (\PHPSpec\Exception $e) {
throw $e;
} catch(\Exception $e) {
$this->_composedActual = true;
$this->setActualValue(array(get_class($e), $e->getMessage()));
}
}
Expand Down

0 comments on commit e2f7d1b

Please sign in to comment.