@@ -9,11 +9,65 @@ you write functional tests that monitor your production servers, you might
9
9
want to write tests on the profiling data as it gives you a great way to check
10
10
various things and enforce some metrics.
11
11
12
- :doc: `The Symfony Profiler </profiler >` gathers a lot of data for
13
- each request. Use this data to check the number of database calls, the time
14
- spent in the framework, etc. 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)::
12
+ .. _speeding-up-tests-by-not-collecting-profiler-data :
13
+
14
+ Enabling the Profiler in Tests
15
+ ------------------------------
16
+
17
+ Collecting data with :doc: `the Symfony Profiler </profiler >` can slow down your
18
+ tests significantly. That's why Symfony disables it by default:
19
+
20
+ .. configuration-block ::
21
+
22
+ .. code-block :: yaml
23
+
24
+ # config/packages/test/web_profiler.yaml
25
+
26
+ # ...
27
+ framework :
28
+ profiler : { collect: false }
29
+
30
+ .. code-block :: xml
31
+
32
+ <!-- config/packages/test/web_profiler.xml -->
33
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
34
+ <container xmlns =" http://symfony.com/schema/dic/services"
35
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
36
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
37
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
38
+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
39
+
40
+ <!-- ... -->
41
+
42
+ <framework : config >
43
+ <framework : profiler enabled =" true" collect =" false" />
44
+ </framework : config >
45
+ </container >
46
+
47
+ .. code-block :: php
48
+
49
+ // config/packages/test/web_profiler.php
50
+
51
+ // ...
52
+ $container->loadFromExtension('framework', array(
53
+ // ...
54
+ 'profiler' => array(
55
+ 'enabled' => true,
56
+ 'collect' => false,
57
+ ),
58
+ ));
59
+
60
+ Setting ``collect `` to ``true `` enables the profiler for all tests. However, if
61
+ you need the profiler just in a few tests, you can keep it disabled globally and
62
+ enable the profiler individually on each test by calling
63
+ ``$client->enableProfiler() ``.
64
+
65
+ Testing the Profiler Information
66
+ --------------------------------
67
+
68
+ The data collected by the Symfony Profiler can be used to check the number of
69
+ database calls, the time spent in the framework, etc. All this information is
70
+ provided by the collectors obtained through the ``$client->getProfile() `` call::
17
71
18
72
class LuckyControllerTest extends WebTestCase
19
73
{
@@ -74,52 +128,3 @@ finish. It's easy to achieve if you embed the token in the error message::
74
128
75
129
Read the API for built-in :doc: `data collectors </profiler/data_collector >`
76
130
to learn more about their interfaces.
77
-
78
- Speeding up Tests by not Collecting Profiler Data
79
- -------------------------------------------------
80
-
81
- To avoid collecting data in each test you can set the ``collect `` parameter
82
- to false:
83
-
84
- .. configuration-block ::
85
-
86
- .. code-block :: yaml
87
-
88
- # app/config/config_test.yml
89
-
90
- # ...
91
- framework :
92
- profiler :
93
- enabled : true
94
- collect : false
95
-
96
- .. code-block :: xml
97
-
98
- <!-- app/config/config.xml -->
99
- <?xml version =" 1.0" encoding =" UTF-8" ?>
100
- <container xmlns =" http://symfony.com/schema/dic/services"
101
- xmlns : framework =" http://symfony.com/schema/dic/symfony"
102
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
103
- xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
104
- http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
105
-
106
- <!-- ... -->
107
-
108
- <framework : config >
109
- <framework : profiler enabled =" true" collect =" false" />
110
- </framework : config >
111
- </container >
112
-
113
- .. code-block :: php
114
-
115
- // app/config/config.php
116
-
117
- // ...
118
- $container->loadFromExtension('framework', array(
119
- 'profiler' => array(
120
- 'enabled' => true,
121
- 'collect' => false,
122
- ),
123
- ));
124
-
125
- In this way only tests that call ``$client->enableProfiler() `` will collect data.
0 commit comments