如何将 Behat 路径从 Public 文件夹更改为不同的文件夹名称
how to change Behat path from Public folder to different folder name
我在测试我继承的 Laravel 应用程序时遇到问题。
通常标记为 "public" 的文件夹已重命名为 "html"。
应用程序本身运行良好,但是当 Behat 测试时 运行 它仍然寻找 public 文件夹.我一直在 解决 它,方法是 复制 "html" 文件并将其重命名为 public,但我想只是解决这个问题,这样我就可以让其他同事测试这个应用程序。
我查看了 Behat 文档,但找不到它。我也用谷歌搜索了很多,但没有找到任何解决方法。
任何人都知道如何设置此路径 所以我可以将其更改为查找名为 "html." 的文件夹,而不是查找名为 "public" 的文件夹
我得到的确切错误是
Warning: file_get_contents(/Library/WebServer/Documents/myApp/myApp/public/build/rev-manifest.json): failed to open stream: No such file or directory in /Library/WebServer/Documents/thirdspace-app/thirdspace/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php line 668
所以上面路径中的public需要是html.
该错误中引用的代码如下所示
if ( ! function_exists('elixir'))
{
function elixir($file)
{
static $manifest = null;
if (is_null($manifest))
{
$manifest = json_decode(file_get_contents(public_path().'/build/rev-manifest.json'), true);
}
if (isset($manifest[$file]))
{
return '/build/'.$manifest[$file];
}
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
}
不过我真的不想更改它,因为我认为这会影响应用程序本身。我只想发送寻找 html 而不是 public 的测试。我真的只想确保解决方案只影响测试,而不影响应用程序本身。
我不知道 Laravel 如何使用 behat 测试,所以这是一个相当笼统的答案。我不知道为什么 behat 测试会依赖于该文件夹而不是查找存储在那里的静态内容(例如上传)。也许您可以添加失败的 behat 测试的示例输出?我认为最有可能包含路径的 2 个选项是:
这使用了 Laravel 辅助函数 public_path()
,它将始终 return 一个需要名为 public
的目录的路径。
有几种不同的方法可以覆盖它,但这可能是最简单的。为了在 Behat 之前运行,请在 bootstrap/app.php
:
中定义
$app->bind('path.public', function() {
return base_path().'/html';
});
我在测试我继承的 Laravel 应用程序时遇到问题。
通常标记为 "public" 的文件夹已重命名为 "html"。
应用程序本身运行良好,但是当 Behat 测试时 运行 它仍然寻找 public 文件夹.我一直在 解决 它,方法是 复制 "html" 文件并将其重命名为 public,但我想只是解决这个问题,这样我就可以让其他同事测试这个应用程序。
我查看了 Behat 文档,但找不到它。我也用谷歌搜索了很多,但没有找到任何解决方法。
任何人都知道如何设置此路径 所以我可以将其更改为查找名为 "html." 的文件夹,而不是查找名为 "public" 的文件夹
我得到的确切错误是
Warning: file_get_contents(/Library/WebServer/Documents/myApp/myApp/public/build/rev-manifest.json): failed to open stream: No such file or directory in /Library/WebServer/Documents/thirdspace-app/thirdspace/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php line 668
所以上面路径中的public需要是html.
该错误中引用的代码如下所示
if ( ! function_exists('elixir'))
{
function elixir($file)
{
static $manifest = null;
if (is_null($manifest))
{
$manifest = json_decode(file_get_contents(public_path().'/build/rev-manifest.json'), true);
}
if (isset($manifest[$file]))
{
return '/build/'.$manifest[$file];
}
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
}
不过我真的不想更改它,因为我认为这会影响应用程序本身。我只想发送寻找 html 而不是 public 的测试。我真的只想确保解决方案只影响测试,而不影响应用程序本身。
我不知道 Laravel 如何使用 behat 测试,所以这是一个相当笼统的答案。我不知道为什么 behat 测试会依赖于该文件夹而不是查找存储在那里的静态内容(例如上传)。也许您可以添加失败的 behat 测试的示例输出?我认为最有可能包含路径的 2 个选项是:
这使用了 Laravel 辅助函数 public_path()
,它将始终 return 一个需要名为 public
的目录的路径。
有几种不同的方法可以覆盖它,但这可能是最简单的。为了在 Behat 之前运行,请在 bootstrap/app.php
:
$app->bind('path.public', function() {
return base_path().'/html';
});