Skip to content

Commit

Permalink
Deal with null type in PHP8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschiet committed Jan 16, 2023
1 parent 3c3ca93 commit d316883
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/Mockery/Reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ private static function formatNullableType($typeHint)
return sprintf('?%s', $typeHint);
}

if ($typeHint === 'null') {
return 'null';
}

return $typeHint === 'mixed' ? 'mixed' : 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 d316883

Please sign in to comment.