function LibraryDiscoveryCollectorTest::testDestruct

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryCollectorTest::testDestruct()
  2. 10 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryCollectorTest::testDestruct()
  3. 11.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryCollectorTest::testDestruct()

Tests the destruct method.

@covers ::destruct

File

core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php, line 131

Class

LibraryDiscoveryCollectorTest
@coversDefaultClass \Drupal\Core\Asset\LibraryDiscoveryCollector @group Asset

Namespace

Drupal\Tests\Core\Asset

Code

public function testDestruct() {
    $this->activeTheme = $this->getMockBuilder(ActiveTheme::class)
        ->disableOriginalConstructor()
        ->getMock();
    $this->themeManager
        ->expects($this->exactly(5))
        ->method('getActiveTheme')
        ->willReturn($this->activeTheme);
    $this->activeTheme
        ->expects($this->once())
        ->method('getName')
        ->willReturn('kitten_theme');
    $this->libraryDiscoveryCollector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser, $this->themeManager);
    $this->libraryDiscoveryParser
        ->expects($this->once())
        ->method('buildByExtension')
        ->with('test')
        ->willReturn($this->libraryData);
    $lock_key = 'library_info:kitten_theme:Drupal\\Core\\Cache\\CacheCollector';
    $this->lock
        ->expects($this->once())
        ->method('acquire')
        ->with($lock_key)
        ->willReturn(TRUE);
    $this->cache
        ->expects($this->exactly(2))
        ->method('get')
        ->with('library_info:kitten_theme')
        ->willReturn(FALSE);
    $this->cache
        ->expects($this->once())
        ->method('set')
        ->with('library_info:kitten_theme', [
        'test' => $this->libraryData,
    ], Cache::PERMANENT, [
        'library_info',
    ]);
    $this->lock
        ->expects($this->once())
        ->method('release')
        ->with($lock_key);
    // This should get data and persist the key.
    $this->libraryDiscoveryCollector
        ->get('test');
    $this->libraryDiscoveryCollector
        ->destruct();
}

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