PHPUnit / Lumen always returns 404

When I create a PHPUnit test case in Laravel Lumen and call a function visit('/'), PHPUnit always returns a 404 error code.

I have the following code to test for strange behavior:

class TestCase extends Laravel\Lumen\Testing\TestCase {
    protected $baseUrl = 'https://google.com'; // this used to be my own url but even this doesn't work.

    public function createApplication() {
        return require __DIR__.'/../bootstrap/app.php';
    }
}

class CountryTest extends TestCase {
    public function testIndex() {
        $this->visit('/');
    }
}

Does anyone know what I did wrong or how to fix it?

Thanks in advance.

+4
source share
2 answers

I fixed this by including my routes with requireinstead require_once.

0
source

I solved this problem by returning APP_URLto the original value in the file .env.

APP_URL=http://localhost

Or just change it to the localhost address that you are using.

0
source

Source: https://habr.com/ru/post/1614419/


All Articles