树构建器而不会在功能测试由于Symfony的4.2弃用根节点

问题描述 投票:4回答:2

我设置了一个Symfony的4.2.2应用程序,我想运行与Gitlab-CI功能测试。但我现在面临这个问题:

A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0.

奇怪的是我有这个问题,但当地只有我第一次缓存后运行单元测试重建。我运行单元测试,第二次,不再被触发的错误。

我使用SENSIO /框架-EXTRA束的5.2.4版本,它应该有解决这个问题,因为说here

这个错误让我的工作每次失败,即使所有的测试都OK。

我确信使用类Symfony\Bundle\FrameworkBundle\Test\WebTestCase在我的功能测试。我还相信有我所有的依赖是最新的。

这是一个功能测试我写的一个例子:

<?php

namespace App\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
 * Class MigrationControllerTest
 *
 * @group functional
 */
class MigrationControllerTest extends WebTestCase
{
    public function testNotAllowed()
    {
        $client = static::createClient();

        $client->request('UPDATE', '/migrate');
        $this->assertEquals(405, $client->getResponse()->getStatusCode());
    }
}

这里是我的CI配置:

image: my.private.repo/images/php/7.2/symfony:latest

cache:
  paths:
    - vendor/

before_script:
  - composer install

services:
  - mysql:5.7

unit_test:
  script:
    # Set up database
    - bin/console doctrine:schema:update --env=test --force
    # Load fixtures
    - bin/console doctrine:fixtures:load --env=test --no-interaction
    # Build assets with Webpack Encore
    - npm install
    - npm run build
    # Enable xdebug for code coverage
    - docker-php-ext-enable xdebug
    # Run unit tests
    - php bin/phpunit --coverage-text --colors=never

我希望输出显示所有测试通过,但实际产量为:

PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Testing Project Test Suite
.2019-02-04T14:48:29+01:00 [error] Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: "No route found for "UPDATE /migrate": Method Not Allowed (Allow: GET, POST)" at /home/goulven/PhpStorm/user-balancer/vendor/symfony/http-kernel/EventListener/RouterListener.php line 143
.........                                                        10 / 10 (100%)

Time: 8.44 seconds, Memory: 52.25MB

OK (10 tests, 17 assertions)

Remaining deprecation notices (4)

  4x: A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0.
    4x in MigrationControllerTest::testMigrateFail from App\Tests\Controller
php symfony4 gitlab-ci-runner
2个回答
1
投票

由于@SergheiNiculaev,我只是说在phpunit.xml.dist文件中的以下行:

<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>

[编辑]另一种解决方案在于增加在CI配置文件中的下列行:

variables:
  # ...
  SYMFONY_DEPRECATIONS_HELPER: weak

0
投票

如果发生这种情况仅在第一次,这意味着高速缓存预热在错误被触发。如果你不想要搜索的根本原因,热身添加到您的before_script这样的:

- php bin/console cache:warmup --env=test

这确保了被执行之前,首先测试用例,使得你的测试用例不被集装箱建筑问题影响缓存容器建成

© www.soinside.com 2019 - 2024. All rights reserved.