错误:找不到类'Symfony \ Component \ Config \ Resource \ BCResourceInterfaceChecker'

问题描述

我将应用程序从symfony 2.8迁移到symfony 3.4。

在Web中,它运行良好。但是当我启动功能测试时,我得到了以下结果:

▶ ./bin/PHPunit --filter=testLanguageControllerTestIndexAction                                   
    PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
    
E                                                                   1 / 1 (100%)

Time: 126 ms,Memory: 14.00MB

There was 1 error:

1) Tests\TranslationBundle\Controller\LanguageControllerTest::testLanguageControllerTestIndexAction
Error: Class 'Symfony\Component\Config\Resource\BCResourceInterfaceChecker' not found

/var/www/renault-del/del/src/app/bootstrap.PHP.cache:3183
/var/www/renault-del/del/src/app/bootstrap.PHP.cache:2778
/var/www/renault-del/del/src/app/bootstrap.PHP.cache:2561
/var/www/renault-del/del/src/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.PHP:174
/var/www/renault-del/del/src/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.PHP:34
/var/www/renault-del/del/src/tests/TranslationBundle/Controller/LanguageControllerTest.PHP:22

ERRORS!
Tests: 1,Assertions: 0,Errors: 1.

顺便说一下,这就是我的composer.json:

"require": {
    "PHP": "^7.2","course-hero/wse-PHP": "~2.0.5","doctrine/doctrine-bundle": "^1.6","doctrine/doctrine-fixtures-bundle": "^2.4","doctrine/orm": "^2.5","friendsofsymfony/rest-bundle" : "^2.1","friendsofsymfony/user-bundle": "^2.1","guzzlehttp/guzzle": "^5.3","ijanki/ftp-bundle": "<1.0.3","jms/serializer-bundle" : "^1.1","knplabs/knp-snappy-bundle": "1.6.*","natxet/cssmin": "^3.0","nelmio/api-doc-bundle" : "^3.0","patchwork/jsqueeze": "^2.0","select2/select2": "^4.0","sensio/distribution-bundle": "^5.0","sensio/framework-extra-bundle": "4.0.0","sonata-project/doctrine-orm-admin-bundle": "3.7.0","stof/doctrine-extensions-bundle": "~1.2.0","symfony/assetic-bundle": "^2.8","symfony/monolog-bundle": "^2.8","symfony/swiftmailer-bundle": "^2.3","symfony/symfony": "3.4.*","twig/twig": "^2.12","friendsofsymfony/ckeditor-bundle": "^1.2","white-october/pagerfanta-bundle": "^1.3","liip/imagine-bundle": "^1.9","friendsofsymfony/oauth-server-bundle": "^1.6","psr/container": "^1.0"
},"require-dev": {
    "friendsofPHP/PHP-cs-fixer" : "@stable","PHPunit/PHPunit":  "~5.1","symfony/PHPunit-bridge": "^5.1"
},

此外,这是 CHANGELOG ,从 2.8.0 3.0.0

3.0.0

 * removed `ReferenceDumper` class
 * removed the `ResourceInterface::isFresh()` method
 * removed `BCResourceInterfaceChecker` class
 * removed `ResourceInterface::getResource()` method

那我该怎么办?

解决方法

最后我找到了解决方法。

因此,在从 Symfony 2.8 迁移到 symfony 3.4 之后,您必须将 bootstrap.php.cache 文件从“ app ”文件夹中的“ var ”文件夹中,因此,您必须在 phpunit.xml 配置中修改此文件的路径。

<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="var/bootstrap.php.cache"
>
    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

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

    <filter>
        <whitelist>
            <directory>tests</directory>
        </whitelist>
    </filter>
</phpunit>