You are here

public function ContainerTest::test_has in Service Container 7.2

Same name and namespace in other branches
  1. 7 tests/src/DependencyInjection/ContainerTest.php \Drupal\Tests\service_container\DependencyInjection\ContainerTest::test_has()

Tests that Container::has() works properly.

@covers ::has()

File

tests/src/DependencyInjection/ContainerTest.php, line 163
Contains \Drupal\Tests\service_container\DependencyInjection\ContainerTest

Class

ContainerTest
@coversDefaultClass \Drupal\service_container\DependencyInjection\Container @group dic

Namespace

Drupal\Tests\service_container\DependencyInjection

Code

public function test_has() {
  $this
    ->assertTrue($this->container
    ->has('other.service'));
  $this
    ->assertFalse($this->container
    ->has('another.service'));

  // Set the service manually, ensure that its also respected.
  $mock_service = new MockService();
  $this->container
    ->set('another.service', $mock_service);
  $this
    ->assertTrue($this->container
    ->has('another.service'));
}