function DrupalTest::setMockContainerService

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/DrupalTest.php \Drupal\Tests\Core\DrupalTest::setMockContainerService()
  2. 8.9.x core/tests/Drupal/Tests/Core/DrupalTest.php \Drupal\Tests\Core\DrupalTest::setMockContainerService()
  3. 10 core/tests/Drupal/Tests/Core/DrupalTest.php \Drupal\Tests\Core\DrupalTest::setMockContainerService()

Sets up a mock expectation for the container get() method.

Parameters

string $service_name: The service name to expect for the get() method.

mixed $return: The value to return from the mocked container get() method.

31 calls to DrupalTest::setMockContainerService()
DrupalTest::testAccessManager in core/tests/Drupal/Tests/Core/DrupalTest.php
Tests the accessManager() method.
DrupalTest::testCache in core/tests/Drupal/Tests/Core/DrupalTest.php
Tests the cache() method.
DrupalTest::testClassResolver in core/tests/Drupal/Tests/Core/DrupalTest.php
Tests the classResolver method.
DrupalTest::testClassResolverWithClass in core/tests/Drupal/Tests/Core/DrupalTest.php
Tests the classResolver method when called with a class.
DrupalTest::testConfig in core/tests/Drupal/Tests/Core/DrupalTest.php
Tests the config() method.

... See full list

File

core/tests/Drupal/Tests/Core/DrupalTest.php, line 469

Class

DrupalTest
Tests the Drupal class.

Namespace

Drupal\Tests\Core

Code

protected function setMockContainerService($service_name, $return = NULL) {
    $expects = $this->container
        ->expects($this->once())
        ->method('get')
        ->with($service_name)
        ->willReturn($return ?? new \stdClass());
    \Drupal::setContainer($this->container);
}

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