I have a simple test that checks that the dashboard is renderable for authenticated users.
Here is the code:
<?php
namespace Tests\Feature;
use App\Models\User;
use Tests\TestCase;
class DashboardTest extends TestCase
{
public function test_dashboard_page_can_be_rendered()
{
$this->actingAs(User::factory()->create());
$response = $this->get('/dashboard');
$response->assertStatus(200);
}
}
This code works fine when I run php artisan test
.
Output:
PASS Tests\Feature\DashboardTest
✓ dashboard page can be rendered
But, when running this on GitHub Actions, I get the following error:
There was 1 failure:
1) Tests\Feature\DashboardTest::test_dashboard_page_can_be_rendered
Expected response status code [200] but received 302.
Failed asserting that 200 is identical to 302.
/home/runner/work/material-hub/material-hub/vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php:198
/home/runner/work/material-hub/material-hub/tests/Feature/DashboardTest.php:17
I missed passing a middleware that I used to group all routes. It must be passed otherwise redirect will occur as described error.
That middleware is passed now and all tests run as usual.