diff --git a/src/MockedClass.php b/src/MockedClass.php index 44775a0..70e1bc4 100644 --- a/src/MockedClass.php +++ b/src/MockedClass.php @@ -12,6 +12,7 @@ use Exan\Moock\Dto\MethodCall; use Exan\Moock\Expector\MockExpector; use Exan\Moock\Properties\MockPropertyValue; +use Generator; use ReflectionClass; use ReflectionMethod; use ReflectionNamedType; @@ -161,6 +162,10 @@ private function getDefault(string $method): mixed DateTimeImmutable::class => fn () => new DateTimeImmutable(), DateInterval::class => fn () => DateInterval::createFromDateString('1 day'), DatePeriod::class => fn () => DatePeriod::createFromISO8601String('R1337/2026-02-24T00:00:00Z/P1Y'), + + Generator::class => function (): Generator { + yield from []; + } ]; if (isset($returns[$plainType])) { diff --git a/tests/Components/TestDefaultReturns.php b/tests/Components/TestDefaultReturns.php index e87debd..e96a8b2 100644 --- a/tests/Components/TestDefaultReturns.php +++ b/tests/Components/TestDefaultReturns.php @@ -8,6 +8,7 @@ use DatePeriod; use DateTime; use DateTimeImmutable; +use Generator; use stdClass; class TestDefaultReturns @@ -126,4 +127,9 @@ public function returnUserServiceInterface(): UserServiceInterface { return new UserService(); } + + public function returnGenerator(): Generator + { + yield 'value'; + } } diff --git a/tests/Documentation/DefaultReturnValuesTest.php b/tests/Documentation/DefaultReturnValuesTest.php index b874cbf..fd98ab1 100644 --- a/tests/Documentation/DefaultReturnValuesTest.php +++ b/tests/Documentation/DefaultReturnValuesTest.php @@ -35,6 +35,7 @@ public function it_returns_hardcoded_values_for_basic_types(): void $this->assertEquals([], $mock->returnArray()); $this->assertEquals([], $mock->returnIterable()); + $this->assertEmpty(iterator_to_array($mock->returnGenerator())); // These objects do not have any properties $this->assertInstanceOf(stdClass::class, $mock->returnObject());