From 6365fde761043ff7e8455afe3e9787a65f5c1137 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 18 Sep 2012 16:38:05 +0200 Subject: [PATCH] updated documentation for the profiler usage in a functional test (refs symfony/symfony#4897) --- book/testing.rst | 12 +++++++++--- cookbook/testing/profiling.rst | 10 +++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/book/testing.rst b/book/testing.rst index 6f501816d3e..c9de7365a34 100644 --- a/book/testing.rst +++ b/book/testing.rst @@ -415,13 +415,19 @@ HTTP layer. For a list of services available in your application, use the Accessing the Profiler Data ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -On each request, the Symfony profiler collects and stores a lot of data about -the internal handling of that request. For example, the profiler could be -used to verify that a given page executes less than a certain number of database +On each request, you can enable the Symfony profiler to collect data about the +internal handling of that request. For example, the profiler could be used to +verify that a given page executes less than a certain number of database queries when loading. To get the Profiler for the last request, do the following:: + // enable the profiler for the very next request + $client->enableProfiler(); + + $crawler = $client->request('GET', '/profiler'); + + // get the profile $profile = $client->getProfile(); For specific details on using the profiler inside a test, see the diff --git a/cookbook/testing/profiling.rst b/cookbook/testing/profiling.rst index 8a8055bf278..ee92790c760 100644 --- a/cookbook/testing/profiling.rst +++ b/cookbook/testing/profiling.rst @@ -11,15 +11,19 @@ various things and enforce some metrics. The Symfony2 :ref:`Profiler ` gathers a lot of data for each request. Use this data to check the number of database calls, the time -spent in the framework, ... But before writing assertions, always check that -the profiler is indeed available (it is enabled by default in the ``test`` -environment):: +spent in the framework, ... But before writing assertions, enable the profiler +and check that the profiler is indeed available (it is enabled by default in +the ``test`` environment):: class HelloControllerTest extends WebTestCase { 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