setIdentifier('tenant-a') ->setEnabled(true); $service = $this->createStub(TenantService::class); $service->method('fetchById')->willReturn($tenantObject); $tenant = new TenantContext($service); $identity = new IdentityContext(); $descriptor = ExecutionDescriptor::cli(); $scope = new ExecutionScope( $descriptor, ExecutionContext::fromDescriptor($descriptor), $tenant, $identity, ); $tenant->resolveIdentifier('tenant-a'); $user = new User(); $user->setId('user-a'); $identity->initialize($user); $scope->dispose(); self::assertFalse($tenant->present()); self::assertFalse($identity->present()); } #[Test] #[TestDox('New scopes cannot see state from an earlier execution')] public function isolates(): void { $tenantObject = (new TenantObject()) ->setIdentifier('tenant-a') ->setEnabled(true); $service = $this->createStub(TenantService::class); $service->method('fetchById')->willReturn($tenantObject); $tenant = new TenantContext($service); $identity = new IdentityContext(); $tenant->resolveIdentifier('tenant-a'); $identity->initialize(new User()); $descriptor = ExecutionDescriptor::cli(); new ExecutionScope( $descriptor, ExecutionContext::fromDescriptor($descriptor), $tenant, $identity, ); self::assertFalse($tenant->present()); self::assertFalse($identity->present()); } #[Test] #[TestDox('Execution scopes can only be marked terminated once')] public function terminatesOnce(): void { $descriptor = ExecutionDescriptor::cli(); $scope = new ExecutionScope( $descriptor, ExecutionContext::fromDescriptor($descriptor), new TenantContext($this->createStub(TenantService::class)), new IdentityContext(), ); $scope->markTerminated(); $this->expectException(\LogicException::class); $scope->markTerminated(); } }