gpt4 book ai didi

php - Laravel 5.4 上的示例 PHPUnit 测试失败并返回 404

转载 作者:可可西里 更新时间:2023-11-01 12:30:10 24 4
gpt4 key购买 nike

我可以从以下链接在 Laravel 5.4 上进行我的项目:localhost:8888/streaming_statistic/public

我有一个测试:

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ApiTest extends TestCase
{
public function testBasicTest()
{
$response = $this->get('/');

$response->assertStatus(200);
}
}

我用命令运行所有测试

./vendor/bin/phpunit

但结果是:

PHPUnit 5.7.13 by Sebastian Bergmann and contributors.

F 1 / 1 (100%)

Time: 222 ms, Memory: 12.25MB

There was 1 failure:

1) Tests\Feature\ApiTest::testBasicTest
Expected status code 200 but received 404.
Failed asserting that false is true.

/Applications/MAMP/htdocs/streaming_statistic/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:56
/Applications/MAMP/htdocs/streaming_statistic/tests/Feature/ApiTest.php:16

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

我可以打开这个页面http://localhost:8888/streaming_statistic/public/我有一条路线:

Route::get('/', function () {
return view('welcome');
});

我做错了什么?在 Laravel 中为 Controller 方法编写测试的正确方法是什么? HTTP 测试可能不是他们的最佳解决方案?

最佳答案

为了测试这个环境变量是错误的...

APP_URL=http://127.0.0.1:8888/streaming_statistic/public

我将根 Web 服务器目录更改为 streaming_statistic/public 并将 env 更改为

APP_URL=http://127.0.0.1:8888

之后我得到:

OK (1 test, 1 assertion)

关于php - Laravel 5.4 上的示例 PHPUnit 测试失败并返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42189472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com