1

I need to test my class, and the class make an Curl request.

I want to check the data passed to the curl request, so this is the code:

class SendCurl {

    /** @var GuzzleHttp\Client */
    protected $client;

    public function __construct(\GuzzleHttp\Client $client) {
         $this->client = $client;
    }

    public function send() {
        $this->curl();
    }

    protected function curl() {
        $this->client->get(
            $this->statHatUrl, [
                'headers'         => ['Content-Type' => 'application/json'],
                'body'            => $this->getValidJson(),
            ]
        );
    }

}

now as you can see here, I call this class like this:

$api = new SendCurl($client);
$api->send();

now I want to check the data send to the curl get request so what I did till now is to use mockery

  $client = Mockery::mock('GuzzleHttp\Client');
  $client->shouldReceive('get')
         ->once()
         ->with(Mockery::type('string'), Mockery::type('array'));

  $obj = new SendCurl($client);
  $obj->send();

so I successfully check that the first parameter to the "get" method of the client is a string, and that the second parameter is an array.

BUT how do I compare them to an exact value.

something like:

 ->with(Mockery::type('string') && equalsTo('www.WhatEver.com'))

dont mind the syntax, only the idea.

1 Answer 1

2

Pass the expected values to the with() method:

$client = Mockery::mock('GuzzleHttp\Client');
$client->shouldReceive('get')
       ->once()
       ->with('www.WhatEver.com', array(1, 2));
Sign up to request clarification or add additional context in comments.

2 Comments

can I do some regex on it? like: /^*wha*$/ or similiar?
with('/^foo/') OR with(matchesPattern('/^foo/')) You have all the info at the docs: docs.mockery.io/en/latest/reference/argument_validation.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.