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

Regression in PHPUnit 7.5.10 with regard to Exception stubbing/mocking #3683

Closed
dominikzogg opened this issue May 9, 2019 · 7 comments
Closed
Labels
type/bug Something is broken

Comments

@dominikzogg
Copy link

dominikzogg commented May 9, 2019

Q A
PHPUnit version 7.5.10
PHP version 7.3.5
Installation Method Composer

Mocking the driver exception like this worked up to 7.5.9, the fix of the issue #3596 seems to break it:

/** @var DriverException | MockObject $driverException */
$driverException = $this->getMockBuilder(DriverException::class)->getMockForAbstractClass();

$connectionException = new ConnectionException('connection lost', $driverException);

With 7.5.10 its not working anymore:

Fatal error: Cannot override final method Exception::getMessage() in vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php(642) : eval()'d code on line 1
@dominikzogg
Copy link
Author

#3596

@sebastianbergmann
Copy link
Owner

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

@sebastianbergmann sebastianbergmann added the status/waiting-for-feedback Waiting for feedback from original reporter label May 9, 2019
@Prakson
Copy link

Prakson commented May 9, 2019

I have similar problem with exception mock.

<?php

namespace Tests;

use PHPUnit\Framework\TestCase;

class MockTest extends TestCase
{
    public function test(): void
    {
        $this->createMock(\Throwable::class);
    }
}

Output:

[docker://xxx:5000/xxx/xxx:latest/]:php /opt/project/vendor/phpunit/phpunit/phpunit --configuration /opt/project/phpunit.xml Tests\MockTest /opt/project/tests/MockTest.php --teamcity
PHPUnit 8.1.4 by Sebastian Bergmann and contributors.

PHP Fatal error:  Cannot override final method Exception::getMessage() in /opt/project/vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php(627) : eval()'d code on line 1
PHP Stack trace:
PHP   1. {main}() /opt/project/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /opt/project/vendor/phpunit/phpunit/phpunit:61
PHP   3. PHPUnit\TextUI\Command->run() /opt/project/vendor/phpunit/phpunit/src/TextUI/Command.php:163
PHP   4. PHPUnit\TextUI\TestRunner->doRun() /opt/project/vendor/phpunit/phpunit/src/TextUI/Command.php:207
PHP   5. PHPUnit\Framework\TestSuite->run() /opt/project/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:613
PHP   6. Tests\MockTest->run() /opt/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php:761
PHP   7. PHPUnit\Framework\TestResult->run() /opt/project/vendor/phpunit/phpunit/src/Framework/TestCase.php:808
PHP   8. Tests\MockTest->runBare() /opt/project/vendor/phpunit/phpunit/src/Framework/TestResult.php:685
PHP   9. Tests\MockTest->runTest() /opt/project/vendor/phpunit/phpunit/src/Framework/TestCase.php:854
PHP  10. Tests\MockTest->test() /opt/project/vendor/phpunit/phpunit/src/Framework/TestCase.php:1172
PHP  11. Tests\MockTest->createMock() /opt/project/tests/MockTest.php:11
PHP  12. PHPUnit\Framework\MockObject\MockBuilder->getMock() /opt/project/vendor/phpunit/phpunit/src/Framework/TestCase.php:1335
PHP  13. PHPUnit\Framework\MockObject\Generator->getMock() /opt/project/vendor/phpunit/phpunit/src/Framework/MockObject/MockBuilder.php:117
PHP  14. PHPUnit\Framework\MockObject\Generator->getObject() /opt/project/vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php:196
PHP  15. PHPUnit\Framework\MockObject\Generator->evalClass() /opt/project/vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php:581
PHP  16. eval() /opt/project/vendor/phpunit/phpunit/src/Framework/MockObject/Generator.php:627

@sebastianbergmann
Copy link
Owner

CC @morozov

@snamor
Copy link

snamor commented May 9, 2019

Having the same problem here. It seems to be related to the changes introduced with #3604 when trying to mock the final function getMessage from Exception class.

@sebastianbergmann sebastianbergmann added type/bug Something is broken and removed status/waiting-for-feedback Waiting for feedback from original reporter labels May 9, 2019
@sebastianbergmann
Copy link
Owner

I can reproduce this with

<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;

class Test extends TestCase
{
    public function testOne(): void
    {
        $this->createMock(\Throwable::class);
    }
}

@morozov
Copy link
Contributor

morozov commented May 9, 2019

Thank you all for the information. I should be able to provide a fix within a few days.

@sebastianbergmann sebastianbergmann changed the title #3596 broke mocking DriverExceptions for us Regression in PHPUnit 7.5.10 with regard to Exception stubbing/mocking May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

5 participants