public function testCanCreateTokenResponse() { $request = $this->createMock(ServerRequestInterface::class); $client = Client::createNewClient('name', 'http://www.example.com'); $owner = $this->createMock(TokenOwnerInterface::class); $owner->expects($this->once())->method('getTokenOwnerId')->will($this->returnValue(1)); $token = AccessToken::reconstitute(['token' => 'azerty', 'owner' => $owner, 'client' => null, 'expiresAt' => (new \DateTimeImmutable())->add(new DateInterval('PT1H')), 'scopes' => []]); $this->tokenService->expects($this->once())->method('createToken')->will($this->returnValue($token)); $response = $this->grant->createTokenResponse($request, $client, $owner); $body = json_decode($response->getBody(), true); $this->assertEquals('azerty', $body['access_token']); $this->assertEquals('Bearer', $body['token_type']); $this->assertEquals(3600, $body['expires_in']); $this->assertEquals(1, $body['owner_id']); }
public function testCanCreateTokenResponse() { $request = $this->getMock(ServerRequestInterface::class); $client = new Client(); $owner = $this->getMock(TokenOwnerInterface::class); $owner->expects($this->once())->method('getTokenOwnerId')->will($this->returnValue(1)); $token = new AccessToken(); $token->setToken('azerty'); $token->setOwner($owner); $token->setExpiresAt((new DateTime())->add(new DateInterval('PT1H'))); $this->tokenService->expects($this->once())->method('createToken')->will($this->returnValue($token)); $response = $this->grant->createTokenResponse($request, $client, $owner); $body = json_decode($response->getBody(), true); $this->assertEquals('azerty', $body['access_token']); $this->assertEquals('Bearer', $body['token_type']); $this->assertEquals(3600, $body['expires_in']); $this->assertEquals(1, $body['owner_id']); }