'The bootstrap/cache directory must be present and writable' 测试期间出现 laravel 6 错误

'The bootstrap/cache directory must be present and writable' error during laravel 6 testing

Laravel 6 在 phpunit.xml 中包含一些附加配置:

<server name="APP_CONFIG_CACHE" value="bootstrap/cache/config.phpunit.php"/>
<server name="APP_SERVICES_CACHE" value="bootstrap/cache/services.phpunit.php"/>
<server name="APP_PACKAGES_CACHE" value="bootstrap/cache/packages.phpunit.php"/>
<server name="APP_ROUTES_CACHE" value="bootstrap/cache/routes.phpunit.php"/>
<server name="APP_EVENTS_CACHE" value="bootstrap/cache/events.phpunit.php"/>

如果我 运行 在 PHPStorm 中进行测试,我会收到以下错误:

In PackageManifest.php line 168:

The bootstrap/cache directory must be present and writable.

但是 bootstrap/cache 目录确实存在并且可写。但是,如果我在 phpunit.xml 中注释掉那些新配置,我的测试 运行 没有任何错误。我该如何解决这个问题?

我也运行php artisan cache:clear。运气不好。

如果您 运行正在 Linux,很可能是 read/write 权限问题,要解决这些问题,请执行以下操作:

在执行以下步骤之前,请务必在您的 Laravel 文件夹之外

假设您的 user 应该是所有者,请键入以下命令:

sudo chown -R user:www-data /path/of/your/laravel/project

然后给用户和网络服务器权限如下:

sudo find /path/of/your/laravel/project -type f -exec chmod 664 {} \;

然后 运行:

sudo find /path/of/your/laravel/project -type d -exec chmod 775 {} \;

在你 运行 那些命令之后,转到你的 Laravel 文件夹,并将 read/write 的网络服务器权限授予你的 bootstrap/cachestorage 文件夹:

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

它不仅能解决你的问题,还能解决你的项目安全问题。

这是一个来自 Laravel 结尾的问题:

https://github.com/laravel/framework/issues/29862

This PR 修复了该问题。

将框架版本更新到最新版本(截至本回答时为 6.0.3)可解决问题。