That is not null coalescence operator, but ternary operator.
Have you tried
$caf = CompanyCustomerAgreement::factory()->make([
'last_completed_step' => null,
'code' => 'UAMI2',
]);
$co = CompanyCustomerAgreement::whereCompanyCode($code)->first();
if(!isset($co)) {
$this->redirect('/expired');
} else {
$this->lcStep = $co->last_completed_step ?: 1;
$this->currentStep = $co->last_completed_step ?: 1;
} // end if
Shouldn't null coalescence kick in???
/** @test */
public function caf_loads_properly(): void
{
$caf = CompanyCustomerAgreement::factory()->make([
'last_completed_step' => null
]);
Livewire::actingAs($this->user)
->test(CustomerWizard::class, ['code' => 'UAMI2'])
->assertSet('companyCode', 'UAMI2')
->assertSet('currentStep', 1)
->assertSet('lcStep', 1)
->assertOK();
} // end test
Failed asserting that null matches expected 1.
Fails on either ->assertSet('currentStep', 1) or ->assertSet('lcStep', 1)
Thanks @jgravois
You have to use the create() method in order to persist your CompanyCustomerAgreement to the database:
$caf = CompanyCustomerAgreement::factory()->create([
'code' => 'UAMI2',
'last_completed_step' => null
]);
Please or to participate in this conversation.