diff --git a/src/Framework/Constraint/IsType.php b/src/Framework/Constraint/IsType.php index 1637eff7d12..a554afd4d67 100644 --- a/src/Framework/Constraint/IsType.php +++ b/src/Framework/Constraint/IsType.php @@ -47,7 +47,8 @@ class IsType extends Constraint 'resource' => true, 'string' => true, 'scalar' => true, - 'callable' => true + 'callable' => true, + 'iterable' => true, ]; /** @@ -137,6 +138,9 @@ protected function matches($other): bool case 'callable': return \is_callable($other); + + case 'iterable': + return \is_iterable($other); } } } diff --git a/tests/Framework/Constraint/IsTypeTest.php b/tests/Framework/Constraint/IsTypeTest.php index e4318ef3566..05b66f19fdc 100644 --- a/tests/Framework/Constraint/IsTypeTest.php +++ b/tests/Framework/Constraint/IsTypeTest.php @@ -91,6 +91,14 @@ public function resources() ]; } + public function testIterableTypeIsSupported(): void + { + $constraint = Assert::isType('iterable'); + + $this->assertFalse($constraint->evaluate('', '', true)); + $this->assertTrue($constraint->evaluate([], '', true)); + $this->assertEquals('is of type "iterable"', $constraint->toString()); + } /** * Removes spaces in front of newlines *