Skip to content

registerForTearDown must remove PHPUnit listener once disable is called #74

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

Closed
mvorisek opened this issue Dec 10, 2024 · 2 comments · Fixed by #78
Closed

registerForTearDown must remove PHPUnit listener once disable is called #74

mvorisek opened this issue Dec 10, 2024 · 2 comments · Fixed by #78

Comments

@mvorisek
Copy link

mvorisek commented Dec 10, 2024

repro code:

use phpmock\environment\SleepEnvironmentBuilder;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;

class DistributedMutexTest extends TestCase
{
    use PHPMock;

    #[\Override]
    protected function setUp(): void
    {
        parent::setUp();

        $sleepBuilder = new SleepEnvironmentBuilder();
        $sleepBuilder->addNamespace(__NAMESPACE__);
        $sleep = $sleepBuilder->build();
        $sleep->enable();
        $this->registerForTearDown($sleep);

        global $i;
        $i++;
    }
}

and

        global $i;
        var_dump($i);

added in https://github.com/php-mock/php-mock/blob/2.5.1/classes/environment/MockEnvironment.php#L71

and PHPUnit launched with --repeat 1000

Currently somethings like this is output:

int(1)
int(2)
int(2)
int(3)
int(3)
int(3)
...

confirming that the https://github.com/php-mock/php-mock/blob/2.5.1/classes/environment/MockEnvironment.php#L71 code needs to not only add the listener, but also wrap the Deactivatable instance which will remove the listener once called.

The current implementation is slower with every test repeat and unusable with higher repeat counts.

@michalbundyra
Copy link
Member

@mvorisek thanks for reporting the issue. Would you be able to confirm what version of PHPUnit are you using? Thanks

@mvorisek
Copy link
Author

mvorisek commented Mar 9, 2025

I am not on PC now, but the issue is present at least with PHPUnit v9 and v10, not sure if both, but at least on one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants