Skip to content

Commit 41de7f3

Browse files
committed
Merge branch '2.0' into 2.1
2 parents e741967 + 9ddbceb commit 41de7f3

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

book/testing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ Learn more
765765
* :doc:`/cookbook/testing/http_authentication`
766766
* :doc:`/cookbook/testing/insulating_clients`
767767
* :doc:`/cookbook/testing/profiling`
768+
* :doc:`/cookbook/testing/bootstrap`
768769

769770

770771
.. _`DemoControllerTest`: https://github.com/symfony/symfony-standard/blob/master/src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
* :doc:`/cookbook/testing/insulating_clients`
133133
* :doc:`/cookbook/testing/profiling`
134134
* :doc:`/cookbook/testing/doctrine`
135+
* :doc:`/cookbook/testing/bootstrap`
135136

136137
* :doc:`/cookbook/validation/index`
137138

cookbook/testing/bootstrap.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
How to customize the Bootstrap Process before running Tests
2+
===========================================================
3+
4+
Sometimes when running tests, you need to do additional bootstrap work before
5+
running those tests. For example, if you're running a functional test and
6+
have introduced a new translation resource, then you will need to clear your
7+
cache before running those tests. This cookbook covers how to do that.
8+
9+
First, add the following file::
10+
11+
// app/tests.bootstrap.php
12+
if (isset($_ENV['BOOTSTRAP_CLEAR_CACHE_ENV'])) {
13+
passthru(sprintf(
14+
'php "%s/console" cache:clear --env=%s --no-warmup',
15+
__DIR__,
16+
$_ENV['BOOTSTRAP_CLEAR_CACHE_ENV']
17+
));
18+
}
19+
20+
require __DIR__.'/bootstrap.php.cache';
21+
22+
Replace the test bootstrap file ``bootstrap.php.cache`` in ``app/phpunit.xml.dist``
23+
with ``tests.bootstrap.php``:
24+
25+
.. code-block:: xml
26+
27+
<!-- app/phpunit.xml.dist -->
28+
bootstrap = "tests.bootstrap.php"
29+
30+
Now, you can define in your ``phpunit.xml.dist`` file which environment you want the
31+
cache to be cleared:
32+
33+
.. code-block:: xml
34+
35+
<!-- app/phpunit.xml.dist -->
36+
<php>
37+
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
38+
</php>
39+
40+
This now becomes an environment variable (i.e. ``$_ENV``) that's available
41+
in the custom bootstrap file (``tests.bootstrap.php``).

cookbook/testing/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Testing
88
insulating_clients
99
profiling
1010
doctrine
11+
bootstrap

0 commit comments

Comments
 (0)