【问题标题】:PHPUnit / Lumen always returns 404PHPUnit / Lumen 总是返回 404
【发布时间】:2016-02-04 18:32:52
【问题描述】:

当我在 Laravel Lumen 中创建 PHPUnit 测试用例并调用 visit('/') 函数时,PHPUnit 总是返回 404 错误代码。

我有以下代码来测试奇怪的行为:

class TestCase extends Laravel\Lumen\Testing\TestCase {
    protected $baseUrl = 'https://google.com'; // this used to be my own url but even this doesn't work.

    public function createApplication() {
        return require __DIR__.'/../bootstrap/app.php';
    }
}

class CountryTest extends TestCase {
    public function testIndex() {
        $this->visit('/');
    }
}

有谁知道我做错了什么或如何解决这个问题?

提前致谢。

【问题讨论】:

    标签: php laravel phpunit lumen


    【解决方案1】:

    我通过使用require 而不是require_once 包含我的路线来解决此问题。

    【讨论】:

    • 这很奇怪。我在 Docker 中运行 Lumen,这是让它工作的唯一方法。
    【解决方案2】:

    我通过将APP_URL 恢复为.env 文件中的原始值解决了这个问题。

    APP_URL=http://localhost
    

    或者只是将其更改为您正在使用的本地主机地址。

    【讨论】:

      猜你喜欢
      • 2020-11-11
      • 2016-11-18
      • 2018-05-03
      • 2020-11-30
      • 2020-09-15
      • 2021-08-05
      • 2015-07-31
      • 1970-01-01
      • 2014-05-29
      相关资源
      最近更新 更多