Change of baseUrl for PHPUnit in Laravel 5.4

删除回忆录丶 提交于 2020-01-06 06:55:10

问题


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?


回答1:


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
}


来源:https://stackoverflow.com/questions/45381501/change-of-baseurl-for-phpunit-in-laravel-5-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!