Skip to content

Commit

Permalink
test(resolvers): Add test for session identity resolver and session o…
Browse files Browse the repository at this point in the history
…verride compatibility issues
  • Loading branch information
ollieread committed Oct 25, 2024
1 parent 1df4a8f commit c7bb727
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/Http/Resolvers/SessionResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
);
}
}

0 comments on commit c7bb727

Please sign in to comment.