简体   繁体   中英

Laravel phpunit always 404

Environment: PHP 7.0 macOS apache

The code is :

public function testBasicExample()
{
    $this->visit('/');
}

Run phpunit. The result is:

1) ExampleTest::testBasicExample
A request to [http://localhost] failed. Received status code [404].

It's always normal when in Chrome.

I found a solution for this issue, it is by using the url provided by

php artisan serve

Please visit this thread for more info

You need to edit your TestCase.php file and update

protected $baseUrl = 'http://localhost'

with

protected $baseUrl = 'HOST OR URL THAT YOU USE TO ACCESS YOUR SITE'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM