ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

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

  • Creator
    Topic
  • #18393

    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
  • #21512
    wwsh
    wwsh
    Participant

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

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.