62

When I run tests with PhpUnit on a new package I'm creating for Laravel, it generates the file .phpunit.result.cache.

What to do with that? Do I add it to my .gitignore file or not?

I'm using PHPUnit 8.0.4

fabpico
  • 2,628
  • 4
  • 26
  • 43
Davide Casiraghi
  • 15,591
  • 9
  • 34
  • 56

3 Answers3

77

This file helps PHPUnit remember which tests previously failed, which can speed up your testing flow if you only re-run failed tests during development. This is useful for test-driven workflows in which you have configured tests to run automatically, such as on file save, and the same collection of tests is being run repeatedly.

It is also a good idea to add the cache file .phpunit.result.cache to your .gitignore so that it does not end up being committed to your repository.

https://laravel-news.com/tips-to-speed-up-phpunit-tests

If you would prefer not to generate the file then you can run phpunit with the --do-not-cache-result option, as pointed out by @Slack Undertow in the comments. This might be desired when running tests as part of a build pipeline, for example. Or, as @codekandis pointed out, the same option is available as the cacheResult attribute in phpunit.xml.

Travis Britz
  • 5,094
  • 2
  • 20
  • 35
  • 2
    @SlackUndertow https://github.com/sebastianbergmann/phpunit/issues/3587#issuecomment-480181912 "[...] Basically the cache is to speed up when testing _the same_ collection over and over again [...]" So a decision to turn it of should be made by the test collection size and the assumed iterations of testing that collection. But: "[...] When using the play / pause buttons in PHPStorm for example, caching this result makes no sense. In addition to the IDE having its own 'run failed tests again/first' option. [...]" The cache is mainly useful in non-IDE environments. – codekandis Sep 13 '19 at 20:13
16

You can also change this file location by editing phpunit.xml:

<phpunit 
    ...
    cacheResultFile="../.temp/fs_cache/.phpunit.result.cache"
>

Or completely disable it by

<phpunit 
    ...
    cacheResult ="false"
>
Yehor
  • 6,203
  • 3
  • 20
  • 28
1

Official PHPUnit explanation (I currently don't find any other useful official details).

This caching is required for certain other features to work.

You can disable it with:

<phpunit 
    ...
    cacheResult="false">
fabpico
  • 2,628
  • 4
  • 26
  • 43