Unit testing Symfony2单元测试产生致命错误:ContainerWareeEventManager::removeEventListener()的声明必须与兼容

Unit testing Symfony2单元测试产生致命错误:ContainerWareeEventManager::removeEventListener()的声明必须与兼容,unit-testing,symfony,controller,phpunit,fatal-error,Unit Testing,Symfony,Controller,Phpunit,Fatal Error,在一个非常简单的标准测试上调用phpunit时,它会产生以下输出和错误: 命令(在symfony2根目录中): 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\Contain

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

命令(在symfony2根目录中):

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
<?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>
<?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');
    }
}
输出:

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
<?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>
<?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 root]/build:

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
<?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>
<?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');
    }
}

Doctrine\Common\EventManager::removeEventListener($events, $listener = NULL)
当然仍然是bundles/Symfony2中的原始版本。 通常symfony2或corebundles中没有任何更改,只有我们自己的包

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


编辑:

正如下面的评论中提到的,我也尝试了以下几点:

  • 将Symfony从2.4升级到2.6->未成功,相同错误
  • 降级某些条令包->不成功,相同错误
实际上,composer.json看起来是这样的(对于需求):


好的。。。在经历了许多、许多小时的降级、升级等测试和尝试之后,我现在发现,问题仅仅在于phpunit本身

我安装了“phpunit4.1.6-6-g43914fa”,正如您在上面的输出中所看到的


我现在已经降级到了3.7.13(“phpunit/phpunit”:“~3.6”),这是没有任何问题的

在Symfony\Bridge中,是Doctrine等工具包的适配器。您的symfony/条令桥接器与条令不兼容。您可以尝试在撰写文件中使用master。事实上,如果信条没有任何改变,symfony不会提供新的桥梁。如果条令不起作用,也许你必须降级。@Aitch我已经尝试过将symfony从2.4升级到2.6,但没有成功。然后在你发表评论之后,我尝试将条令/普通(从~2.3降到~2.2)和条令/条令包(从~1.3降到~1.0)也没有任何运气-总是相同的错误…创建一个空文件夹,安装symfony with composer,然后查看版本并将它们添加到你的
composer.json
。然后
composer update
not
install
@Aitch谢谢你的提示,我已经在上面的问题末尾添加了我尝试过的东西(以及结果)。