4中PHPUnit的baseUrl的更改

4中PHPUnit的baseUrl的更改

本文介绍了Laravel 5.4中PHPUnit的baseUrl的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel 5.4之前,我们似乎可以通过以下代码更改用于测试的URL:

It seems that before Laravel 5.4 we could change the URL for testing by coding like this:

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

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

But now it is not working and some suggest we have to use this method

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

有人会帮助我并告诉我该方法放在哪里吗?

Would anybody help me and tell Where I should put this method?

推荐答案

您可以将其放在tests/TestCase.php中(以Laravel 5.4为例):

You may put it in tests/TestCase.php (Laravel 5.4 example):

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

    use CreatesApplication;
}

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

Or you may add it in specific test:

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

这篇关于Laravel 5.4中PHPUnit的baseUrl的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:10