setMockContainerService example

$this->expectException(ContainerNotInitializedException::class);
    $this->expectExceptionMessage('\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.');
    \Drupal::getContainer();
  }

  /** * Tests the service() method. * * @covers ::service */
  public function testService() {
    $this->setMockContainerService('test_service');
    $this->assertNotNull(\Drupal::service('test_service'));
  }

  /** * Tests the currentUser() method. * * @covers ::currentUser */
  public function testCurrentUser() {
    $this->setMockContainerService('current_user');
    $this->assertNotNull(\Drupal::currentUser());
  }
Home | Imprint | This part of the site doesn't use cookies.