Skip to content

Commit

Permalink
Iterable return types should return empty array by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored and sebastianbergmann committed May 20, 2021
1 parent c3d9624 commit 73e9d2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Framework/MockObject/Invocation.php
Expand Up @@ -152,7 +152,7 @@ public function generateReturnValue()
case 'generator':
case 'iterable':
$generator = static function () {
yield;
yield from [];
};

return $generator();
Expand Down
@@ -0,0 +1,27 @@
--TEST--
Iterable return types should return empty array by default
--FILE--
<?php declare(strict_types=1);
interface Foo
{
public function forTraversable(): traversable;
public function forGenerator(): Generator;
public function forIterable(): iterable;
}

require __DIR__ . '/../../../../vendor/autoload.php';

$generator = new \PHPUnit\Framework\MockObject\Generator;

$mock = $generator->getMock('Foo');

var_dump(iterator_to_array($mock->forTraversable()));
var_dump(iterator_to_array($mock->forGenerator()));
var_dump(iterator_to_array($mock->forIterable()));
--EXPECTF--
array(0) {
}
array(0) {
}
array(0) {
}

0 comments on commit 73e9d2b

Please sign in to comment.