diff --git a/src/Assert.php b/src/Assert.php index cf0548a5..337349ba 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -15,6 +15,8 @@ use BadMethodCallException; use Closure; use Countable; +use DateTime; +use DateTimeImmutable; use Exception; use InvalidArgumentException; use ResourceBundle; @@ -2099,6 +2101,10 @@ protected static function valueToString($value) return \get_class($value).': '.self::valueToString($value->__toString()); } + if ($value instanceof DateTime || $value instanceof DateTimeImmutable) { + return \get_class($value).': '.self::valueToString($value->format('c')); + } + return \get_class($value); } diff --git a/tests/AssertTest.php b/tests/AssertTest.php index ee850229..a12a846c 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -677,6 +677,8 @@ public function getStringConversions() array('eq', array(array(1), array(2)), 'Expected a value equal to array. Got: array'), array('eq', array(new ArrayIterator(array()), new stdClass()), 'Expected a value equal to stdClass. Got: ArrayIterator'), array('eq', array(1, self::getResource()), 'Expected a value equal to resource. Got: 1'), + + array('lessThan', array(new \DateTime('2020-01-01 00:00:00'), new \DateTime('1999-01-01 00:00:00')), 'Expected a value less than DateTime: "1999-01-01T00:00:00+00:00". Got: DateTime: "2020-01-01T00:00:00+00:00"'), ); }