liip / LiipFunctionalTestBundle

Some helper classes for writing functional tests in Symfony
http://liip.ch
MIT License
639 stars 182 forks source link

Enabling bundle causes significant overhead? #446

Open rpander93 opened 6 years ago

rpander93 commented 6 years ago

Hi all,

I'm working on an app using Symfony4.1 and I noticed my testsuite becoming incredibly slow with this bundle enabled. Some debugging showed me that the container is initialized multiple times per test, causing the cache to get recreated also.

I refactored my test to use the WebTestCase provided by Symfony rather than the one provided by this bundle. That already helped somewhat. If I disable the bundle completely in bundles.php, the issue vanishes completely.

In the end, the time required for 1 test class with 2 tests drops from 1.5m to 4s.

Preconditions

  1. Symfony 4.1
  2. PHP 7.2
  3. Bundle version 2.0@alpha

Steps to reproduce

  1. Enable bundle using Symfony Flex
  2. Create functional test extending WebTestCase from this bundle
  3. Execute some tests using the client and grab some services from the container in the test

Expected result

  1. Container should not be recompiled every time.

Actual result

  1. Some debug output in Kernel.php shows me that the container is initialized multiple times and the cache warmer is executed also every time.
rpander93 commented 6 years ago

This is my test class: https://gist.github.com/rpander93/97c37a7b33b0eddd8e76be0f3f83a741

Debugging output by placing some lines in WebTestCase.php and Kernel.php:

Creating kernel for cache: test Initializing container... executing cache warmer.... Initializing container... executing cache warmer.... Creating kernel for cache: test Initializing container... executing cache warmer.... Initializing container... executing cache warmer....

alexislefebvre commented 5 years ago

A possible solution: use traits instead of inheriting from the big test class, see https://github.com/liip/LiipFunctionalTestBundle/issues/332#issuecomment-329958638