File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ How to automatically clear the cache before tests are run
2
+ =========================================================
3
+
4
+ Some features need the cache to be cleared in order to work.
5
+ You could have tests failing, because some part of the cache would need to
6
+ be cleared. (For example, new translation resources)
7
+
8
+ It's a good idea to clear the cache before running your tests, and automate it
9
+ is even better.
10
+
11
+ Add the following file::
12
+
13
+ // app/tests.bootstrap.php
14
+ if (isset($_ENV['BOOTSTRAP_CLEAR_CACHE_ENV'])) {
15
+ passthru(sprintf(
16
+ 'php "%s/console" cache:clear --env=%s --no-warmup',
17
+ __DIR__,
18
+ $_ENV['BOOTSTRAP_CLEAR_CACHE_ENV']
19
+ ));
20
+ }
21
+
22
+ require __DIR__.'/bootstrap.php.cache';
23
+
24
+ Replace the test bootstrap file ``bootstrap.php.cache `` in `app/phpunit.xml ` by
25
+ ``tests.bootstrap.php ``:
26
+
27
+ .. code-block :: xml
28
+
29
+ <!-- app/phpunit.xml -->
30
+ bootstrap = "tests.bootstrap.php"
31
+
32
+ And then, you can define in your `phpunit.xml ` file which environment you want the
33
+ cache to be cleared:
34
+
35
+ .. code-block :: xml
36
+
37
+ <!-- app/phpunit.xml -->
38
+ <php >
39
+ <env name =" BOOTSTRAP_CLEAR_CACHE_ENV" value =" test" />
40
+ </php >
41
+
You can’t perform that action at this time.
0 commit comments