diff --git a/tests/Unit/Attributes/CurrentTenantTest.php b/tests/Unit/Attributes/CurrentTenantTest.php index 2015310..631ddd8 100644 --- a/tests/Unit/Attributes/CurrentTenantTest.php +++ b/tests/Unit/Attributes/CurrentTenantTest.php @@ -7,12 +7,11 @@ use Orchestra\Testbench\Attributes\DefineEnvironment; use PHPUnit\Framework\Attributes\Test; use Sprout\Attributes\CurrentTenant; -use Sprout\Contracts\Tenant; -use Sprout\Managers\TenancyManager; use Sprout\Support\GenericTenant; use Sprout\Tests\Unit\UnitTestCase; use Workbench\App\Models\TenantModel; use function Sprout\sprout; +use function Sprout\tenancy; class CurrentTenantTest extends UnitTestCase { @@ -41,7 +40,7 @@ protected function setupSecondTenancy($app): void public function resolvesCurrentTenant(): void { /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get('tenants'); + $tenancy = tenancy('tenants'); sprout()->setCurrentTenancy($tenancy); @@ -63,7 +62,7 @@ public function resolvesCurrentTenant(): void public function resolvesCurrentTenantForSpecificTenancy(): void { /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get('backup'); + $tenancy = tenancy('backup'); sprout()->setCurrentTenancy($tenancy); diff --git a/tests/Unit/Support/ResolutionHelperTest.php b/tests/Unit/Support/ResolutionHelperTest.php index f7d55f1..5385696 100644 --- a/tests/Unit/Support/ResolutionHelperTest.php +++ b/tests/Unit/Support/ResolutionHelperTest.php @@ -9,14 +9,13 @@ use PHPUnit\Framework\Attributes\Test; use Sprout\Exceptions\MisconfigurationException; use Sprout\Exceptions\NoTenantFound; -use Sprout\Managers\IdentityResolverManager; -use Sprout\Managers\TenancyManager; use Sprout\Support\ResolutionHelper; use Sprout\Support\ResolutionHook; use Sprout\Tests\Unit\UnitTestCase; use Workbench\App\Models\TenantModel; use function Sprout\resolver; use function Sprout\sprout; +use function Sprout\tenancy; class ResolutionHelperTest extends UnitTestCase { @@ -67,12 +66,12 @@ public function throwsExceptionWhenHandlingResolutionForUnsupportedHook(): void public function returnsFalseIfThereIsAlreadyATenant(): void { /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get(); + $tenancy = tenancy(); $tenancy->setTenant(TenantModel::factory()->createOne()); /** @var \Sprout\Contracts\IdentityResolver $resolver */ - $resolver = app(IdentityResolverManager::class)->get('path'); + $resolver = resolver('path'); /** @var \Illuminate\Http\Request $fakeRequest */ $fakeRequest = $this->mock(Request::class); @@ -86,10 +85,10 @@ public function returnsFalseIfThereIsAlreadyATenant(): void public function returnsFalseIfTheResolverCannotResolve(): void { /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get(); + $tenancy = tenancy(); /** @var \Sprout\Contracts\IdentityResolver $resolver */ - $resolver = app(IdentityResolverManager::class)->get('path'); + $resolver = resolver('path'); $tenancy->setTenant(TenantModel::factory()->createOne()) ->resolvedVia($resolver) @@ -109,10 +108,10 @@ public function resolvesTenantUsingRouteParameters(): void $tenant = TenantModel::factory()->createOne(); /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get(); + $tenancy = tenancy(); /** @var \Sprout\Contracts\IdentityResolver&\Sprout\Contracts\IdentityResolverUsesParameters $resolver */ - $resolver = app(IdentityResolverManager::class)->get('path'); + $resolver = resolver('path'); /** @var \Illuminate\Routing\Route $fakeRoute */ $fakeRoute = $this->mock(Route::class, function (MockInterface $mock) use ($tenant, $tenancy, $resolver) { @@ -158,10 +157,10 @@ public function resolvesTenantUsingRouteParameters(): void public function throwsAnExceptionWhenUnableToIdentifyATenantFromTheRoute(): void { /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get(); + $tenancy = tenancy(); /** @var \Sprout\Contracts\IdentityResolver&\Sprout\Contracts\IdentityResolverUsesParameters $resolver */ - $resolver = app(IdentityResolverManager::class)->get('path'); + $resolver = resolver('path'); /** @var \Illuminate\Routing\Route $fakeRoute */ $fakeRoute = $this->mock(Route::class, function (MockInterface $mock) use ($tenancy, $resolver) { @@ -199,10 +198,10 @@ public function throwsAnExceptionWhenUnableToIdentifyATenantFromTheRoute(): void public function returnsFalseWhenUnableToIdentifyATenantFromTheRouteAndToldNotToThrow(): void { /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get(); + $tenancy = tenancy(); /** @var \Sprout\Contracts\IdentityResolver&\Sprout\Contracts\IdentityResolverUsesParameters $resolver */ - $resolver = app(IdentityResolverManager::class)->get('path'); + $resolver = resolver('path'); /** @var \Illuminate\Routing\Route $fakeRoute */ $fakeRoute = $this->mock(Route::class, function (MockInterface $mock) use ($tenancy, $resolver) { @@ -246,10 +245,10 @@ public function resolvesTenantWithoutRouteParameters(): void $tenant = TenantModel::factory()->createOne(); /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get(); + $tenancy = tenancy(); /** @var \Sprout\Contracts\IdentityResolver&\Sprout\Contracts\IdentityResolverUsesParameters $resolver */ - $resolver = app(IdentityResolverManager::class)->get('path'); + $resolver = resolver('path'); /** @var \Illuminate\Http\Request $fakeRequest */ $fakeRequest = $this->mock(Request::class, function (MockInterface $mock) use ($tenant) { @@ -283,10 +282,10 @@ public function resolvesTenantWithoutRouteParameters(): void public function throwsAnExceptionWhenUnableToIdentifyATenantFromTheRequest(): void { /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get(); + $tenancy = tenancy(); /** @var \Sprout\Contracts\IdentityResolver&\Sprout\Contracts\IdentityResolverUsesParameters $resolver */ - $resolver = app(IdentityResolverManager::class)->get('path'); + $resolver = resolver('path'); /** @var \Illuminate\Http\Request $fakeRequest */ $fakeRequest = $this->mock(Request::class, function (MockInterface $mock) { @@ -312,10 +311,10 @@ public function throwsAnExceptionWhenUnableToIdentifyATenantFromTheRequest(): vo public function returnsFalseWhenUnableToIdentifyATenantFromTheRequestAndToldNotToThrow(): void { /** @var \Sprout\Contracts\Tenancy $tenancy */ - $tenancy = app(TenancyManager::class)->get(); + $tenancy = tenancy(); /** @var \Sprout\Contracts\IdentityResolver&\Sprout\Contracts\IdentityResolverUsesParameters $resolver */ - $resolver = app(IdentityResolverManager::class)->get('path'); + $resolver = resolver('path'); /** @var \Illuminate\Http\Request $fakeRequest */ $fakeRequest = $this->mock(Request::class, function (MockInterface $mock) { diff --git a/tests/Unit/TenancyOptionsTest.php b/tests/Unit/TenancyOptionsTest.php index 3f83d2f..9ee73df 100644 --- a/tests/Unit/TenancyOptionsTest.php +++ b/tests/Unit/TenancyOptionsTest.php @@ -6,8 +6,8 @@ use Illuminate\Config\Repository; use Orchestra\Testbench\Attributes\DefineEnvironment; use PHPUnit\Framework\Attributes\Test; -use Sprout\Managers\TenancyManager; use Sprout\TenancyOptions; +use function Sprout\tenancy; class TenancyOptionsTest extends UnitTestCase { @@ -40,7 +40,7 @@ public function throwIfNotRelatedOption(): void #[Test, DefineEnvironment('setupSecondTenancy')] public function correctlyReportsHydrateTenantRelationOptionPresence(): void { - $tenancy = app(TenancyManager::class)->get('tenants'); + $tenancy = tenancy('tenants'); $tenancy->removeOption(TenancyOptions::hydrateTenantRelation()); $this->assertFalse(TenancyOptions::shouldHydrateTenantRelation($tenancy)); @@ -49,7 +49,7 @@ public function correctlyReportsHydrateTenantRelationOptionPresence(): void $this->assertTrue(TenancyOptions::shouldHydrateTenantRelation($tenancy)); - $tenancy = app(TenancyManager::class)->get('backup'); + $tenancy = tenancy('backup'); $this->assertFalse(TenancyOptions::shouldHydrateTenantRelation($tenancy)); } @@ -57,7 +57,7 @@ public function correctlyReportsHydrateTenantRelationOptionPresence(): void #[Test, DefineEnvironment('setupSecondTenancy')] public function correctlyReportsThrowIfNotRelatedOptionPresence(): void { - $tenancy = app(TenancyManager::class)->get('tenants'); + $tenancy = tenancy('tenants'); $tenancy->removeOption(TenancyOptions::throwIfNotRelated()); $this->assertFalse(TenancyOptions::shouldThrowIfNotRelated($tenancy)); @@ -66,7 +66,7 @@ public function correctlyReportsThrowIfNotRelatedOptionPresence(): void $this->assertTrue(TenancyOptions::shouldThrowIfNotRelated($tenancy)); - $tenancy = app(TenancyManager::class)->get('backup'); + $tenancy = tenancy('backup'); $this->assertFalse(TenancyOptions::shouldThrowIfNotRelated($tenancy)); } diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/UnitTestCase.php index 02e2b6a..049d89c 100644 --- a/tests/Unit/UnitTestCase.php +++ b/tests/Unit/UnitTestCase.php @@ -4,8 +4,9 @@ namespace Sprout\Tests\Unit; use Orchestra\Testbench\Concerns\WithWorkbench; +use Orchestra\Testbench\TestCase; -abstract class UnitTestCase extends \Orchestra\Testbench\TestCase +abstract class UnitTestCase extends TestCase { use WithWorkbench;