Skip to content

registerForTearDown must remove PHPUnit listener once disable is called #74

Closed
@mvorisek

Description

@mvorisek

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions