Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joshlopes/afb3577552beba536c4a246c14089ece to your computer and use it in GitHub Desktop.
Save joshlopes/afb3577552beba536c4a246c14089ece to your computer and use it in GitHub Desktop.
# 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
Copy link

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