Ejemplo n.º 1
0
 public function testCanSetScopesFromInstances()
 {
     $scope = new Scope();
     $scope->setName('bar');
     $accessToken = new AccessToken();
     $accessToken->setScopes([$scope]);
     $this->assertCount(1, $accessToken->getScopes());
 }
 public function testCanSetScopesFromInstances()
 {
     $scope = new Scope();
     $scope->setName('bar');
     $authorizationCode = new AuthorizationCode();
     $authorizationCode->setScopes([$scope]);
     $this->assertCount(1, $authorizationCode->getScopes());
 }
Ejemplo n.º 3
0
 public function testGettersAndSetters()
 {
     $scope = new Scope();
     $this->assertNull($scope->getId());
     $scope->setName('scope');
     $this->assertEquals('scope', $scope->getName());
     $scope->setDescription('Fooo');
     $this->assertEquals('Fooo', $scope->getDescription());
     $scope->setIsDefault(true);
     $this->assertTrue($scope->isDefault());
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider scopeProvider
  */
 public function testCanSaveToken($registeredScopes, $tokenScope, $throwException)
 {
     if ($throwException) {
         $this->setExpectedException(OAuth2Exception::class, null, 'invalid_scope');
     }
     $token = new AccessToken();
     if (empty($tokenScope)) {
         $scope = new Scope();
         $scope->setName('read');
         $this->scopeService->expects($this->once())->method('getDefaultScopes')->will($this->returnValue([$scope]));
     } else {
         $token->setScopes($tokenScope);
     }
     if (!$throwException) {
         $this->tokenRepository->expects($this->once())->method('save')->with($this->isInstanceOf(AbstractToken::class));
     }
     $scopes = [];
     foreach ($registeredScopes as $registeredScope) {
         $scope = new Scope();
         $scope->setName($registeredScope);
         $scopes[] = $scope;
     }
     $this->scopeService->expects($this->any())->method('getAll')->will($this->returnValue($scopes));
     $this->tokenService->createToken($token);
     $this->assertEquals(40, strlen($token->getToken()));
     if (empty($tokenScope)) {
         $this->assertCount(1, $token->getScopes());
     } else {
         $this->assertEquals(explode(' ', $tokenScope), $token->getScopes());
     }
 }