【问题标题】:Change of baseUrl for PHPUnit in Laravel 5.4Laravel 5.4 中 PHPUnit 的 baseUrl 变化
【发布时间】:2017-07-31 16:13:03
【问题描述】:

似乎在 Laravel 5.4 之前我们可以通过这样的编码来更改测试的 URL:

protected $baseUrl = 'http://someurl.com';

但现在它不起作用,有人建议我们必须使用这种方法

function setUp()
{
    parent::setUp();
    config(['app.url' => 'http://yourcustomeaddress.loc']);
}

有人能帮我告诉我应该把这个方法放在哪里吗?

【问题讨论】:

    标签: phpunit laravel-5.4


    【解决方案1】:

    你可以把它放在tests/TestCase.php(Laravel 5.4 例子):

    abstract class TestCase extends BaseTestCase
    {
        function setUp()
        {
            parent::setUp();
            config(['app.url' => 'http://yourcustomeaddress.loc']);
        }
    
        use CreatesApplication;
    }
    

    或者你可以在特定的测试中添加它:

    class ExampleTest extends TestCase
    {
        function setUp()
        {
            parent::setUp();
            config(['app.url' => 'http://yourcustomeaddress.loc']);
        }
    // your test functions
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-02
      • 2017-08-02
      • 2015-12-07
      • 2017-07-28
      • 2017-09-04
      • 1970-01-01
      • 2018-05-07
      • 2017-08-10
      • 2018-01-21
      相关资源
      最近更新 更多