function ViewsLoggerTestTrait::setUpMockLoggerWithMissingEntity

Same name in other branches
  1. 11.x core/modules/views/tests/src/Traits/ViewsLoggerTestTrait.php \Drupal\Tests\views\Traits\ViewsLoggerTestTrait::setUpMockLoggerWithMissingEntity()

Sets up a mock logger for when views can't load an entity.

11 calls to ViewsLoggerTestTrait::setUpMockLoggerWithMissingEntity()
ContactLinkTest::setUp in core/modules/contact/tests/src/Unit/ContactLinkTest.php
EntityLinkTest::setUp in core/modules/comment/tests/src/Unit/Plugin/views/field/EntityLinkTest.php
EntityOperationsUnitTest::testRenderWithoutEntity in core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php
@covers ::render
LinkApproveTest::setUp in core/modules/comment/tests/src/Unit/Plugin/views/field/LinkApproveTest.php
LinkBaseTest::setUp 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 19

Class

ViewsLoggerTestTrait
Provides helper functions for logging in views.

Namespace

Drupal\Tests\views\Traits

Code

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);
}

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