Symfony2 unit tests produces Fatal Error: Declaration of ContainerAwareEventManager::removeEventListener() must be compatible with

Symfony2 unit tests produces Fatal Error: Declaration of ContainerAwareEventManager::removeEventListener() must be compatible with

在一个非常简单的标准测试中调用 phpunit 时,它会产生以下输出和错误:

命令(在 symfony2 root 中):

phpunit -c build/ src

输出:

PHPUnit 4.1.6-6-g43914fa by Sebastian Bergmann.

Configuration read from /srv/xxxxxxxxx/build/phpunit.xml

PHP Fatal error:  Declaration of Symfony\Bridge\Doctrine\ContainerAwareEventManager::removeEventListener() must be compatible with Doctrine\Common\EventManager::removeEventListener($events, $listener = NULL) in /srv/xxxxxxxxx/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php on line 141
PHP Stack trace:
PHP   1. {main}() /usr/local/composer/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/local/composer/vendor/phpunit/phpunit/phpunit:57
PHP   3. PHPUnit_TextUI_Command->run() /usr/local/composer/vendor/phpunit/phpunit/src/TextUI/Command.php:132
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/composer/vendor/phpunit/phpunit/src/TextUI/Command.php:179
PHP   5. PHPUnit_Framework_TestSuite->run() /usr/local/composer/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:426
PHP   6. PHPUnit_Framework_TestSuite->run() /usr/local/composer/vendor/phpunit/phpunit/src/Framework/TestSuite.php:699
PHP   7. PHPUnit_Framework_TestCase->run() /usr/local/composer/vendor/phpunit/phpunit/src/Framework/TestSuite.php:699
PHP   8. PHPUnit_Framework_TestResult->run() /usr/local/composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:760
PHP   9. PHPUnit_Framework_TestCase->runBare() /usr/local/composer/vendor/phpunit/phpunit/src/Framework/TestResult.php:686
PHP  10. PHPUnit_Framework_TestCase->runTest() /usr/local/composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:826
PHP  11. ReflectionMethod->invokeArgs() /usr/local/composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:962
PHP  12. Syw\Admin\CoreBundle\Tests\Controller\DebugControllerTest->testIndex() /usr/local/composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:962
PHP  13. Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient() /srv/xxxxxxxxx/src/Syw/Admin/CoreBundle/Tests/Controller/DebugControllerTest.php:13
PHP  14. Symfony\Component\HttpKernel\Kernel->boot() /srv/xxxxxxxxx/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:47
PHP  15. Symfony\Component\HttpKernel\Kernel->initializeContainer() /srv/xxxxxxxxx/app/bootstrap.php.cache:2300
PHP  16. Symfony\Component\DependencyInjection\ContainerBuilder->compile() /srv/xxxxxxxxx/app/bootstrap.php.cache:2521
PHP  17. Symfony\Component\DependencyInjection\Compiler\Compiler->compile() /srv/xxxxxxxxx/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:619
PHP  18. JMS\AopBundle\DependencyInjection\Compiler\PointcutMatchingPass->process() /srv/xxxxxxxxx/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:117
PHP  19. JMS\AopBundle\DependencyInjection\Compiler\PointcutMatchingPass->processInlineDefinitions() /srv/xxxxxxxxx/vendor/jms/aop-bundle/JMS/AopBundle/DependencyInjection/Compiler/PointcutMatchingPass.php:66
PHP  20. JMS\AopBundle\DependencyInjection\Compiler\PointcutMatchingPass->processDefinition() /srv/xxxxxxxxx/vendor/jms/aop-bundle/JMS/AopBundle/DependencyInjection/Compiler/PointcutMatchingPass.php:85
PHP  21. class_exists() /srv/xxxxxxxxx/vendor/jms/aop-bundle/JMS/AopBundle/DependencyInjection/Compiler/PointcutMatchingPass.php:110
PHP  22. spl_autoload_call() /srv/xxxxxxxxx/vendor/jms/aop-bundle/JMS/AopBundle/DependencyInjection/Compiler/PointcutMatchingPass.php:110
PHP  23. Composer\Autoload\ClassLoader->loadClass() /srv/xxxxxxxxx/vendor/jms/aop-bundle/JMS/AopBundle/DependencyInjection/Compiler/PointcutMatchingPass.php:0
PHP  24. Composer\Autoload\includeFile() /usr/local/composer/vendor/composer/ClassLoader.php:301

这是 [symfony-root]/build 中的 phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
    backupGlobals               = "false"
    backupStaticAttributes      = "false"
    colors                      = "true"
    convertErrorsToExceptions   = "true"
    convertNoticesToExceptions  = "true"
    convertWarningsToExceptions = "true"
    processIsolation            = "false"
    stopOnFailure               = "false"
    syntaxCheck                 = "false"
    bootstrap                   = "../app/bootstrap.php.cache" >

    <php>
        <server name="KERNEL_DIR" value="app/" />
    </php>

    <testsuites>
        <testsuite name="Onlinexxxxxxxxx Test Suite">
            <directory>src/*/*Bundle/Tests</directory>
            <directory>src/*/*/*Bundle/Tests</directory>
        </testsuite>
    </testsuites>

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

    <logging>
        <log type="coverage-html" target="../build/coverage" title="GMS" charset="UTF-8" yui="true" highlight="true"
             lowUpperBound="35" highLowerBound="70"/>
        <log type="coverage-clover" target="../build/logs/clover.xml"/>
        <log type="junit" target="../build/logs/junit.xml" logIncompleteSkipped="false"/>
    </logging>

</phpunit>

这是非常简单的测试 class:

<?php

namespace Syw\Admin\CoreBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DebugControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = static::createClient();

        $crawler = $client->request('GET', '/debug');
    }

    public function testDetail()
    {
        $client = static::createClient();

        $crawler = $client->request('GET', '/detail');
    }
}

如有任何帮助,我们将不胜感激。

顺便说一句,

Symfony\Bridge\Doctrine\ContainerAwareEventManager::removeEventListener()

Doctrine\Common\EventManager::removeEventListener($events, $listener = NULL)

当然还是bundles/Symfony2的原版。 通常 symfony2 或 corebundle 中的任何东西都没有改变,只有我们自己的包。

顺便说一下 (#2):我们正在使用 Symfony 2.4(但我也尝试升级到 Symfony 2.6,但没有解决这个问题)


编辑:

就像下面评论中提到的,我也尝试了以下方法:

composer.json实际上看起来是这样的(对于要求):

"require": {
  "ali/datatable": "dev-master",
  "doctrine/data-fixtures": "dev-master",
  "doctrine/doctrine-bundle": "~1.2",
  "doctrine/doctrine-fixtures-bundle": "dev-master",
  "doctrine/doctrine-migrations-bundle": "2.1.*@dev",
  "doctrine/migrations": "1.0.*@dev",
  "doctrine/orm": "~2.2,>=2.2.3",
  "dropbox/dropbox-sdk": "1.1.*",
  "friendsofsymfony/rest-bundle": "@dev",
  "gedmo/doctrine-extensions": "dev-master",
  "google-api-php-client": "0.6.7",
  "hybridauth/hybridauth": "3.0.0.*@dev",
  "incenteev/composer-parameter-handler": "~2.0",
  "jms/i18n-routing-bundle": "dev-master",
  "jms/security-extra-bundle": "dev-master",
  "jms/serializer-bundle": "@dev",
  "knplabs/knp-paginator-bundle": "dev-master",
  "languagedetect": "1.0",
  "languagetool": "2.8",
  "lexik/maintenance-bundle": "dev-master",
  "misd/guzzle-bundle": "~1.0",
  "nelmio/api-doc-bundle": "@dev",
  "nelmio/cors-bundle": "~1.0",
  "php": ">=5.3.3",
  "sensio/distribution-bundle": "2.3.*",
  "sensio/framework-extra-bundle": "~3.0",
  "sensio/generator-bundle": "~2.3",
  "stfalcon/tinymce-bundle": "dev-master",
  "stof/doctrine-extensions-bundle": "~1.1@dev",
  "symfony/assetic-bundle": "2.3.*",
  "symfony/monolog-bundle": "2.3.*",
  "symfony/swiftmailer-bundle": "2.3.*",
  "symfony/symfony": "2.4.*",
  "twig/extensions": "1.0.*"
},

好的...经过许多小时的测试和尝试降级、升级和所有这些事情之后,我现在发现,问题仅仅是 phpunit 本身。

我已经安装了 "PHPUnit 4.1.6-6-g43914fa",如您在上面的输出中所见。

我现在已经降级到 3.7.13 ("phpunit/phpunit": "~3.6") 并且没有任何问题。