New in Symfony 2.2: Functional Tests Speed-Up
Contributed by
Fabien Potencier
in #4897.
When writing functional tests, having access to the Symfony profiler can be very useful. You can use it to verify that a given page executes less than a certain number of database queries (read the dedicated cookbook entry), to check the time spent in the framework, or to test any other data collected during the request handling. But that comes with a cost as the profiler slows down the handling of a request quite a bit.
As of Symfony 2.2, the profiler is disabled by default in functional tests (at least in the default configuration that comes with the Standard Edition):
1 2 3 4 | # in app/config/config_test.yml
framework:
profiler:
enabled: false
|
Even if it is disabled by default, you can still explicitly enable it for the very next request when you need it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public function testIndex()
{
$client = static::createClient();
// Enable the profiler for the next request
// it does nothing if the profiler is not available
$client->enableProfiler();
$crawler = $client->request('GET', '/hello/Fabien');
// ... write some assertions about the Response
// Check that the profiler is enabled
if ($profile = $client->getProfile()) {
// check the number of requests
$this->assertLessThan(10, $profile->getCollector('db')->getQueryCount());
}
}
|
Free performance improvement is always nice!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
New in Symfony 2.2: Functional Tests Speed-Up symfony.com/blog/new-in-symfony-2-2-functional-tests-speed-up
Tweet thisComments
One small side note: The option is called "enabled" and not "enable" as it is mentioned in the snippet.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Vazgen Manukyan said on Jan 17, 2013 at 00:05 #1