mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 04:26:02 +03:00
cs
This commit is contained in:
parent
3d81db203e
commit
75bab3016c
@ -1,5 +1,12 @@
|
||||
<?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;
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
@ -18,7 +25,7 @@ class EventTest extends TestCase
|
||||
{
|
||||
$this->setRequestMethod('GET');
|
||||
$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": [
|
||||
{
|
||||
@ -77,6 +84,5 @@ JSON
|
||||
$api = $this->getApiMock();
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$api->get('');
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Mailgun\Hydrator\ModelHydrator;
|
||||
use Mailgun\Mailgun;
|
||||
use Mailgun\Model\ApiResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
@ -44,12 +43,17 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||
protected $testDomain;
|
||||
|
||||
private $requestMethod;
|
||||
|
||||
private $requestUri;
|
||||
|
||||
private $requestHeaders;
|
||||
|
||||
private $requestBody;
|
||||
|
||||
private $httpResponse;
|
||||
|
||||
private $hydratedResponse;
|
||||
|
||||
private $hydrateClass;
|
||||
|
||||
protected function setUp()
|
||||
@ -70,7 +74,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||
->getMock();
|
||||
$httpClient
|
||||
->method('sendRequest')
|
||||
->willReturn($this->httpResponse === null ? new Response() : $this->httpResponse);
|
||||
->willReturn(null === $this->httpResponse ? new Response() : $this->httpResponse);
|
||||
}
|
||||
|
||||
if (null === $requestClient) {
|
||||
@ -100,7 +104,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||
return $response instanceof ResponseInterface;
|
||||
}),
|
||||
$this->callback(function ($class) use ($hydratorModelClass) {
|
||||
return $hydratorModelClass === null || $class === $hydratorModelClass;
|
||||
return null === $hydratorModelClass || $class === $hydratorModelClass;
|
||||
}));
|
||||
|
||||
if (null !== $this->hydratedResponse) {
|
||||
@ -109,6 +113,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$class = $this->getApiClass();
|
||||
|
||||
return new $class($httpClient, $requestClient, $hydrator);
|
||||
}
|
||||
|
||||
@ -125,13 +130,11 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||
public function validateRequestHeaders($headers)
|
||||
{
|
||||
return $this->veriyProperty($this->requestHeaders, $headers);
|
||||
|
||||
}
|
||||
|
||||
public function validateRequestBody($body)
|
||||
{
|
||||
return $this->veriyProperty($this->requestBody, $body);
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public function setHydrateClass($hydrateClass)
|
||||
@ -212,21 +217,22 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
private function veriyProperty($property, $value)
|
||||
{
|
||||
if ($property === null) {
|
||||
if (null === $property) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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|null $message
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user