Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit / Lumen always returns 404

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

I have the following code to test the weird 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 this?

Thanks in advance.

like image 387
frietkot Avatar asked Oct 31 '22 16:10

frietkot


1 Answers

I fixed this by including my routes with require instead of require_once.

like image 156
frietkot Avatar answered Nov 09 '22 13:11

frietkot