Skip to content

Commit 308c4a1

Browse files
committed
Merge pull request #1727 from symfony/profiler
updated documentation for the profiler usage in a functional test
2 parents 9118861 + 6365fde commit 308c4a1

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

book/testing.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,19 @@ HTTP layer. For a list of services available in your application, use the
415415
Accessing the Profiler Data
416416
~~~~~~~~~~~~~~~~~~~~~~~~~~~
417417

418-
On each request, the Symfony profiler collects and stores a lot of data about
419-
the internal handling of that request. For example, the profiler could be
420-
used to verify that a given page executes less than a certain number of database
418+
On each request, you can enable the Symfony profiler to collect data about the
419+
internal handling of that request. For example, the profiler could be used to
420+
verify that a given page executes less than a certain number of database
421421
queries when loading.
422422

423423
To get the Profiler for the last request, do the following::
424424

425+
// enable the profiler for the very next request
426+
$client->enableProfiler();
427+
428+
$crawler = $client->request('GET', '/profiler');
429+
430+
// get the profile
425431
$profile = $client->getProfile();
426432

427433
For specific details on using the profiler inside a test, see the

cookbook/testing/profiling.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ various things and enforce some metrics.
1111

1212
The Symfony2 :ref:`Profiler <internals-profiler>` gathers a lot of data for
1313
each request. Use this data to check the number of database calls, the time
14-
spent in the framework, ... But before writing assertions, always check that
15-
the profiler is indeed available (it is enabled by default in the ``test``
16-
environment)::
14+
spent in the framework, ... But before writing assertions, enable the profiler
15+
and check that the profiler is indeed available (it is enabled by default in
16+
the ``test`` environment)::
1717

1818
class HelloControllerTest extends WebTestCase
1919
{
2020
public function testIndex()
2121
{
2222
$client = static::createClient();
23+
24+
// Enable the profiler for the next request (it does nothing if the profiler is not available)
25+
$client->enableProfiler();
26+
2327
$crawler = $client->request('GET', '/hello/Fabien');
2428

2529
// ... write some assertions about the Response

0 commit comments

Comments
 (0)