diff --git a/src/BelongsToTenants.php b/src/BelongsToTenants.php index 6a75704..191abc1 100644 --- a/src/BelongsToTenants.php +++ b/src/BelongsToTenants.php @@ -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); } /** diff --git a/tests/LandlordTest.php b/tests/LandlordTest.php index a397d0e..9cd58c3 100644 --- a/tests/LandlordTest.php +++ b/tests/LandlordTest.php @@ -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();