/** * (non-PHPdoc) * * @see CIUnit_Framework_ComparatorAbstract::assertEquals() */ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FALSE, $ignoreCase = FALSE, array &$processedObjects = array()) { if (gettype($expected) != gettype($actual)) { $message = sprintf('%s does not match expected type "%s".', CIUnit_Util_Type::shortExport($actual), gettype($expected)); throw new CIUnit_Framework_Exception_ComparissonFailure($expected, $actual, '', '', $message); } }
/** * (non-PHPdoc) * * @see CIUnit_Framework_Comparator_Object::toArray() */ protected function toArray($object) { // Remove some of the contetn of the exception that would be different // if not comparing two identical exceptions $array = CIUnit_Util_Type::toArray($object); unset($array['file'], $array['line'], $array['trace'], $array['string'], $array['xdebug_message']); return $array; }
/** * (non-PHPdoc) * * @see CIUnit_Framework_Comparator_Scalar::assertEquals() */ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FALSE, $ignoreCase = FALSE, array &$processedObjects = array()) { // Finds whether a value is infinite if (is_infinite($actual) && is_infinite($expected)) { return; } // Find whether a value is not a number if (is_nan($actual) && is_nan($expected)) { return; } // Check for nan and infinite + compare with delta if ((is_infinite($actual) xor is_infinite($expected)) || (is_nan($actual) xor is_nan($expected)) || abs($actual - $expected) > $delta) { throw new CIUnit_Framework_Exception_ComparissonFailure($expected, $actual, '', '', sprintf('Failed asserting that %s matches expected %s.', CIUnit_Util_Type::export($actual), CIUnit_Util_Type::export($expected))); } }
/** * (non-PHPdoc) * * @see CIUnit_Framework_ConstraintAbstract::failureDescription() */ public function failureDescription($evaluated) { return sprintf('%s is true', CIUnit_Util_Type::export($evaluated)); }
/** * String representation of the constraint * @return string */ public function toString() { return sprintf('is greater than %s', CIUnit_Util_Type::export($this->evaluated)); }
/** * (non-PHPdoc) * @see CIUnit_Framework_ConstraintAbstract::failureDescription() */ protected function failureDescription($evaluated) { return CIUnit_Util_Type::shortExport($evaluated) . ' ' . $this->toString(); }
/** * (non-PHPdoc) * * @see CIUnit_Framework_ConstraintAbstract::failureDescription() */ public function failureDescription($evaluated) { return sprintf('%s is of type "%s"', CIUnit_Util_Type::export($evaluated), $this->type); }
public function toString() { return sprintf('is equal to %s', CIUnit_Util_Type::export($this->expected)); }
/** * (non-PHPdoc) * * @see CIUnit_Framework_ComparatorAbstract::assertEquals() */ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FALSE, $ignoreCase = FALSE, array &$processedObjects = array()) { if ($canonicalize) { sort($expected); sort($actual); } $expectedAsString = "Array (\n"; $actualAsString = "Array (\n"; $remaining = $actual; $areEqual = TRUE; // Loop through all keys in the expected array and compare them with the // keys in the actual foreach ($expected as $key => $value) { unset($remaining[$key]); // If there is no corresponding key in actual, they are not equal if (!array_key_exists($key, $actual)) { $areEqual = FALSE; $expectedAsString .= sprintf(" %s => %s\n", CIUnit_Util_Type::export($key), CIUnit_Util_Type::export($value)); continue; // Continue executing the loop, but skip the code // below for this iteration } // Try to compare array values in both arrays using the in-house // comparisson mechanism try { $comparator = $this->factory->getComparator($value, $actual[$key]); $comparator->assertEquals($value, $actual[$key], $delta, $canonicalize, $ignoreCase, $processedObjects); $expectedAsString .= sprintf(" %s => %s\n", CIUnit_Util_Type::export($key), CIUnit_Util_Type::export($value)); $actualAsString .= sprintf(" %s => %s\n", CIUnit_Util_Type::export($key), CIUnit_Util_Type::export($actual[$key])); } catch (CIUnit_Framework_Exception_ComparissonFailure $e) { // Add $actual[$key] and $value to expectedAsString and // actualAsString from the exception $expectedAsString .= sprintf(" %s => %s\n", CIUnit_Util_Type::export($key), $e->getExpectedAsString() ? $this->indent($e->getExpectedAsString()) : CIUnit_Util_Type::export($e->getExpected())); $actualAsString .= sprintf(" %s => %s\n", CIUnit_Util_Type::export($key), $e->getExpectedAsString() ? $this->indent($e->getActualAsString()) : CIUnit_Util_Type::export($e->getActual())); $areEqual = FALSE; } } // Add all from remaining to actualAsStirng foreach ($remaining as $key => $value) { $actualAsString .= sprintf(" %s => %s\n", CIUnit_Util_Type::export($key), CIUnit_Util_Type::export($value)); $areEqual = FALSE; } $expectedAsString .= ")"; $actualAsString .= ")"; if (!$areEqual) { throw new CIUnit_Framework_Exception_ComparissonFailure($expected, $actual, $expectedAsString, $actualAsString, 'Failed asserting that two arrays are equal.'); } }
/** * (non-PHPdoc) * * @see CIUnit_Framework_ComparatorAbstract::assertEquals() */ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FALSE, $ignoreCase = FALSE, array &$processedObjects = array()) { if ($actual != $expected) { throw new CIUnit_Framework_Exception_ComparissonFailure($expected, $actual, CIUnit_Util_Type::export($expected), CIUnit_Util_Type::export($actual)); } }
/** * (non-PHPdoc) * * @see CIUnit_Framework_ComparatorAbstract::assertEquals() */ public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FALSE, $ignoreCase = FALSE, array &$processedObjects = array()) { $actualToCompare = $actual; $expectedToCompare = $expected; if (is_string($expected) || is_string($actual)) { $expectedToCompare = (string) $expected; $actualToCompare = (string) $actual; if ($ignoreCase) { $actualToCompare = strtolower($actualToCompare); $expectedToCompare = strtolower($expectedToCompare); } } if ($actualToCompare != $expectedToCompare) { if (is_string($expected) && is_string($actual)) { throw new CIUnit_Framework_Exception_ComparissonFailure($expected, $actual, CIUnit_Util_Type::export($expected), CIUnit_Util_Type::export($actual), 'Failed asserting that two strings are equal.'); } throw new CIUnit_Framework_Exception_ComparissonFailure($expected, $actual, '', '', sprintf('Failed asserting that %s matches expected %s.', CIUnit_Util_Type::export($actual), CIUnit_Util_Type::export($expected))); } }
/** * Converts an object in to an array * * @param object $object * @return array */ protected function toArray($object) { return CIUnit_Util_Type::toArray($object); }
/** * (non-PHPdoc) * * @see CIUnit_Framework_ConstraintAbstract::failureDescription() */ public function failureDescription($evaluated) { return sprintf('%s is an instance of %s', CIUnit_Util_Type::shortExport($evaluated), $this->class); }
/** * String representation of the constraint * @return string */ public function toString() { return sprintf('is less or equal to %s', CIUnit_Util_Type::export($this->evaluated)); }