OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions Functional Tests, Setting Mock Services

This topic contains 1 reply, has 2 voices, and was last updated by  wwsh 7 years, 9 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #34168

    archy_bold
    Participant

    Hi there.

    I’m trying to test one of my controllers and have followed the documentation, all works well. However I want to test an action that will connect to an external web service. I don’t actually want to test the web service itself so I’d prefer to mock it.

    I’ve looked into how to do that in Symfony and it seems you can replace the service definitions in the container by calling set() on it, replacing the existing ID with a mocked service.

    The only issue is that, whilst I can see calling the following:

    in my test function will get the mocked service, once I call $client->request();, the one returned in the controller itself is the actual service, not the mocked one. This seems to suggest that the client is resetting once I make the request.

    I understand that the client will reset on the next request, but I don’t see how I can mock services if the client resets on the first request. I feel like I’m missing something because everything I’ve read suggests this should work in Symfony.

    I’ve seen other suggestions that say I should write a test-specific kernel, but I want to keep my code in the bundle rather than messing with the underlying part of Symfony.

    I’ve also looked into Guzzle mocks, but I don’t see how I can get these mocks into my services if I can’t access them.

    Any suggestions?

    Thanks,
    Simon

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #34169

    wwsh
    Participant

    Please supply the class code on how do you mock the service.

Viewing 1 replies (of 1 total)

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top