php - 自 Symfony 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/framework-extra-bundle 的 5.2.4 版本,它应该可以解决问题,如此处所述。
这个错误使我的工作每次都失败,即使所有测试都正常。
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
解决方案
感谢@SergheiNiculaev,我刚刚在phpunit.xml.dist
文件中添加了以下行:
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
[编辑] 另一种解决方案是在 CI 配置文件中添加以下行:
variables:
# ...
SYMFONY_DEPRECATIONS_HELPER: weak
推荐阅读
- javascript - 未捕获的类型错误:无法在 Laravel 的倒数计时器中设置属性 'textContent' 为 null
- cuda - 如何在 CUDA 上对 struct 应用原子操作?
- webpack - webpack 捆绑后 React-dom 和 Webpack 的巨大尺寸
- javascript - 如何比较日期并从选择列表中选择选项?
- azure - 为什么自定义 AI 的 Azure 机器学习工作室不支持 Java
- javascript - 制表符 - 更新货币列自定义编辑器的值
- java - 如何在kotlin中覆盖java类属性变量
- python - 防止函数修改列表
- python-requests - 将登录名从 mechanize 转移到 urllib 或 requests
- python - 使用 rpy2 在 Python 中使用 R 中的包时遇到问题