I am attempting to run the feature tests in a Laravel application which is running within a local Lando environment. The environment is accessible via https://catalog.lndo.site.
If I attempt to run the example test:
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function test_example()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
via the CLI with the command lando php artisan test --testsuite=Feature
I get a failure:
• Tests\Feature\ExampleTest > example
Expected response status code [200] but received 404.
Failed asserting that 200 is identical to 404.
at tests/Feature/ExampleTest.php:18
14▕ */
15▕ public function test_example()
16▕ {
17▕ $response = $this->get('/');
➜ 18▕ $response->assertStatus(200);
19▕ }
20▕ }
21▕
Tests: 1 failed
Time: 0.66s
I'm assuming this test isn't passing because it's running in a docker container.
If I follow the code through to Illuminate\Foundation\Testing\Concerns\MakesHttpRequests::call
I can see the request looks like this:
GET /catalog.lndo.site HTTP/1.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Language: en-us,en;q=0.5
Host: localhost
User-Agent: Symfony
Obviously that GET url isn't correct
The .env file is:
APP_NAME=Laravel
APP_ENV=local
DUSK_DRIVER_URL=http://chromedriver:4444/wd/hub
APP_DEBUG=true
APP_URL=catalog.lndo.site
APP_KEY=base64:VsA/HpgsJT1somemorestring=
DB_CONNECTION=mysql
DB_HOST=database
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=laravel
Is there a configuration I can change in Lando, Laravel, or the test suite that would allow this test to pass? I can't help but think I just have a configuration value wrong somewhere
Your issue is that you have not added http://
or https://
to the begining of your APP_URL
.
Due to how that is interpret, you must explicitly add the protocol to that ENV