function PostSaveProcessTest::testDiscoveriesToClear

Tests queueing discoveries to clear, deduplicated by class name.

File

core/modules/views/tests/src/Unit/PostSaveProcessTest.php, line 34

Class

PostSaveProcessTest
Tests Drupal\views\PostSaveProcess.

Namespace

Drupal\Tests\views\Unit

Code

public function testDiscoveriesToClear() : void {
  $postSaveProcess = new PostSaveProcess();
  $this->assertSame([], $postSaveProcess->getDiscoveriesToClear());
  // Two distinct CachedDiscoveryInterface implementations.
  [$discoveryA, $discoveryB] = \array_map(fn(string $class) => $this->createStub($class), [
    EntityTypeManagerInterface::class,
    TypedDataManagerInterface::class,
  ]);
  $postSaveProcess->addDiscoveryToClear($discoveryA);
  // Adding the same instance again must not create a duplicate entry.
  $postSaveProcess->addDiscoveryToClear($discoveryA);
  $this->assertCount(1, $postSaveProcess->getDiscoveriesToClear());
  // A discovery of a different class is queued as its own entry.
  $postSaveProcess->addDiscoveryToClear($discoveryB);
  $this->assertSame([
    get_class($discoveryA) => $discoveryA,
    get_class($discoveryB) => $discoveryB,
  ], $postSaveProcess->getDiscoveriesToClear());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.