Laravel Codeception验收测试覆盖路线未被识别

问题描述 投票:2回答:2

我正在尝试使用代码验收测试为我的控制器生成代码覆盖率但是当我用覆盖率运行测试时,Laravel不知道如何处理这条路由。

c3.php已设置并包含在public/index.php中 - 我已验证了正确的页面。

 [ErrorException] file_get_contents(http://localhost/c3/report/clear): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

我需要添加路线吗?

laravel codeception
2个回答
2
投票

这很难评估,因为可能会有很多事情可能导致这种情况。我不确定这是问题的路由,但可能是之前的步骤(因为它不是4xx错误)。在Laravel中,通常当我遇到500问题时,特别是在路由方面(好吧,mod_rewrite),它通常与我的.htaccess文件有关。

您是否尝试过添加此行?

RewriteBase /

RewriteEngine On

在.htaccess文件中?


0
投票

对我来说,在this GitHub issue中描述了在Laravel 4.2中运行验收测试的解决方案。

codeception.yml

coverage:
    enabled: true
    remote: false
    c3_url: 'http://whatever.dev/c3.php'

routes.php文件

Route::get('/c3.php/{extra}', function () {
    require base_path('c3.php');
})->where('extra', '.*');

提示:在我正在进行的验收/功能测试中,我正在引导Laravel作为流程的一部分,因此我可以在测试中完全访问Facades和IOC容器,这有助于断言。

$app = require __DIR__.'/../bootstrap/start.php';
$app->boot();

注意:生成代码覆盖时,使用require_once将不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.