I'm setting up a Symfony 4.2.2 application, and I want to run functional tests with Gitlab-CI. But I'm facing this issue:
A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0.
The strange thing is I've got this issue localy but only the first time I run unit tests after a cache rebuild. The second time I run unit tests, the error is not triggered anymore.
I'm using version 5.2.4 of sensio/framework-extra-bundle which should have fix the issue, as said here.
This error makes my job fail everytime, even though all tests are OK.
I made sure to use the class Symfony\Bundle\FrameworkBundle\Test\WebTestCase
in my functional tests.
I also made sure to have all my dependencies up to date.
Here is an example of a functional test I wrote:
<?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());
}
}
And here is my CI config:
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
I expect the output to show all tests passed, but the actual output is:
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
Thanks to @SergheiNiculaev, I just added the following line in phpunit.xml.dist
file:
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
[EDIT] Another solution consists in adding the following line in the CI config file:
variables:
# ...
SYMFONY_DEPRECATIONS_HELPER: weak
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With