trait ViewsLoggerTestTrait

Same name in other branches
  1. 10 core/modules/views/tests/src/Traits/ViewsLoggerTestTrait.php \Drupal\Tests\views\Traits\ViewsLoggerTestTrait

Provides helper functions for logging in views.

Hierarchy

11 files declare their use of ViewsLoggerTestTrait
ContactLinkTest.php in core/modules/contact/tests/src/Unit/ContactLinkTest.php
EntityLinkTest.php in core/modules/comment/tests/src/Unit/Plugin/views/field/EntityLinkTest.php
EntityOperationsUnitTest.php in core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php
LinkApproveTest.php in core/modules/comment/tests/src/Unit/Plugin/views/field/LinkApproveTest.php
LinkBaseTest.php in core/modules/views/tests/src/Unit/Plugin/views/field/LinkBaseTest.php

... See full list

File

core/modules/views/tests/src/Traits/ViewsLoggerTestTrait.php, line 14

Namespace

Drupal\Tests\views\Traits
View source
trait ViewsLoggerTestTrait {
    
    /**
     * Sets up a mock logger for when views can't load an entity.
     */
    public function setUpMockLoggerWithMissingEntity() : void {
        $loggerFactory = $this->createMock(LoggerChannelFactoryInterface::class);
        $logger = $this->createMock(LoggerInterface::class);
        $logger->expects($this->once())
            ->method('error')
            ->with('The view %id failed to load an entity of type %entity_type at row %index for field %field', $this->anything());
        $loggerFactory->expects($this->once())
            ->method('get')
            ->willReturn($logger);
        $container = new ContainerBuilder();
        $container->set('logger.factory', $loggerFactory);
        \Drupal::setContainer($container);
    }

}

Members

Title Sort descending Modifiers Object type Summary
ViewsLoggerTestTrait::setUpMockLoggerWithMissingEntity public function Sets up a mock logger for when views can't load an entity.

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