Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix querying allTenants when trait on model was not booted yet #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/BelongsToTenants.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function getQualifiedTenant($tenant)
*/
public static function allTenants()
{
return static::$landlord->newQueryWithoutTenants(new static());
$model = new static();
return static::$landlord->newQueryWithoutTenants($model);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/LandlordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@

class LandlordTest extends TestCase
{
public function testApplyScopesQueryAllTenants()
{
app()->bind(TenantManager::class, function() {
$manager = \Mockery::mock(TenantManager::class);
$manager->shouldReceive('newQueryWithoutTenants')->andReturn([]);
$manager->shouldReceive('applyTenantScopes');
return $manager;
});

$landlord = new TenantManager();

$landlord->addTenant('tenant_a_id', 1);

$landlord->addTenant('tenant_b_id', 2);

$this->assertEquals([], ModelStub::allTenants());
}

public function testTenantsWithStrings()
{
$landlord = new TenantManager();
Expand Down