Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Normalize cache file paths #29890

Merged
merged 1 commit into from
Sep 6, 2019
Merged

[6.x] Normalize cache file paths #29890

merged 1 commit into from
Sep 6, 2019

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Sep 6, 2019

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:

APP_CONFIG_CACHE=relative/path.php

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 for tests/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...

$ ../vendor/bin/phpunit -c ../phpunit.xml

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

  1. If no environment variable is set, this PR does not change functionality, i.e.
# no value set, no change in functionality
APP_CONFIG_CACHE=

resolves to BASE_PATH/bootstrap/cache/config.php

  1. If the environment variable is set using an absolute path, this PR does not change functionality, i.e.
# absolute path set, no change in functionality
APP_CONFIG_CACHE=/absolute/path/to/file.php

resolves to /absolute/path/to/file.php

  1. If the environment variable is set using a relative path, this PR does change functionality, i.e.
# relative path set, changes functionality
APP_CONFIG_CACHE=relative/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 馃憖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[6.0] PHPUnit can only be run from project root
2 participants