Permalink
Browse files

Fixes #957.

Added delta support for the DateTime comparator.
  • Loading branch information...
whatthejeff committed Jul 6, 2013
1 parent 5555dd5 commit be88aa01b68015c158b49972c63c5d7642a5476f
Showing with 47 additions and 1 deletion.
  1. +7 −1 PHPUnit/Framework/Comparator/DateTime.php
  2. +40 −0 Tests/Framework/AssertTest.php
@@ -85,7 +85,13 @@ public function accepts($expected, $actual)
*/
public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FALSE, $ignoreCase = FALSE)
{
- if ($expected != $actual) {
+ $delta = new DateInterval(sprintf('PT%sS', abs($delta)));
+
+ $expectedLower = clone $expected;
+ $expectedUpper = clone $expected;
+
+ if ($actual < $expectedLower->sub($delta) ||
+ $actual > $expectedUpper->add($delta)) {
throw new PHPUnit_Framework_ComparisonFailure(
$expected,
$actual,
@@ -711,14 +711,34 @@ protected function notEqualValues()
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/New_York')),
),
+ array(
+ new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
+ new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/New_York')),
+ 3500
+ ),
+ array(
+ new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
+ new DateTime('2013-03-29 05:13:35', new DateTimeZone('America/New_York')),
+ 3500
+ ),
array(
new DateTime('2013-03-29', new DateTimeZone('America/New_York')),
new DateTime('2013-03-30', new DateTimeZone('America/New_York')),
),
+ array(
+ new DateTime('2013-03-29', new DateTimeZone('America/New_York')),
+ new DateTime('2013-03-30', new DateTimeZone('America/New_York')),
+ 43200
+ ),
array(
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago')),
),
+ array(
+ new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
+ new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago')),
+ 3500
+ ),
array(
new DateTime('2013-03-30', new DateTimeZone('America/New_York')),
new DateTime('2013-03-30', new DateTimeZone('America/Chicago')),
@@ -807,6 +827,16 @@ protected function equalValues()
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
),
+ array(
+ new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
+ new DateTime('2013-03-29 04:13:25', new DateTimeZone('America/New_York')),
+ 10
+ ),
+ array(
+ new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
+ new DateTime('2013-03-29 04:14:40', new DateTimeZone('America/New_York')),
+ 65
+ ),
array(
new DateTime('2013-03-29', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29', new DateTimeZone('America/New_York')),
@@ -815,10 +845,20 @@ protected function equalValues()
new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/Chicago')),
),
+ array(
+ new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')),
+ new DateTime('2013-03-29 03:13:49', new DateTimeZone('America/Chicago')),
+ 15
+ ),
array(
new DateTime('2013-03-30', new DateTimeZone('America/New_York')),
new DateTime('2013-03-29 23:00:00', new DateTimeZone('America/Chicago')),
),
+ array(
+ new DateTime('2013-03-30', new DateTimeZone('America/New_York')),
+ new DateTime('2013-03-29 23:01:30', new DateTimeZone('America/Chicago')),
+ 100
+ ),
array(
new DateTime('@1364616000'),
new DateTime('2013-03-29 23:00:00', new DateTimeZone('America/Chicago')),

0 comments on commit be88aa0

Please sign in to comment.