Skip to content

Commit 4465f86

Browse files
Merge branch '10.5' into 11.2
2 parents 49e6aaa + c23fadf commit 4465f86

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/Framework/MockObject/Runtime/ReturnValueGenerator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ private function newInstanceOf(string $stubClassName, string $className, string
184184
{
185185
try {
186186
return (new ReflectionClass($stubClassName))->newInstanceWithoutConstructor();
187+
// @codeCoverageIgnoreStart
187188
} catch (Throwable $t) {
188189
throw new RuntimeException(
189190
sprintf(
@@ -193,6 +194,7 @@ private function newInstanceOf(string $stubClassName, string $className, string
193194
$t->getMessage(),
194195
),
195196
);
197+
// @codeCoverageIgnoreEnd
196198
}
197199
}
198200

@@ -207,6 +209,7 @@ private function testDoubleFor(string $type, string $className, string $methodNa
207209
{
208210
try {
209211
return (new Generator)->testDouble($type, false, false, [], [], '', false);
212+
// @codeCoverageIgnoreStart
210213
} catch (Throwable $t) {
211214
throw new RuntimeException(
212215
sprintf(
@@ -216,6 +219,7 @@ private function testDoubleFor(string $type, string $className, string $methodNa
216219
$t->getMessage(),
217220
),
218221
);
222+
// @codeCoverageIgnoreEnd
219223
}
220224
}
221225

@@ -230,6 +234,7 @@ private function testDoubleForIntersectionOfInterfaces(array $types, string $cla
230234
{
231235
try {
232236
return (new Generator)->testDoubleForInterfaceIntersection($types, false);
237+
// @codeCoverageIgnoreStart
233238
} catch (Throwable $t) {
234239
throw new RuntimeException(
235240
sprintf(
@@ -239,6 +244,7 @@ private function testDoubleForIntersectionOfInterfaces(array $types, string $cla
239244
$t->getMessage(),
240245
),
241246
);
247+
// @codeCoverageIgnoreEnd
242248
}
243249
}
244250
}

tests/unit/Framework/MockObject/ReturnValueGeneratorTest.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use PHPUnit\TestFixture\MockObject\AnInterfaceForIssue5593;
2323
use PHPUnit\TestFixture\MockObject\AnotherInterface;
2424
use PHPUnit\TestFixture\MockObject\AnotherInterfaceForIssue5593;
25+
use PHPUnit\TestFixture\MockObject\ExtendableClass;
2526
use PHPUnit\TestFixture\MockObject\YetAnotherInterface;
2627
use stdClass;
2728

@@ -119,17 +120,35 @@ public function test_Generates_callable_for_Closure(): void
119120

120121
public function test_Generates_Generator_for_Generator(): void
121122
{
122-
$this->assertInstanceOf(Generator::class, $this->generate('Generator'));
123+
$value = $this->generate('Generator');
124+
125+
$this->assertInstanceOf(Generator::class, $value);
126+
127+
foreach ($value as $element) {
128+
$this->assertSame([], $element);
129+
}
123130
}
124131

125132
public function test_Generates_Generator_for_Traversable(): void
126133
{
127-
$this->assertInstanceOf(Generator::class, $this->generate('Traversable'));
134+
$value = $this->generate('Traversable');
135+
136+
$this->assertInstanceOf(Generator::class, $value);
137+
138+
foreach ($value as $element) {
139+
$this->assertSame([], $element);
140+
}
128141
}
129142

130143
public function test_Generates_Generator_for_iterable(): void
131144
{
132-
$this->assertInstanceOf(Generator::class, $this->generate('iterable'));
145+
$value = $this->generate('iterable');
146+
147+
$this->assertInstanceOf(Generator::class, $value);
148+
149+
foreach ($value as $element) {
150+
$this->assertSame([], $element);
151+
}
133152
}
134153

135154
public function test_Generates_test_stub_for_class_or_interface_name(): void
@@ -201,6 +220,22 @@ public function test_Generates_test_stub_for_first_intersection_of_interfaces_fo
201220
$this->assertInstanceOf(AnotherInterface::class, $value);
202221
}
203222

223+
public function test_Does_not_handle_union_of_extendable_class_and_interface(): void
224+
{
225+
$this->expectException(RuntimeException::class);
226+
$this->expectExceptionMessage('Return value for OriginalClassName::methodName() cannot be generated because the declared return type is a union, please configure a return value for this method');
227+
228+
$this->generate(ExtendableClass::class . '|' . AnInterface::class);
229+
}
230+
231+
public function test_Does_not_handle_intersection_of_extendable_class_and_interface(): void
232+
{
233+
$this->expectException(RuntimeException::class);
234+
$this->expectExceptionMessage('Return value for OriginalClassName::methodName() cannot be generated because the declared return type is an intersection, please configure a return value for this method');
235+
236+
$this->generate(ExtendableClass::class . '&' . AnInterface::class);
237+
}
238+
204239
public function test_Generates_test_stub_for_unknown_type(): void
205240
{
206241
$this->assertInstanceOf(Stub::class, $this->generate('ThisDoesNotExist'));

0 commit comments

Comments
 (0)