From 07aaad8ca70303d02b76aeb001cce51037f0e61c Mon Sep 17 00:00:00 2001 From: Marc Veldman Date: Tue, 15 Oct 2019 20:56:16 +0200 Subject: [PATCH] SimpeXML and ResourceBundle are also 'countable'. (#141) --- src/Assert.php | 9 ++++++++- tests/AssertTest.php | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Assert.php b/src/Assert.php index ee15dff3..5997c2e9 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -17,6 +17,8 @@ use Countable; use Exception; use InvalidArgumentException; +use ResourceBundle; +use SimpleXMLElement; use Throwable; use Traversable; @@ -487,7 +489,12 @@ public static function isArrayAccessible($value, $message = '') */ public static function isCountable($value, $message = '') { - if (!\is_array($value) && !($value instanceof Countable)) { + if ( + !\is_array($value) + && !($value instanceof Countable) + && !($value instanceof ResourceBundle) + && !($value instanceof SimpleXMLElement) + ) { static::reportInvalidArgument(\sprintf( $message ?: 'Expected a countable. Got: %s', static::typeToString($value) diff --git a/tests/AssertTest.php b/tests/AssertTest.php index 890475d5..dea9893f 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -122,6 +122,7 @@ public function getTests() array('isCountable', array(array(1, 2)), true), array('isCountable', array(new ArrayIterator(array())), true), array('isCountable', array(new stdClass()), false), + array('isCountable', array(new \SimpleXMLElement('bar')), true), array('isCountable', array('abcd'), false), array('isCountable', array(123), false), array('isIterable', array(array()), true),