Phpunit: result cache file created by default

Created on 3 Aug 2018  路  19Comments  路  Source: sebastianbergmann/phpunit

| Q | A
| --------------------| ---------------
| PHPUnit version | 7.3.0
| PHP version | 7.2.8
| Installation Method | Composer

After upgrading from PHPUnit 7.2 when running tests the .phpunit.result.cache was created. Shouldn't be check here for not defined?

Most helpful comment

no config === default configuration
default on v7 is no cache, default on v8 will be with cash

All 19 comments

@epdenouden ping

@sebastianbergmann @kubawerlos will look into it this weekend!

the variable is hack/trick to NOT save cache file when running tests for PHPUnit itself during PHPUnit development (maybe a comment there would be nice, for now it's hidden knowledge, and each hack deserves a comment)

By default, the new caching feature is enabled: https://github.com/sebastianbergmann/phpunit/blob/00d26bb6c5ada299716fe85163b2be39100c8af1/src/TextUI/TestRunner.php#L1160 , as it's hard to discover the feature by users if you don't track the changes, while starting taking benefits from it is super nice

Changelog claims it's disabled by default.

@kubawerlos Quick question: would you be fine with a revised changelog or you have a use case where the creation of the cachefile causes trouble? We would like to have the feature enabled if it doesn't interfere with use cases I didn't think of during development.

@epdenouden it's totally fine to have it enabled by default, only it came as surprise after reading Changelog.

+1

@epdenouden What is the reason to have that .phpunit.result.cache file not deleted by default?
I think that for the most of the users - we don't need it, as it was before. No?

delete cache by default? you mean to not create it by default, i believe ?

no cache = no possibility to execute tests faster = new feature not in use

@dmitry-ivanov The answer to your question has two parts:

  1. the file is _not deleted_ as it is a cache to store information about test results between runs.
  2. it is currently _created_ by default as it takes up little space and the cache needs to be active to support the 'run failed tests first' (--order-by=defects) feature. See #3147 for more details

@keradus "possibility to execute tests faster"? How do results from the previous run can help to execute tests faster?

The file is used for the new feature to run failed tests first, as @epdenouden mentioned.
Nice feature, thanks guys! Now I get it.

@dmitry-ivanov During development I often use --order-by=depends,defects --stop-on-defect to quickly halt PHPUnit when getting tests green. Some IDEs like IntelliJ have this feature built into their user interface:

image

@epdenouden Regarding

Quick question: would you be fine with a revised changelog or you have a use case where the creation of the cachefile causes trouble? We would like to have the feature enabled if it doesn't interfere with use cases I didn't think of during development.

It works fine in PhpStorm as you mentioned, but when I run the tests using the command line on a read-only filesystem then it will fail trying to write the cache file. Example of a read-only filesystem include shared folders on a Vagrant dev environment.

@epdenouden I love the feature and just enabled it for my tests, but agree with @RinkAttendant6 that it should be disabled by default since it could be a BC break depending on where phpunit is executed.

@dmitry-ivanov I did not get it: In the IDE, you mentioned here, its easy to rerun only failed tests. There is a button for doing this.

The new implemented ticket says

Support for running tests first that failed in a previous run

(saying: Run all test, but in another order). This does no increase execution time of running test.

This "cache" file is also created in each folder of the located unit tests if you only want to run one test, or running a test only for one specific class.

In the IDE you mentioned here its easy to rerun only failed tests.

@dpauli Can you please show me where I wrote this? :)

PS: @epdenouden said, that you can use --order-by=depends,defects --stop-on-defect to run failed tests first. And if there are still some failed tests - your execution will stop.

And some IDEs have even a button in their UI for that.

@dmitry-ivanov Sorry for the missing comma (I updated it) and the wrong person I mentioned :) Its too warm today:

@epdenouden argued with a feature which is already implemented in the IntelliJ IDE.

So is this file supposed to be generated by default or not?
When running in PhpStorm it is creating in the project root or in the /tests dir if running a suite in isolation.
Also storm ignores the cacheResult="false" as it passes --no-configuration when it runs

@oniice Yes, the --no-configuration issue came up in the office, too. I think taking _don't use a configuration_ as a request to mean _be as defensive as possible_ would be good. In other words: no config = no cache writing/reading.

@keradus your opinion on ^^^ ?

no config === default configuration
default on v7 is no cache, default on v8 will be with cash

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joubertredrat picture joubertredrat  路  4Comments

greg0ire picture greg0ire  路  4Comments

klesun picture klesun  路  4Comments

keradus picture keradus  路  3Comments

keradus picture keradus  路  4Comments