First, do not use env directly rather use it via config. Second, just to confirm that's the issue, use a valid fixed value for samaccountname and password and see if the issue persist when running all tests.
Apr 9, 2021
8
Level 1
Test fails when running all test
I have multiple test and when I run each of them individually they all pass, but when I run all test at once one of them always fails, in this case it's the "user_can_login" test, it fails with a 401(Unauthorized).
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UserTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function user_can_login()
{
$response = $this->post(route('user-login', [
'samaccountname' => env('TEST_USER'),
'password' => env('TEST_USER_PASS')
]));
$response->assertStatus(200);
}
}
I've remove all tests keeping only the example test and it keeps failing, this also happens with some other test I've written. The example test:
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
Level 1
Was not able to figure out what the problem was, but found a way around it by enabling phpunit to run each test in a separate process by changing processIsolation to true.
Please or to participate in this conversation.