File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -765,6 +765,7 @@ Learn more
765
765
* :doc: `/cookbook/testing/http_authentication `
766
766
* :doc: `/cookbook/testing/insulating_clients `
767
767
* :doc: `/cookbook/testing/profiling `
768
+ * :doc: `/cookbook/testing/bootstrap `
768
769
769
770
770
771
.. _`DemoControllerTest` : https://github.com/symfony/symfony-standard/blob/master/src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php
Original file line number Diff line number Diff line change 132
132
* :doc:` /cookbook/testing/insulating_clients`
133
133
* :doc:` /cookbook/testing/profiling`
134
134
* :doc:` /cookbook/testing/doctrine`
135
+ * :doc:` /cookbook/testing/bootstrap`
135
136
136
137
* :doc:` /cookbook/validation/index`
137
138
Original file line number Diff line number Diff line change
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 ``).
Original file line number Diff line number Diff line change 8
8
insulating_clients
9
9
profiling
10
10
doctrine
11
+ bootstrap
You can’t perform that action at this time.
0 commit comments