public function EntityControllerCacheTest::testDeveloperEntityControllerCache in Apigee Edge 8
Tests developer entity controller cache.
File
- tests/
src/ Kernel/ EntityControllerCacheTest.php, line 66
Class
- EntityControllerCacheTest
- Apigee Edge entity controller cache tests.
Namespace
Drupal\Tests\apigee_edge\KernelCode
public function testDeveloperEntityControllerCache() {
$developer_cache = $this->container
->get('apigee_edge.controller.cache.developer');
$developer_id_cache = $this->container
->get('apigee_edge.controller.cache.developer_ids');
// Generate developer entities with random data.
$developers = [];
for ($i = 0; $i < 3; $i++) {
$id = $this
->getRandomUniqueId();
$developers[$id] = new Developer([
'developerId' => $id,
'email' => strtolower($this
->randomMachineName()) . '@example.com',
]);
}
$this
->saveAllEntitiesAndValidate($developers, $developer_cache, $developer_id_cache);
/** @var \Apigee\Edge\Api\Management\Entity\DeveloperInterface $developer */
foreach ($developers as $developer) {
// Load developer by email and by id.
$this
->assertSame($developer, $developer_cache
->getEntity($developer
->getEmail()));
$this
->assertSame($developer, $developer_cache
->getEntity($developer
->getDeveloperId()));
$this
->assertContains($developer
->getEmail(), $developer_id_cache
->getIds());
// Pass an invalid entity id to ensure it does not cause any trouble
// anymore.
// @see \Drupal\apigee_edge\Entity\Controller\Cache\EntityCache::removeEntities()
// @see https://www.drupal.org/project/drupal/issues/3017753
$developer_cache
->removeEntities([
$developer
->getDeveloperId(),
$this
->getRandomGenerator()
->string(),
]);
$this
->assertNull($developer_cache
->getEntity($developer
->getEmail()));
$this
->assertNull($developer_cache
->getEntity($developer
->getDeveloperId()));
$this
->assertNotContains($developer
->getEmail(), $developer_id_cache
->getIds());
}
$this
->assertEmptyCaches($developer_cache, $developer_id_cache);
}