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

Prevent runtime type error due to wrong return value configuration #3122

sebastianbergmann opened this issue May 12, 2018 · 0 comments


Copy link

@sebastianbergmann sebastianbergmann commented May 12, 2018

willReturn() should raise an error when a return value is configured that does not match the stubbed method's return value.

<?php declare(strict_types=1);

class C
    public function m(): int
        return 1;

final class Test extends PHPUnit\Framework\TestCase
    public function testOne(): void
        $o = $this->createMock(C::class);
        $o->method('m')->willReturn('not an integer');

Actual: TypeError when stubbed method is invoked

PHPUnit 7.1-gfafd3c555 by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)

Time: 68 ms, Memory: 4.00MB

There was 1 error:

1) Test::testOne
TypeError: Return value of Mock_C_06141907::m() must be of the type integer, string returned


Tests: 1, Assertions: 0, Errors: 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant