public function PluginDiscoveryDecoratorTest::testUseCachesWithCachedDecoratedDiscovery in Plugin 8.2
@covers ::useCaches
File
- tests/
src/ Unit/ PluginDiscovery/ PluginDiscoveryDecoratorTest.php, line 121
Class
- PluginDiscoveryDecoratorTest
- @coversDefaultClass \Drupal\plugin\PluginDiscovery\PluginDiscoveryDecorator
Namespace
Drupal\Tests\plugin\Unit\PluginDiscoveryCode
public function testUseCachesWithCachedDecoratedDiscovery() {
$this->decoratedDiscovery = $this
->getMockForAbstractClass(PluginDiscoveryDecoratorTestCachedDiscovery::class);
$this->sut = new PluginDiscoveryDecorator($this->decoratedDiscovery);
$this->decoratedDiscovery
->expects($this
->once())
->method('clearCachedDefinitions');
$this->decoratedDiscovery
->expects($this
->exactly(3))
->method('getDefinitions')
->willReturn([]);
// There are no cached definitions yet, so this should call the decorated
// discovery.
$this->sut
->getDefinitions();
// This should return the cached definitions.
$this->sut
->getDefinitions();
$this->sut
->useCaches(FALSE);
// This should return newly built definitions, so this should call the
// decorated discovery.
$this->sut
->getDefinitions();
// This should return newly built definitions again, because we disabled
// caching.
$this->sut
->getDefinitions();
}