Monday, January 31, 2022

[FIXED] Api-platform test Client::getResponse() is marked as @internal, what should I use instead?

Issue

I have a test case in Api-Platform where I am checking that when I do filtering on a collection it gets me the correct data.

Therefore if my response is:

{
  "hydra:member": [
       {
          "test": "123"
       },
       {
          "test": "123"
       }
  ]
}

I want to assert that every "test" returned is "123".

The way I am doing it is:

        foreach ($client->getResponse()->toArray()['hydra:member'] as $member) {
            self::assertEquals($member['test'], "123");
        }

This works well but I see that the method getResponse is marked as @internal which means it should not be used outside the library. Is there something else I can use?


Solution

There is a Client::request() method that returns an ResponseInterface, defined here.

public function request(string $method, string $url, array $options = []): ResponseInterface

Why don't you use that response directly?



Answered By - yivi

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.