sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.72k stars 2.2k forks source link

prophesize() should work with @backupStaticAttributes enabled #2016

Closed malkusch closed 7 years ago

malkusch commented 8 years ago

Using PHPUnit_Framework_TestCase::prophesize() in conjunction with @backupStaticAttributes enabled fails for repeated tests with a "Cannot redeclare class" error.

class ProphesizeWithBackupStaticAttributesTest extends \PHPUnit_Framework_TestCase
{

    /**
     * @backupStaticAttributes enabled
     * @test
     * @dataProvider provideProphesizeShouldWorkRepeatly
     */
    public function prophesizeShouldWorkRepeatly()
    {
        $this->prophesize(\Countable::class);
    }

    public function provideProphesizeShouldWorkRepeatly()
    {
        return [
            [], [], []
        ];
    }
}

Running this test with PHPUnit-5.1.3 will fail with this message:

..PHP Fatal error: Cannot redeclare class Double\Countable\P2 in … vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(49) : eval()'d code on line 2

As a hint: This issue seems to be introduced with Prophecy-1.1 and even more strangely it doesn't fail for HHVM: https://travis-ci.org/php-mock/php-mock-prophecy/builds/98688771 phpspec/prophecy@694dc3297976aa6410a236dd770bbc2adaf76e4b looks like the offending commit.

stof commented 8 years ago

This class may need to be whitelisted during the backup