Skip to content

Add a cookbook entry to explain how to clear the cache before tests #1735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions cookbook/testing/auto_cache_clear.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
How to automatically clear the cache before tests are run
=========================================================

Some features need the cache to be cleared in order to work.
You could have tests failing, because some part of the cache would need to
be cleared. (For example, new translation resources)

It's a good idea to clear the cache before running your tests, and automate it
is even better.

Add the following file::

// app/tests.bootstrap.php
if (isset($_ENV['BOOTSTRAP_CLEAR_CACHE_ENV'])) {
passthru(sprintf(
'php "%s/console" cache:clear --env=%s --no-warmup',
__DIR__,
$_ENV['BOOTSTRAP_CLEAR_CACHE_ENV']
));
}

require __DIR__.'/bootstrap.php.cache';

Replace the test bootstrap file ``bootstrap.php.cache`` in `app/phpunit.xml` by
``tests.bootstrap.php``:

.. code-block:: xml

<!-- app/phpunit.xml -->
bootstrap = "tests.bootstrap.php"

And then, you can define in your `phpunit.xml` file which environment you want the
cache to be cleared:

.. code-block:: xml

<!-- app/phpunit.xml -->
<php>
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
</php>