Skip to content

Commit 0e44dcd

Browse files
staabmsebastianbergmann
authored andcommitted
Fix class-loading in ReturnValueGenerator
1 parent e47fce3 commit 0e44dcd

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

src/Framework/MockObject/Runtime/ReturnValueGenerator.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,59 +57,59 @@ public function generate(string $className, string $methodName, string $stubClas
5757
$types = [$returnType];
5858
}
5959

60-
$types = array_map('strtolower', $types);
61-
6260
if (!$intersection) {
63-
if (in_array('', $types, true) ||
64-
in_array('null', $types, true) ||
65-
in_array('mixed', $types, true) ||
66-
in_array('void', $types, true)) {
61+
$lowerTypes = array_map('strtolower', $types);
62+
63+
if (in_array('', $lowerTypes, true) ||
64+
in_array('null', $lowerTypes, true) ||
65+
in_array('mixed', $lowerTypes, true) ||
66+
in_array('void', $lowerTypes, true)) {
6767
return null;
6868
}
6969

70-
if (in_array('true', $types, true)) {
70+
if (in_array('true', $lowerTypes, true)) {
7171
return true;
7272
}
7373

74-
if (in_array('false', $types, true) ||
75-
in_array('bool', $types, true)) {
74+
if (in_array('false', $lowerTypes, true) ||
75+
in_array('bool', $lowerTypes, true)) {
7676
return false;
7777
}
7878

79-
if (in_array('float', $types, true)) {
79+
if (in_array('float', $lowerTypes, true)) {
8080
return 0.0;
8181
}
8282

83-
if (in_array('int', $types, true)) {
83+
if (in_array('int', $lowerTypes, true)) {
8484
return 0;
8585
}
8686

87-
if (in_array('string', $types, true)) {
87+
if (in_array('string', $lowerTypes, true)) {
8888
return '';
8989
}
9090

91-
if (in_array('array', $types, true)) {
91+
if (in_array('array', $lowerTypes, true)) {
9292
return [];
9393
}
9494

95-
if (in_array('static', $types, true)) {
95+
if (in_array('static', $lowerTypes, true)) {
9696
return $this->newInstanceOf($stubClassName, $className, $methodName);
9797
}
9898

99-
if (in_array('object', $types, true)) {
99+
if (in_array('object', $lowerTypes, true)) {
100100
return new stdClass;
101101
}
102102

103-
if (in_array('callable', $types, true) ||
104-
in_array('closure', $types, true)) {
103+
if (in_array('callable', $lowerTypes, true) ||
104+
in_array('closure', $lowerTypes, true)) {
105105
return static function (): void
106106
{
107107
};
108108
}
109109

110-
if (in_array('traversable', $types, true) ||
111-
in_array('generator', $types, true) ||
112-
in_array('iterable', $types, true)) {
110+
if (in_array('traversable', $lowerTypes, true) ||
111+
in_array('generator', $lowerTypes, true) ||
112+
in_array('iterable', $lowerTypes, true)) {
113113
$generator = static function (): \Generator
114114
{
115115
yield from [];

tests/unit/Framework/MockObject/ReturnValueGeneratorTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
namespace PHPUnit\Framework\MockObject;
1111

12-
use function assert;
13-
use function interface_exists;
1412
use function sprintf;
1513
use Generator;
1614
use PHPUnit\Framework\Attributes\CoversClass;
@@ -144,13 +142,6 @@ public function test_Generates_test_stub_for_class_or_interface_name(): void
144142

145143
public function test_Generates_test_stub_for_intersection_of_interfaces(): void
146144
{
147-
/**
148-
* @todo Figure out why AnotherInterface is not found by the autoloader
149-
* when only the tests of this class are run; the interface is found as
150-
* expected when the entire (unit) test suite is run
151-
*/
152-
assert(interface_exists(AnotherInterface::class));
153-
154145
$value = $this->generate(AnInterface::class . '&' . AnotherInterface::class);
155146

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

0 commit comments

Comments
 (0)