Symfony2单元测试产生致命错误:ContainerAwareEventManager :: removeEventListener()的声明必须与

时间:2015-03-11 07:41:36

标签: unit-testing symfony controller phpunit fatal-error

在非常简单的标准测试中调用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>

这是非常简单的测试类:

<?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)

当然仍然是捆绑/ Symfony2中的原始版本。 通常,symfony2或corebundles中没有任何内容被更改,只是我们自己的包。

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


编辑:

如下面的评论所述,我也尝试了以下方法:

  • 将Symfony从2.4升级到2.6 - &gt;没有成功,同样的错误
  • 降级一些学说包 - &gt;没有成功,同样的错误

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.*"
},

1 个答案:

答案 0 :(得分:0)

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

我安装了“PHPUnit 4.1.6-6-g43914fa”,您可以在上面的输出中看到。

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