[6.x] Normalize cache file paths #29890
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #29862
Note: I believe this is an issue in need of fixing with and without the new bootstrap file but has become apparent due to the new file.
Scenario
You have set a relative path for the cache files using its environment variable, i.e.
APP_CONFIG_CACHE
.Assume we have the environment variable set:
Problem
In PHPStorm
From their docs:
Custom working directory
... By default, the field is empty and the working directory is the root of the project.
Source: https://www.jetbrains.com/help/phpstorm/run-debug-configuration-phpunit.html
Unfortunately it seems that this is not always the case and people are hitting errors as it is not using the project root as the "base path". I believe PHPStorm is now looking for the config cache file relative to where you run the test, so if you are in the
tests/Unit
file it is looking fortests/Unit/relative/path.php
There is a manual fix where in PHPStorm's settings you can specify a "Custom working directory" when running tests, but I'm sure everyone would prefer it "just work".
When running tests on the command line from a sub directory.
If you are in a project's root directory and you
cd app
and then run PHPUnit from this directory with...it will look for the cache directory in
app/relative/path.php
.I believe these are both the same issue just being hit with different tools, i.e. PHPStorm vs PHPUnit.
Solution
resolves to
BASE_PATH/bootstrap/cache/config.php
resolves to
/absolute/path/to/file.php
resolves to
BASE_PATH/relative/path/to/file.php
Essentially this PR just enforces a consistent path when specifying a relative path and has the added bonus of fixing the bug I introduced to Laravel 👀