Skip to content

Commit

Permalink
Merge branch '11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Apr 1, 2024
2 parents e03a07d + a2482b7 commit 2c4fb12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
40 changes: 20 additions & 20 deletions src/Framework/MockObject/Runtime/ReturnValueGenerator.php
Expand Up @@ -57,59 +57,59 @@ public function generate(string $className, string $methodName, string $stubClas
$types = [$returnType];
}

$types = array_map('strtolower', $types);

if (!$intersection) {
if (in_array('', $types, true) ||
in_array('null', $types, true) ||
in_array('mixed', $types, true) ||
in_array('void', $types, true)) {
$lowerTypes = array_map('strtolower', $types);

if (in_array('', $lowerTypes, true) ||
in_array('null', $lowerTypes, true) ||
in_array('mixed', $lowerTypes, true) ||
in_array('void', $lowerTypes, true)) {
return null;
}

if (in_array('true', $types, true)) {
if (in_array('true', $lowerTypes, true)) {
return true;
}

if (in_array('false', $types, true) ||
in_array('bool', $types, true)) {
if (in_array('false', $lowerTypes, true) ||
in_array('bool', $lowerTypes, true)) {
return false;
}

if (in_array('float', $types, true)) {
if (in_array('float', $lowerTypes, true)) {
return 0.0;
}

if (in_array('int', $types, true)) {
if (in_array('int', $lowerTypes, true)) {
return 0;
}

if (in_array('string', $types, true)) {
if (in_array('string', $lowerTypes, true)) {
return '';
}

if (in_array('array', $types, true)) {
if (in_array('array', $lowerTypes, true)) {
return [];
}

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

if (in_array('object', $types, true)) {
if (in_array('object', $lowerTypes, true)) {
return new stdClass;
}

if (in_array('callable', $types, true) ||
in_array('closure', $types, true)) {
if (in_array('callable', $lowerTypes, true) ||
in_array('closure', $lowerTypes, true)) {
return static function (): void
{
};
}

if (in_array('traversable', $types, true) ||
in_array('generator', $types, true) ||
in_array('iterable', $types, true)) {
if (in_array('traversable', $lowerTypes, true) ||
in_array('generator', $lowerTypes, true) ||
in_array('iterable', $lowerTypes, true)) {
$generator = static function (): \Generator
{
yield from [];
Expand Down
9 changes: 0 additions & 9 deletions tests/unit/Framework/MockObject/ReturnValueGeneratorTest.php
Expand Up @@ -9,8 +9,6 @@
*/
namespace PHPUnit\Framework\MockObject;

use function assert;
use function interface_exists;
use function sprintf;
use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
Expand Down Expand Up @@ -144,13 +142,6 @@ public function test_Generates_test_stub_for_class_or_interface_name(): void

public function test_Generates_test_stub_for_intersection_of_interfaces(): void
{
/**
* @todo Figure out why AnotherInterface is not found by the autoloader
* when only the tests of this class are run; the interface is found as
* expected when the entire (unit) test suite is run
*/
assert(interface_exists(AnotherInterface::class));

$value = $this->generate(AnInterface::class . '&' . AnotherInterface::class);

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

0 comments on commit 2c4fb12

Please sign in to comment.