class EntityCollectorTest in Simple OAuth (OAuth2) & OpenID Connect 8.2
Same name and namespace in other branches
- 8.4 tests/src/Unit/EntityCollectorTest.php \Drupal\Tests\simple_oauth\Unit\EntityCollectorTest
- 8.3 tests/src/Unit/EntityCollectorTest.php \Drupal\Tests\simple_oauth\Unit\EntityCollectorTest
- 5.x tests/src/Unit/EntityCollectorTest.php \Drupal\Tests\simple_oauth\Unit\EntityCollectorTest
@coversDefaultClass \Drupal\simple_oauth\ExpiredCollector @group simple_oauth
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\simple_oauth\Unit\EntityCollectorTest
Expanded class hierarchy of EntityCollectorTest
File
- tests/
src/ Unit/ EntityCollectorTest.php, line 21
Namespace
Drupal\Tests\simple_oauth\UnitView source
class EntityCollectorTest extends UnitTestCase {
/**
* @covers ::collect
*/
public function testCollect() {
list($expired_collector, $query, ) = $this
->buildProphecies();
$query
->condition('expire', 42, '<')
->shouldBeCalledTimes(1);
$this
->assertArrayEquals([
1,
52,
], array_map(function ($entity) {
return $entity
->id();
}, $expired_collector
->collect()));
}
/**
* @covers ::collectForClient
*/
public function testCollectForClient() {
list($expired_collector, $query, ) = $this
->buildProphecies();
$client = $this
->prophesize(Oauth2ClientInterface::class);
$client
->id()
->willReturn(35);
$query
->condition('client', 35)
->shouldBeCalledTimes(1);
$tokens = $expired_collector
->collectForClient($client
->reveal());
$this
->assertArrayEquals([
1,
52,
], array_map(function ($entity) {
return $entity
->id();
}, $tokens));
}
/**
* @covers ::collectForAccount
*/
public function testCollectForAccount() {
list($expired_collector, $token_query, , , $client_storage) = $this
->buildProphecies();
$account = $this
->prophesize(AccountInterface::class);
$account
->id()
->willReturn(22);
$token_query
->condition('auth_user_id', 22)
->shouldBeCalledTimes(1);
$client_storage
->loadByProperties([
'user_id' => 22,
])
->shouldBeCalledTimes(1);
$token_query
->condition('client', 6)
->shouldBeCalledTimes(1);
$tokens = $expired_collector
->collectForAccount($account
->reveal());
$this
->assertArrayEquals([
1,
52,
], array_map(function ($entity) {
return $entity
->id();
}, $tokens));
}
/**
* @covers ::collect
*/
public function testDeleteMultipleTokens() {
list($expired_collector, , $storage) = $this
->buildProphecies();
$storage
->delete([
'foo',
])
->shouldBeCalledTimes(1);
$expired_collector
->deleteMultipleTokens([
'foo',
]);
}
protected function buildProphecies() {
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$token_storage = $this
->prophesize(EntityStorageInterface::class);
$token_query = $this
->prophesize(QueryInterface::class);
$token_query
->execute()
->willReturn([
1 => '1',
52 => '52',
]);
$token_storage
->getQuery()
->willReturn($token_query
->reveal());
$token1 = $this
->prophesize(Oauth2Token::class);
$token1
->id()
->willReturn(1);
$token52 = $this
->prophesize(Oauth2Token::class);
$token52
->id()
->willReturn(52);
$token_storage
->loadMultiple([
'1',
'52',
])
->willReturn([
1 => $token1
->reveal(),
52 => $token52
->reveal(),
]);
$client_storage = $this
->prophesize(EntityStorageInterface::class);
$client_query = $this
->prophesize(QueryInterface::class);
$client_query
->execute()
->willReturn([
6 => '6',
]);
$client_storage
->getQuery()
->willReturn($client_query
->reveal());
$client6 = $this
->prophesize(Oauth2Client::class);
$client6
->id()
->willReturn(6);
$client_storage
->loadByProperties([
'user_id' => 22,
])
->willReturn([
6 => $client6
->reveal(),
]);
$entity_type_manager
->getStorage('oauth2_token')
->willReturn($token_storage
->reveal());
$entity_type_manager
->getStorage('oauth2_client')
->willReturn($client_storage
->reveal());
$date_time = $this
->prophesize(TimeInterface::class);
$date_time
->getRequestTime()
->willReturn(42);
$expired_collector = new ExpiredCollector($entity_type_manager
->reveal(), $date_time
->reveal());
return [
$expired_collector,
$token_query,
$token_storage,
$client_query,
$client_storage,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityCollectorTest:: |
protected | function | ||
EntityCollectorTest:: |
public | function | @covers ::collect | |
EntityCollectorTest:: |
public | function | @covers ::collectForAccount | |
EntityCollectorTest:: |
public | function | @covers ::collectForClient | |
EntityCollectorTest:: |
public | function | @covers ::collect | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |