trait EntityControllerCacheUtilsTrait in Apigee Edge 8
A trait to common functions of entity controller tests.
Hierarchy
- trait \Drupal\Tests\apigee_edge\Traits\EntityControllerCacheUtilsTrait
2 files declare their use of EntityControllerCacheUtilsTrait
- EntityControllerCacheTest.php in tests/src/ Kernel/ EntityControllerCacheTest.php 
- EntityControllerCacheTest.php in modules/apigee_edge_teams/ tests/ src/ Kernel/ EntityControllerCacheTest.php 
File
- tests/src/ Traits/ EntityControllerCacheUtilsTrait.php, line 28 
Namespace
Drupal\Tests\apigee_edge\TraitsView source
trait EntityControllerCacheUtilsTrait {
  /**
   * Saves entities into the entity cache and checks the result.
   *
   * @param \Apigee\Edge\Entity\EntityInterface[] $entities
   *   Apigee Edge entities to save into the cache.
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\EntityCacheInterface $entity_cache
   *   The entity cache implementation.
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\EntityIdCacheInterface $entity_id_cache
   *   The entity id cache implementation.
   */
  protected function saveAllEntitiesAndValidate(array $entities, EntityCacheInterface $entity_cache, EntityIdCacheInterface $entity_id_cache) {
    // Save the generated entities into the controller cache.
    $entity_cache
      ->saveEntities($entities);
    $this
      ->assertSame($entities, $entity_cache
      ->getEntities());
    // Set cache states to TRUE.
    $entity_cache
      ->allEntitiesInCache(TRUE);
    $this
      ->assertTrue($entity_cache
      ->isAllEntitiesInCache());
    $this
      ->assertTrue($entity_id_cache
      ->isAllIdsInCache());
  }
  /**
   * Checks whether the cache is properly cleared.
   *
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\EntityCacheInterface $entity_cache
   *   The entity cache implementation.
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\EntityIdCacheInterface $entity_id_cache
   *   The entity id cache implementation.
   */
  protected function assertEmptyCaches(EntityCacheInterface $entity_cache, EntityIdCacheInterface $entity_id_cache) {
    $this
      ->assertEmpty($entity_cache
      ->getEntities());
    $this
      ->assertEmpty($entity_id_cache
      ->getIds());
    $this
      ->assertFalse($entity_cache
      ->isAllEntitiesInCache());
    $this
      ->assertFalse($entity_id_cache
      ->isAllIdsInCache());
  }
  /**
   * Gets a random unique ID.
   */
  protected function getRandomUniqueId() : string {
    return $this->container
      ->get('uuid')
      ->generate();
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| EntityControllerCacheUtilsTrait:: | protected | function | Checks whether the cache is properly cleared. | |
| EntityControllerCacheUtilsTrait:: | protected | function | Gets a random unique ID. | |
| EntityControllerCacheUtilsTrait:: | protected | function | Saves entities into the entity cache and checks the result. | 
