public function testDoesCaseSensitiveTest() { $token = new AccessToken(); $token->setToken('Token'); $this->tokenRepository->expects($this->once())->method('findByToken')->with('token')->will($this->returnValue($token)); $this->assertNull($this->tokenService->getToken('token')); }
public function generateAccessToken(TokenOwnerInterface $user) { $token = new AccessToken(); $token->setOwner($user); $token->setToken(substr(md5(rand()), 0, 7)); $expiresAt = new DateTime(); $token->setExpiresAt($expiresAt->modify('+1 hour')); $this->entityManager->persist($token); $this->entityManager->flush(); return $token->getToken(); }
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']); }
public function testGettersAndSetters() { $owner = $this->getMock(TokenOwnerInterface::class); $client = new Client(); $expiresAt = new DateTime(); $accessToken = new AccessToken(); $accessToken->setToken('token'); $accessToken->setScopes(['scope1', 'scope2']); $accessToken->setClient($client); $accessToken->setExpiresAt($expiresAt); $accessToken->setOwner($owner); $this->assertEquals('token', $accessToken->getToken()); $this->assertCount(2, $accessToken->getScopes()); $this->assertTrue($accessToken->matchScopes('scope1')); $this->assertFalse($accessToken->matchScopes('scope3')); $this->assertSame($client, $accessToken->getClient()); $this->assertEquals($expiresAt, $accessToken->getExpiresAt()); $this->assertSame($owner, $accessToken->getOwner()); }
/** * @return AccessToken */ private function getValidAccessToken() { $accessToken = new AccessToken(); $accessToken->setToken('azerty_access'); $accessToken->setScopes('read'); $validDate = new DateTime(); $validDate->add(new DateInterval('PT1H')); $accessToken->setExpiresAt($validDate); return $accessToken; }