Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit36a933e

Browse files
committed
minor#8705 Updated testing/* articles to Symfony 4 (javiereguiluz)
This PR was squashed before being merged into the master branch (closes#8705).Discussion----------Updated testing/* articles to Symfony 4Commits-------d396d8a Fixed everything62228ec Updated testing/* articles to Symfony 4
2 parentsab4410e +d396d8a commit36a933e

File tree

4 files changed

+83
-103
lines changed

4 files changed

+83
-103
lines changed

‎testing.rst‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,26 @@ As an example, a test could look like this::
158158

159159
..tip::
160160

161-
To run your functional tests, the ``WebTestCase`` class bootstraps the
162-
kernel of your application. In most cases, this happens automatically.
163-
However, if your kernel is in a non-standard directory, you'll need
164-
to modify your ``phpunit.xml.dist`` file to set the ``KERNEL_DIR``
165-
environment variable to the directory of your kernel:
161+
To run your functional tests, the ``WebTestCase`` class needs to know which
162+
is the application kernel to bootstrap it. The kernel class is usually
163+
defined in the ``KERNEL_CLASS`` environment variable (included in the
164+
default ``phpunit.xml.dist`` file provided by Symfony):
166165

167166
..code-block::xml
168167
169168
<?xml version="1.0" charset="utf-8" ?>
170169
<phpunit>
171170
<php>
172-
<servername="KERNEL_DIR"value="/path/to/your/app/" />
171+
<!-- the value is the FQCN of the application kernel-->
172+
<envname="KERNEL_CLASS"value="App\Kernel" />
173173
</php>
174174
<!-- ...-->
175175
</phpunit>
176176
177+
If your use case is more complex, you can also override the
178+
``createKernel()`` or ``getKernelClass()`` methods of your functional test,
179+
which take precedence over the ``KERNEL_CLASS`` env var.
180+
177181
The ``createClient()`` method returns a client, which is like a browser that
178182
you'll use to crawl your site::
179183

‎testing/bootstrap.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ To do this, first add a file that executes your bootstrap work::
2020

2121
require __DIR__.'/../vendor/autoload.php';
2222

23-
Then, configure ``phpunit.xml.dist`` to execute this ``bootstra.php`` file
23+
Then, configure ``phpunit.xml.dist`` to execute this ``bootstrap.php`` file
2424
before running the tests:
2525

2626
..code-block::xml

‎testing/database.rst‎

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -112,45 +112,16 @@ Most of the time you want to use a dedicated database connection to make sure
112112
not to overwrite data you entered when developing the application and also
113113
to be able to clear the database before every test.
114114

115-
To do this, you can specify a database configuration which overwrites the default
116-
configuration:
117-
118-
..configuration-block::
119-
120-
..code-block::yaml
121-
122-
# app/config/config_test.yml
123-
doctrine:
124-
# ...
125-
dbal:
126-
host:localhost
127-
dbname:testdb
128-
user:testdb
129-
password:testdb
130-
131-
..code-block::xml
132-
133-
<!-- app/config/config_test.xml-->
134-
<doctrine:config>
135-
<doctrine:dbal
136-
host="localhost"
137-
dbname="testdb"
138-
user="testdb"
139-
password="testdb"
140-
/>
141-
</doctrine:config>
142-
143-
..code-block::php
144-
145-
// app/config/config_test.php
146-
$container->loadFromExtension('doctrine', array(
147-
'dbal' => array(
148-
'host' => 'localhost',
149-
'dbname' => 'testdb',
150-
'user' => 'testdb',
151-
'password' => 'testdb',
152-
),
153-
));
154-
155-
Make sure that your database runs on localhost and has the defined database and
156-
user credentials set up.
115+
To do this, you can override the value of the ``DATABASE_URL`` env var in the
116+
``phpunit.xml.dist`` to use a diferent database for your tests:
117+
118+
..code-block::xml
119+
120+
<?xml version="1.0" charset="utf-8" ?>
121+
<phpunit>
122+
<php>
123+
<!-- the value is the Doctrine connection string in DSN format-->
124+
<envname="DATABASE_URL"value="mysql://USERNAME:PASSWORD@127.0.0.1/DB_NAME?charset=utf8mb4&serverVersion=5.7" />
125+
</php>
126+
<!-- ...-->
127+
</phpunit>

‎testing/profiling.rst‎

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,65 @@ you write functional tests that monitor your production servers, you might
99
want to write tests on the profiling data as it gives you a great way to check
1010
various things and enforce some metrics.
1111

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+
<containerxmlns="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:profilerenabled="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::
1771

1872
class LuckyControllerTest extends WebTestCase
1973
{
@@ -74,52 +128,3 @@ finish. It's easy to achieve if you embed the token in the error message::
74128

75129
Read the API for built-in:doc:`data collectors</profiler/data_collector>`
76130
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-
<containerxmlns="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:profilerenabled="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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp