Created
May 24, 2017 10:06
-
-
Save joshlopes/afb3577552beba536c4a246c14089ece to your computer and use it in GitHub Desktop.
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
# services.yml | |
app.some_service: | |
class: SomeService | |
calls: | |
- [setSomeOtherService, ['@app.someOtherService'] | |
# Test | |
function doSomethingWithOtherService() | |
{ | |
$mockedOtherService = $this->prophesize(SomeOtherService::class); | |
$mockedOtherService->find(Argument::Type(SomeType::class))->willReturn('something'); | |
$mockedOtherService = $mockedOtherService->reveal(); | |
$someService = new SomeService(); | |
$someService->setSomeOtherService($mockedOtherService); | |
$return = $someService->doSomething(); | |
$this->assertEquals('Test', $return); | |
} |
jakzal
commented
May 24, 2017
# services.yml
app.some_service:
class: SomeService
arguments:
- '@app.someOtherService'
private $someService;
private $mockedOtherService;
function setUp()
{
$this->mockedOtherService = $this->prophesize(SomeOtherService::class);
$this->someService = new SomeService($this->mockedOtherService->reveal());
}
function doSomethingWithOtherService()
{
$this->mockedOtherService->find(Argument::Type(SomeType::class))->willReturn('something');
$return = $someService->doSomething();
$this->assertEquals('Test', $return);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment