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

Cannot double interface that extends interface that extends \Throwable #3967

Closed
fbourigault opened this issue Dec 4, 2019 · 1 comment
Closed

Comments

@fbourigault
Copy link
Contributor

@fbourigault fbourigault commented Dec 4, 2019

Q A
PHPUnit version 8.4.3, master
PHP version 7.3.12
Installation Method Composer

Summary

Creating a mock of Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface triggers the following PHP fatal error.

PHP Fatal error: Class Mock_Exception_80007f4f contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface::getResponse) in /home/fabien/Projets/fbourigault/phpunit-mock-interface/vendor/phpunit/phpunit/src/Framework/MockObject/MockClass.php(42) : eval()'d code on line 3

How to reproduce

I wrote a reproducer as a PHPUnit e2e test: https://gist.github.com/fbourigault/8e6298706db421bee040d57dfe51000f

In the test output, we can notice the missing foo method. Also, the mock class name is not the expected one.

 declare(strict_types=1);
 
-class MockBaz extends Exception implements Baz, PHPUnit\Framework\MockObject\MockObject
+class Mock_Exception_c6cde15f 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;
-    }
 }
@sebastianbergmann
Copy link
Owner

@sebastianbergmann sebastianbergmann commented Dec 4, 2019

This is related to the fix for #2995.

Loading

@fbourigault fbourigault changed the title Cannot mock RedirectionExceptionInterface from Symfony. Cannot mock RedirectionExceptionInterface from Symfony Dec 4, 2019
@sebastianbergmann sebastianbergmann changed the title Cannot mock RedirectionExceptionInterface from Symfony Cannot double interface that extends interface that extends \Throwable Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants