Skip to content

Instantly share code, notes, and snippets.

@jonathanfranks
Created March 1, 2019 20:07
Show Gist options
  • Save jonathanfranks/09e455d915ec4e5d1d6d0cb327ec22b5 to your computer and use it in GitHub Desktop.
Save jonathanfranks/09e455d915ec4e5d1d6d0cb327ec22b5 to your computer and use it in GitHub Desktop.
Mocking service container in D8 unit test
$fakeService = $this->createMock('Drupal\fake\Services\Fake');
$fakeService->method('serviceMethod')
->withAnyParameters()
->willReturn(0);
$container = new ContainerBuilder();
$container->set('fake.service_name', $fakeService);
\Drupal::setContainer($container);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment