6

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
lobodol
  • 184
  • 2
  • 12
  • Hello and welcome to the StackOverflow community. Just disable deprecation notices - https://stackoverflow.com/questions/28850809/disable-deprecated-warning-in-symfony-2-7 – Serghei Niculaev Feb 04 '19 at 14:45
  • Thank you @SergheiNiculaev, this is exactly what I needed. I just added the following line to my `phpunit.xml.dist` file : ```xml ``` – lobodol Feb 04 '19 at 15:26
  • Glad your problem is solved. Also you can do it by adding this code to your CI config, if you want: https://stackoverflow.com/a/41775356/3127223 – Serghei Niculaev Feb 04 '19 at 15:30

2 Answers2

3

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
lobodol
  • 184
  • 2
  • 12
  • 3
    I don't want to be rude but that is not a good idea. Check where that notice really comes from and fix that issue. It is not given to annoy you, but to tell you that you need to act before upgrading to the next Symfony version – Nico Haase Feb 06 '19 at 10:32
0

If this happens only on first time, that means that the error is triggered during cache warmup. If you don't want to search for the root cause, add the warmup to your before_script like:

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

This ensures that the cached container is built before the first testcase is executed such that your test cases are not influenced by container building problems

Nico Haase
  • 11,420
  • 35
  • 43
  • 69