Skip to content

Commit

Permalink
test(tenanted-models): Add test for when hydration is strictly disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieread committed Oct 25, 2024
1 parent 7510741 commit 1df4a8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function retrieved(Model $model): void
}

if (! TenancyOptions::shouldHydrateTenantRelation($tenancy)) {
return;
return; // @codeCoverageIgnore
}

/**
Expand Down
20 changes: 19 additions & 1 deletion tests/Database/Eloquent/BelongsToTenantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,25 @@ public function automaticallyPopulateTheTenantRelationWhenHydrating(): void

$this->assertTrue($child->exists);
$this->assertTrue($child->relationLoaded('tenant'));
$this->assertTrue($child->tenant->is($tenant));
$this->assertNotNull($child->getRelation('tenant'));
$this->assertTrue($child->getRelation('tenant')->is($tenant));
}

#[Test]
public function doNotHydrateWhenHydrateTenantRelationIsMissing(): void
{
/** @var \Sprout\Contracts\Tenancy $tenancy */
$tenancy = app(TenancyManager::class)->get();
$tenancy->removeOption(TenancyOptions::hydrateTenantRelation());

$tenant = TenantModel::factory()->create();

$tenancy->setTenant($tenant);

$child = TenantChild::query()->find(TenantChild::factory()->create()->getKey());

$this->assertTrue($child->exists);
$this->assertFalse($child->relationLoaded('tenant'));
}

#[Test]
Expand Down

0 comments on commit 1df4a8f

Please sign in to comment.