Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with null type in PHP8.2 #1205

Merged
merged 2 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion library/Mockery/Reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ private static function formatNullableType($typeHint)
return sprintf('?%s', $typeHint);
}

return $typeHint === 'mixed' ? 'mixed' : sprintf('%s|null', $typeHint);
if ($typeHint === 'null' || $typeHint === 'mixed') {
return $typeHint;
}

return sprintf('%s|null', $typeHint);
}
}
28 changes: 28 additions & 0 deletions tests/PHP82/Php82LanguageFeaturesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace test\Mockery;

use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;

/**
* @requires PHP 8.2.0-dev
*/
class Php82LanguageFeaturesTest extends MockeryTestCase
{
/** @test */
public function it_can_mock_an_class_with_null_return_type()
{
$mock = Mockery::mock(HasNullReturnType::class);

$this->assertInstanceOf(HasNullReturnType::class, $mock);
}
}

class HasNullReturnType
{
public function getChildren(): null
{
return null;
}
}