Skip to content

Commit

Permalink
Mock method only if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Nascimento committed Jun 16, 2017
1 parent 1fcbe3f commit c08349a
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions tests/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public function setup()
*/
public function mustSendRequest()
{
$this->guzzleClientMock->method('createRequest')
->willReturn($this->getMock('GuzzleHttp\Message\RequestInterface'));
if ($this->isUsingLegacyGuzzle()) {
$this->guzzleClientMock->method('createRequest')
->willReturn($this->getMock('GuzzleHttp\Message\RequestInterface'));
}

$responseMock = $this->getResponseMock();

Expand All @@ -58,18 +60,20 @@ public function mustSendRequest()
*/
public function mustSendRequestWithProperContent()
{
$this->guzzleClientMock->method('createRequest')
->with(
RequestInterface::HTTP_POST,
self::REQUEST_PATH,
[
'json' => [
'content' => self::CONTENT,
'api_key' => self::API_KEY
if ($this->isUsingLegacyGuzzle()) {
$this->guzzleClientMock->method('createRequest')
->with(
RequestInterface::HTTP_POST,
self::REQUEST_PATH,
[
'json' => [
'content' => self::CONTENT,
'api_key' => self::API_KEY
]
]
]
)
->willReturn($this->getMock('GuzzleHttp\Message\RequestInterface'));
)
->willReturn($this->getMock('GuzzleHttp\Message\RequestInterface'));
}

$responseMock = $this->getResponseMock();

Expand All @@ -94,8 +98,10 @@ public function mustReturnClientExeptionWhenGetRequestException()
$this->getGuzzleRequestInterfaceName()
);

$this->guzzleClientMock->method('createRequest')
->willReturn($guzzleRequestMock);
if ($this->isUsingLegacyGuzzle()) {
$this->guzzleClientMock->method('createRequest')
->willReturn($guzzleRequestMock);
}

$this->guzzleClientMock->method('send')
->will(
Expand Down Expand Up @@ -127,8 +133,10 @@ public function mustSetDefaultTimeout()
)->disableOriginalConstructor()
->getMock();

$this->guzzleClientMock->method('createRequest')
->willReturn($guzzleRequestMock);
if ($this->isUsingLegacyGuzzle()) {
$this->guzzleClientMock->method('createRequest')
->willReturn($guzzleRequestMock);
}

$responseMock = $this->getResponseMock();

Expand Down

0 comments on commit c08349a

Please sign in to comment.