mardi 23 décembre 2014

phpunit testing, check the arguments passed to function

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.


Aucun commentaire:

Enregistrer un commentaire