Created
March 1, 2019 20:07
-
-
Save jonathanfranks/09e455d915ec4e5d1d6d0cb327ec22b5 to your computer and use it in GitHub Desktop.
Mocking service container in D8 unit test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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