【问题标题】:PHPUnit test with XAMPP localhost instead of laravel artisan servePHPUnit 测试使用 XAMPP localhost 而不是 laravel artisan serve
【发布时间】:2017-08-02 10:14:05
【问题描述】:

我在 laravel 5.4 上设置了单元测试(不是黄昏浏览器测试),我已将 phpunit.xml 中的 baseUrl 配置为

http://localhost/TestApp/public

但是当我运行时

vendor\bin\phpunit

断言状态为 200,我得到失败的测试,说返回的状态为 404,而在浏览器上我可以访问 URL。

测试如下

namespace Tests\Feature;

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

class ExampleTest extends TestCase
{

    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $response = $this->get('/');


        $response->assertStatus(200);
    }
}

【问题讨论】:

  • 提示:code
  • @Paras 更新代码
  • .env 文件中的 APP_URL 是什么?
  • @Paras APP_URL=localhost/TestApp/public
  • 虽然我注意到将 baseUrl 设置为 localhost:8000 可以在没有工匠服务的情况下工作

标签: laravel unit-testing laravel-5 phpunit laravel-dusk


【解决方案1】:

您可以为您的测试创建一个单独的环境文件 (.env.testing),以便在没有 /public 的情况下使用 localhost/TestApp,它应该可以工作。

https://laravel.com/docs/5.6/configuration#environment-configuration

【讨论】:

    猜你喜欢
    • 2016-07-25
    • 2014-03-21
    • 2019-12-15
    • 2019-12-26
    • 1970-01-01
    • 2015-12-27
    • 2018-02-22
    • 1970-01-01
    • 2019-10-10
    相关资源
    最近更新 更多