johnkary/phpunit-speedtrap

Fatal error with Symfony 3.4 and symfony/phpunit-bridge

lukepass opened this issue · 4 comments

Hello, when running my suite after adding the listener a fatal error occurs:

./vendor/bin/simple-phpunit                      
PHP Fatal error:  Declaration of Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7::addError(PHPUnit\Framework\Test $test, Throwable $t, float $time): void must be compatible with PHPUnit\Framework\TestListener::addError(PHPUnit\Framework\Test $test, Exception $e, $time) in /home/luca/Sites/ciudadania/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerForV7.php on line 27

My phpunit.xml.dist file is like this:


<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="vendor/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="KERNEL_CLASS" value="AppKernel" />
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>src</directory>
            <exclude>
                <directory>src/*Bundle/Resources</directory>
                <directory>src/*/*Bundle/Resources</directory>
                <directory>src/*/Bundle/*Bundle/Resources</directory>
            </exclude>
        </whitelist>
    </filter>

    <listeners>
        <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
    </listeners>
</phpunit>

Hi @lukepass,
Could you post your composer.json? I'm not caught up on how Symfony's PHPUnit bridge works and how that might be influencing running SpeedTrapListener. I hope with the composer.json I can dig in further and find where changes need to be made.

Yes, this is my composer.json:

{
    "name": "luca/base-project",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "AppBundle\\": "src/AppBundle",
            "Application\\Sonata\\UserBundle\\": "src/Application/Sonata/UserBundle",
            "Application\\Sonata\\MediaBundle\\": "src/Application/Sonata/MediaBundle"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        },
        "files": [
            "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
        ]
    },
    "require": {
        "php": ">=5.5.9",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/orm": "^2.5",
        "friendsofsymfony/rest-bundle": "^2.3",
        "greenskies/web-log-viewer-bundle": "^0.0.8",
        "incenteev/composer-parameter-handler": "^2.0",
        "jms/serializer-bundle": "^2.4",
        "leafo/scssphp": "^0.7.7",
        "patchwork/jsqueeze": "^2.0",
        "php-translation/symfony-bundle": "^0.8.1",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^5.0.0",
        "sonata-project/admin-bundle": "^3.35",
        "sonata-project/core-bundle": "dev-use-new-classes as 3.15.1",
        "sonata-project/doctrine-orm-admin-bundle": "^3.6",
        "sonata-project/easy-extends-bundle": "^2.5",
        "sonata-project/media-bundle": "^3.13",
        "sonata-project/translation-bundle": "^2.3",
        "sonata-project/user-bundle": "^4.1",
        "stof/doctrine-extensions-bundle": "^1.3",
        "symfony/assetic-bundle": "^2.8",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.6.4",
        "symfony/symfony": "3.4.*",
        "twig/twig": "^1.0||^2.0"
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.0",
        "liip/functional-test-bundle": "~2.0@alpha",
        "phpstan/phpstan": "^0.9.2",
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^4.1"
    },
    "scripts": {
        "symfony-scripts": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-install-cmd": [
            "@symfony-scripts"
        ],
        "post-update-cmd": [
            "@symfony-scripts"
        ]
    },
    "config": {
        "sort-packages": true
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-bin-dir": "bin",
        "symfony-var-dir": "var",
        "symfony-web-dir": "web",
        "symfony-tests-dir": "tests",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": null
    }
}

Thanks!

Hello @johnkary, did you have any time checking the problem? Thanks!

Hi @lukepass,
I investigated the issue a while back but could not find a solution. It appears symfony/phpunit-bridge internally switches and installs different PHPUnit binaries.

I have updated the README in master via 799c606 to note this incompatibility. Hopefully others see the note.

This issue can remain open for additional visibility and documenting the issue.

If anyone can provide a solution, please submit a PR. Also if you find it working, please comment below.