diff --git a/tests/Http/Resolvers/SessionResolverTest.php b/tests/Http/Resolvers/SessionResolverTest.php index fb4daef..7403592 100644 --- a/tests/Http/Resolvers/SessionResolverTest.php +++ b/tests/Http/Resolvers/SessionResolverTest.php @@ -7,18 +7,22 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Routing\Router; use Illuminate\Session\Middleware\StartSession; +use Orchestra\Testbench\Attributes\DefineEnvironment; use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\Test; use Sprout\Attributes\CurrentTenant; use Sprout\Contracts\Tenant; +use Sprout\Exceptions\CompatibilityException; use Sprout\Overrides\AuthOverride; use Sprout\Overrides\CacheOverride; use Sprout\Overrides\CookieOverride; use Sprout\Overrides\JobOverride; +use Sprout\Overrides\SessionOverride; use Sprout\Overrides\StorageOverride; use Workbench\App\Models\TenantModel; +use function Sprout\sprout; #[Group('resolvers'), Group('sessions')] class SessionResolverTest extends TestCase @@ -46,6 +50,20 @@ protected function defineEnvironment($app): void }); } + protected function withSessionOverride($app):void + { + tap($app['config'], static function (Repository $config) { + $config->set('sprout.services', [ + StorageOverride::class, + JobOverride::class, + CacheOverride::class, + AuthOverride::class, + CookieOverride::class, + SessionOverride::class, + ]); + }); + } + protected function defineRoutes($router): void { $router->middleware(StartSession::class)->group(function (Router $router) { @@ -87,4 +105,19 @@ public function throwsExceptionWithoutHeader(): void $result->assertInternalServerError(); } + + #[Test] + public function throwsExceptionIfSessionOverrideIsEnabled(): void + { + sprout()->addOverride(new SessionOverride()); + $tenant = TenantModel::factory()->createOne(); + + $result = $this->withSession(['multitenancy' => ['tenants' => $tenant->getTenantIdentifier()]])->get(route('session.route')); + $result->assertInternalServerError(); + $this->assertInstanceOf(CompatibilityException::class, $result->exception); + $this->assertSame( + 'Cannot use resolver [session] with override [' . SessionOverride::class . ']', + $result->exception->getMessage() + ); + } }