This commit is contained in:
Nyholm 2018-08-05 09:55:49 +02:00 committed by David Garcia
parent 3d81db203e
commit 75bab3016c
2 changed files with 25 additions and 13 deletions

View File

@ -1,5 +1,12 @@
<?php <?php
/*
* Copyright (C) 2013 Mailgun
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Mailgun\Tests\Api; namespace Mailgun\Tests\Api;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
@ -18,7 +25,7 @@ class EventTest extends TestCase
{ {
$this->setRequestMethod('GET'); $this->setRequestMethod('GET');
$this->setRequestUri('/v3/example.com/events'); $this->setRequestUri('/v3/example.com/events');
$this->setHttpResponse(new Response(200, ['Content-Type'=>'application/json'], <<<JSON $this->setHttpResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON'
{ {
"items": [ "items": [
{ {
@ -77,6 +84,5 @@ JSON
$api = $this->getApiMock(); $api = $this->getApiMock();
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$api->get(''); $api->get('');
} }
} }

View File

@ -13,7 +13,6 @@ use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Mailgun\Hydrator\ModelHydrator; use Mailgun\Hydrator\ModelHydrator;
use Mailgun\Mailgun; use Mailgun\Mailgun;
use Mailgun\Model\ApiResponse;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
/** /**
@ -44,12 +43,17 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
protected $testDomain; protected $testDomain;
private $requestMethod; private $requestMethod;
private $requestUri; private $requestUri;
private $requestHeaders; private $requestHeaders;
private $requestBody; private $requestBody;
private $httpResponse; private $httpResponse;
private $hydratedResponse; private $hydratedResponse;
private $hydrateClass; private $hydrateClass;
protected function setUp() protected function setUp()
@ -70,7 +74,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
->getMock(); ->getMock();
$httpClient $httpClient
->method('sendRequest') ->method('sendRequest')
->willReturn($this->httpResponse === null ? new Response() : $this->httpResponse); ->willReturn(null === $this->httpResponse ? new Response() : $this->httpResponse);
} }
if (null === $requestClient) { if (null === $requestClient) {
@ -100,7 +104,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
return $response instanceof ResponseInterface; return $response instanceof ResponseInterface;
}), }),
$this->callback(function ($class) use ($hydratorModelClass) { $this->callback(function ($class) use ($hydratorModelClass) {
return $hydratorModelClass === null || $class === $hydratorModelClass; return null === $hydratorModelClass || $class === $hydratorModelClass;
})); }));
if (null !== $this->hydratedResponse) { if (null !== $this->hydratedResponse) {
@ -109,6 +113,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
} }
$class = $this->getApiClass(); $class = $this->getApiClass();
return new $class($httpClient, $requestClient, $hydrator); return new $class($httpClient, $requestClient, $hydrator);
} }
@ -125,13 +130,11 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
public function validateRequestHeaders($headers) public function validateRequestHeaders($headers)
{ {
return $this->veriyProperty($this->requestHeaders, $headers); return $this->veriyProperty($this->requestHeaders, $headers);
} }
public function validateRequestBody($body) public function validateRequestBody($body)
{ {
return $this->veriyProperty($this->requestBody, $body); return $this->veriyProperty($this->requestBody, $body);
} }
protected function getMailgunClient() protected function getMailgunClient()
@ -169,7 +172,8 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
} }
/** /**
* Set request http method * Set request http method.
*
* @param string $httpMethod * @param string $httpMethod
*/ */
public function setRequestMethod($httpMethod) public function setRequestMethod($httpMethod)
@ -202,7 +206,8 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
} }
/** /**
* The class we should hydrate to * The class we should hydrate to.
*
* @param string $hydrateClass * @param string $hydrateClass
*/ */
public function setHydrateClass($hydrateClass) public function setHydrateClass($hydrateClass)
@ -213,20 +218,21 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
/** /**
* @param mixed|callable $property Example $this->requestMethod * @param mixed|callable $property Example $this->requestMethod
* @param mixed $value The actual value from the user. * @param mixed $value The actual value from the user.
*
* @return bool * @return bool
*/ */
private function veriyProperty($property, $value) private function veriyProperty($property, $value)
{ {
if ($property === null) { if (null === $property) {
return true; return true;
} }
return is_callable($property) ? ($property)($value) : $value === $property; return is_callable($property) ? ($property)($value) : $value === $property;
} }
/** /**
* Make sure expectException always exists, even on PHPUnit 4 * Make sure expectException always exists, even on PHPUnit 4.
*
* @param string $exception * @param string $exception
* @param string|null $message * @param string|null $message
*/ */