Skip to content

Commit

Permalink
Closes #4933
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 15, 2022
1 parent 7699c48 commit 4a11788
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog-9.5.md
Expand Up @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 9.5 release series are documented in this fil
### Fixed

* [#4929](https://github.com/sebastianbergmann/phpunit/issues/4929): Test Double code generator does not handle new expressions inside parameter default values
* [#4933](https://github.com/sebastianbergmann/phpunit/issues/4933): Backport support for `never` type from PHPUnit 10 to PHPUnit 9.5

## [9.5.18] - 2022-03-08

Expand Down
4 changes: 2 additions & 2 deletions src/Framework/MockObject/MockMethod.php
Expand Up @@ -191,9 +191,9 @@ public function generateCode(): string
{
if ($this->static) {
$templateFile = 'mocked_static_method.tpl';
} elseif ($this->returnType instanceof VoidType) {
} elseif ($this->returnType->isNever() || $this->returnType->isVoid()) {
$templateFile = sprintf(
'%s_method_void.tpl',
'%s_method_never_or_void.tpl',
$this->callOriginalMethod ? 'proxied' : 'mocked'
);
} else {
Expand Down
@@ -0,0 +1,56 @@
--TEST--
\PHPUnit\Framework\MockObject\Generator::generate('Foo', [], 'MockFoo', true, true)
--SKIPIF--
<?php declare(strict_types=1);
if (version_compare('8.1.0-dev', PHP_VERSION, '>')) {
print 'skip: PHP 8.1 is required.';
}
--FILE--
<?php declare(strict_types=1);
interface Foo
{
public function bar(string $baz): never;
}

require_once __DIR__ . '/../../../../vendor/autoload.php';

$generator = new \PHPUnit\Framework\MockObject\Generator;

$mock = $generator->generate(
'Foo',
[],
'MockFoo',
true,
true
);

print $mock->getClassCode();
--EXPECTF--
declare(strict_types=1);

class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo
{
use \PHPUnit\Framework\MockObject\Api;
use \PHPUnit\Framework\MockObject\Method;
use \PHPUnit\Framework\MockObject\MockedCloneMethod;

public function bar(string $baz): never
{
$__phpunit_arguments = [$baz];
$__phpunit_count = func_num_args();

if ($__phpunit_count > 1) {
$__phpunit_arguments_tmp = func_get_args();

for ($__phpunit_i = 1; $__phpunit_i < $__phpunit_count; $__phpunit_i++) {
$__phpunit_arguments[] = $__phpunit_arguments_tmp[$__phpunit_i];
}
}

$this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
'Foo', 'bar', $__phpunit_arguments, 'never', $this, true
)
);
}
}

0 comments on commit 4a11788

Please sign in to comment.