createMock(ClientEntityInterface::class); $client->method('getIdentifier')->willReturn('mockClientId'); $entity = new AccessTokenEntity(); $entity->setClient($client); $entity->setExpiryDateTime(new DateTimeImmutable()); $entity->addScope($this->createScopeEntity('first')); $entity->addScope($this->createScopeEntity('second')); $token = (string)$entity; $payloads = json_decode(base64_decode(explode('.', $token)[1]), true); $this->assertSame('first,second', $payloads['ely-scopes']); } private function createScopeEntity(string $id): ScopeEntityInterface { /** @var ScopeEntityInterface|\PHPUnit\Framework\MockObject\MockObject $entity */ $entity = $this->createMock(ScopeEntityInterface::class); $entity->method('getIdentifier')->willReturn($id); return $entity; } }