Skip to content

Commit

Permalink
Deal with null type in PHP8.2 (#1205)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Apr 15, 2023
2 parents f9a7b32 + fb334db commit 8c19e1a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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;
}
}

0 comments on commit 8c19e1a

Please sign in to comment.