Skip to content

Commit 0d333d2

Browse files
committed
[#1735] Tweaks to the new test cache-clearing entry
This was made a little bit more generic - and also includes some minor items
1 parent 2dd4986 commit 0d333d2

File tree

4 files changed

+43
-41
lines changed

4 files changed

+43
-41
lines changed

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
* :doc:`/cookbook/testing/insulating_clients`
130130
* :doc:`/cookbook/testing/profiling`
131131
* :doc:`/cookbook/testing/doctrine`
132+
* :doc:`/cookbook/testing/bootstrap`
132133

133134
* :doc:`/cookbook/validation/index`
134135

cookbook/testing/auto_cache_clear.rst

Lines changed: 0 additions & 41 deletions
This file was deleted.

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)