Skip to content

Commit

Permalink
Allow use of ReferenceExpectation in expect calls
Browse files Browse the repository at this point in the history
Make ReferenceExpectation inherit from EqualException so it will be
recognised by SimpleExpectation::isExpectation.
  • Loading branch information
mal committed Jul 27, 2015
1 parent 6a40271 commit e7598f8
Showing 1 changed file with 5 additions and 45 deletions.
50 changes: 5 additions & 45 deletions expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,29 +445,16 @@ function testMessage($compare) {
* @package SimpleTest
* @subpackage UnitTester
*/
class ReferenceExpectation {
private $value;

/**
* Sets the reference value to compare against.
* @param mixed $value Test reference to match.
* @param string $message Customised message on failure.
* @access public
*/
function __construct(&$value, $message = '%s') {
$this->message = $message;
$this->value = &$value;
}

class ReferenceExpectation extends EqualExpectation {
/**
* Tests the expectation. True if it exactly
* references the held value.
* @param mixed $compare Comparison reference.
* @return boolean True if correct.
* @access public
*/
function test(&$compare) {
return SimpleTestCompatibility::isReference($this->value, $compare);
function test($compare) {
return SimpleTestCompatibility::isReference($this->getValue(), $compare);
}

/**
Expand All @@ -479,38 +466,11 @@ function test(&$compare) {
*/
function testMessage($compare) {
if ($this->test($compare)) {
return "Reference expectation [" . $this->dumper->describeValue($this->value) . "]";
return "Reference expectation [" . $this->dumper->describeValue($this->getValue()) . "]";
} else {
return "Reference expectation fails " .
$this->dumper->describeDifference($this->value, $compare);
}
}

/**
* Overlays the generated message onto the stored user
* message. An additional message can be interjected.
* @param mixed $compare Comparison value.
* @param SimpleDumper $dumper For formatting the results.
* @return string Description of success
* or failure.
* @access public
*/
function overlayMessage($compare, $dumper) {
$this->dumper = $dumper;
return sprintf($this->message, $this->testMessage($compare));
}

/**
* Accessor for the dumper.
* @return SimpleDumper Current value dumper.
* @access protected
*/
protected function getDumper() {
if (! $this->dumper) {
$dumper = new SimpleDumper();
return $dumper;
$this->dumper->describeDifference($this->getValue(), $compare);
}
return $this->dumper;
}
}

Expand Down

0 comments on commit e7598f8

Please sign in to comment.