I've just written a laravel Observer. It is attached to a Company model as I want to know the users that created a company. I have a large suite of other tests which use factories to setup companies. These tests now fail because the observer needs a user but no user is logged in when the factory is called.
CompanyObserver.php
class CompanyObserver {
function created(Company $company) {
info('USER ' . Auth::user()->id . ' created the new company ' . $company->id . '.';
}
}
OldTests.php
Class OldTests {
function testSomething() {
// Now fails because observer is triggered but no use is logged in.
$company = factory(Company::class)->create();
// Random request
$this->post('getCompany/' . $company->id)->assertStatus(200);
}
}
How can I handle having a new observer that require a user to be logged in for my old tests? Do I have to go and change all my old tests?