Skip to content

Commit

Permalink
Make this test work with PHP >= 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Apr 27, 2021
1 parent 503ae4c commit 2c47a3e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/end-to-end/mock-objects/generator/3967-php7-php80.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/3967
--SKIPIF--
<?php declare(strict_types=1);
if (!(new ReflectionMethod(Exception::class, '__clone'))->isFinal()) {
print 'skip: PHP < 8.1 required';
}
--FILE--
<?php declare(strict_types=1);
interface Bar extends \Throwable
{
public function foo(): string;
}

interface Baz extends Bar
{
}

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

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

$mock = $generator->generate(
'Baz',
[],
'MockBaz',
true,
true
);

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

class MockBaz extends Exception implements Baz, PHPUnit\Framework\MockObject\MockObject
{
use \PHPUnit\Framework\MockObject\Api;
use \PHPUnit\Framework\MockObject\Method;

public function foo(): string
{
$__phpunit_arguments = [];
$__phpunit_count = func_num_args();

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

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

$__phpunit_result = $this->__phpunit_getInvocationHandler()->invoke(
new \PHPUnit\Framework\MockObject\Invocation(
'Bar', 'foo', $__phpunit_arguments, ': string', $this, true
)
);

return $__phpunit_result;
}
}
6 changes: 6 additions & 0 deletions tests/end-to-end/mock-objects/generator/3967.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/3967
--SKIPIF--
<?php declare(strict_types=1);
if ((new ReflectionMethod(Exception::class, '__clone'))->isFinal()) {
print 'skip: PHP >= 8.1 required';
}
--FILE--
<?php declare(strict_types=1);
interface Bar extends \Throwable
Expand Down Expand Up @@ -31,6 +36,7 @@ class MockBaz extends Exception implements Baz, PHPUnit\Framework\MockObject\Moc
{
use \PHPUnit\Framework\MockObject\Api;
use \PHPUnit\Framework\MockObject\Method;
use \PHPUnit\Framework\MockObject\UnmockedCloneMethod;

public function foo(): string
{
Expand Down

0 comments on commit 2c47a3e

Please sign in to comment.