Skip to content

Commit

Permalink
Merge branch '10.5' into 11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 31, 2024
2 parents 49e6aaa + c23fadf commit 4465f86
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Framework/MockObject/Runtime/ReturnValueGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private function newInstanceOf(string $stubClassName, string $className, string
{
try {
return (new ReflectionClass($stubClassName))->newInstanceWithoutConstructor();
// @codeCoverageIgnoreStart
} catch (Throwable $t) {
throw new RuntimeException(
sprintf(
Expand All @@ -193,6 +194,7 @@ private function newInstanceOf(string $stubClassName, string $className, string
$t->getMessage(),
),
);
// @codeCoverageIgnoreEnd
}
}

Expand All @@ -207,6 +209,7 @@ private function testDoubleFor(string $type, string $className, string $methodNa
{
try {
return (new Generator)->testDouble($type, false, false, [], [], '', false);
// @codeCoverageIgnoreStart
} catch (Throwable $t) {
throw new RuntimeException(
sprintf(
Expand All @@ -216,6 +219,7 @@ private function testDoubleFor(string $type, string $className, string $methodNa
$t->getMessage(),
),
);
// @codeCoverageIgnoreEnd
}
}

Expand All @@ -230,6 +234,7 @@ private function testDoubleForIntersectionOfInterfaces(array $types, string $cla
{
try {
return (new Generator)->testDoubleForInterfaceIntersection($types, false);
// @codeCoverageIgnoreStart
} catch (Throwable $t) {
throw new RuntimeException(
sprintf(
Expand All @@ -239,6 +244,7 @@ private function testDoubleForIntersectionOfInterfaces(array $types, string $cla
$t->getMessage(),
),
);
// @codeCoverageIgnoreEnd
}
}
}
41 changes: 38 additions & 3 deletions tests/unit/Framework/MockObject/ReturnValueGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PHPUnit\TestFixture\MockObject\AnInterfaceForIssue5593;
use PHPUnit\TestFixture\MockObject\AnotherInterface;
use PHPUnit\TestFixture\MockObject\AnotherInterfaceForIssue5593;
use PHPUnit\TestFixture\MockObject\ExtendableClass;
use PHPUnit\TestFixture\MockObject\YetAnotherInterface;
use stdClass;

Expand Down Expand Up @@ -119,17 +120,35 @@ public function test_Generates_callable_for_Closure(): void

public function test_Generates_Generator_for_Generator(): void
{
$this->assertInstanceOf(Generator::class, $this->generate('Generator'));
$value = $this->generate('Generator');

$this->assertInstanceOf(Generator::class, $value);

foreach ($value as $element) {
$this->assertSame([], $element);
}
}

public function test_Generates_Generator_for_Traversable(): void
{
$this->assertInstanceOf(Generator::class, $this->generate('Traversable'));
$value = $this->generate('Traversable');

$this->assertInstanceOf(Generator::class, $value);

foreach ($value as $element) {
$this->assertSame([], $element);
}
}

public function test_Generates_Generator_for_iterable(): void
{
$this->assertInstanceOf(Generator::class, $this->generate('iterable'));
$value = $this->generate('iterable');

$this->assertInstanceOf(Generator::class, $value);

foreach ($value as $element) {
$this->assertSame([], $element);
}
}

public function test_Generates_test_stub_for_class_or_interface_name(): void
Expand Down Expand Up @@ -201,6 +220,22 @@ public function test_Generates_test_stub_for_first_intersection_of_interfaces_fo
$this->assertInstanceOf(AnotherInterface::class, $value);
}

public function test_Does_not_handle_union_of_extendable_class_and_interface(): void
{
$this->expectException(RuntimeException::class);
$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');

$this->generate(ExtendableClass::class . '|' . AnInterface::class);
}

public function test_Does_not_handle_intersection_of_extendable_class_and_interface(): void
{
$this->expectException(RuntimeException::class);
$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');

$this->generate(ExtendableClass::class . '&' . AnInterface::class);
}

public function test_Generates_test_stub_for_unknown_type(): void
{
$this->assertInstanceOf(Stub::class, $this->generate('ThisDoesNotExist'));
Expand Down

0 comments on commit 4465f86

Please sign in to comment.