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

Mocks do not fail immedately on unexpected calls #27

Closed
Jean85 opened this issue Oct 7, 2020 · 2 comments
Closed

Mocks do not fail immedately on unexpected calls #27

Jean85 opened this issue Oct 7, 2020 · 2 comments

Comments

@Jean85
Copy link
Contributor

Jean85 commented Oct 7, 2020

I've migrated to this trait since PHPUnit deprecated its integration with Prophecy.

I've struggled a little since then, but I've now found the root of my issue: mocks are not failing immediately as before.

This is a reproducer:

<?php

declare(strict_types=1);

class MockRegressionTest extends \PHPUnit\Framework\TestCase
{
    use ProphecyTrait;

    public function test(): void
    {
        $prophecy = $this->prophesize(\PHPUnit\Framework\TestSuite::class);
        $prophecy->addTestFile('foo.php')
            ->shouldBeCalledOnce();

        $prophecy->reveal()
            ->addTestFile('bar.php'); // should fail here

        $this->fail('If we got here, we have some trouble'); // goes on and fails here
    }
}

Test should fail immediately when calling the method with the wrong argument, but it doesn't. This leads to the mock returning null and either failing with a TypeError or going further, making the test failure a lot harder to debug.

Copying this reproducer into a PHPSpec test gets the right behavior.

Thanks to @DonCallisto for the help debugging this issue.

Jean85 added a commit to Jean85/prophecy-phpunit that referenced this issue Oct 7, 2020
@Jean85
Copy link
Contributor Author

Jean85 commented Oct 8, 2020

I'm investigating further, and it seems that this is in reality due to phpspec/prophecy#457 and related to phpspec/prophecy#441

@stof
Copy link
Member

stof commented Mar 27, 2024

Closing in favor of phpspec/prophecy#508

@stof stof closed this as completed Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants