mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-30 00:46:04 +03:00
66fd858a02
* Set dependencies for 7.3 and 8.x * Set GitHub Actions for PHP 7.3, 7.4 and 8.0 * Set Ubuntu version that supports PHP from 7.1 to 7.4 According to warnings raised by GitHub Actions, the alias for the latest Ubuntu version will upgrade soon to the newer 20.04 LTS instead of 18.04. Aiming to ensure the compatibility with previous PHP versions, it's safer to force the Ubuntu 18.04 that has the previous PHP version as built-in versions in the OS https://github.com/marketplace/actions/setup-php-action#github-hosted-runners * Fix dependencies for PHP ^7.3 and ^8.0 support * Run test suite with PHP versions from 7.3 to 8.1 * Broken Prophecy dependency for PHPUnit on PHP 8.1 This broken dependency doesn't allow us to run PHPUnit tests and ensure it works. Keeping the ^8.0 version should allow installations for non-maintainers on newer versions too. https://packagist.org/packages/phpspec/prophecy#1.12.2 requires - php: ^7.2 || ~8.0, <8.1 - ... * Use the latest Ubuntu version instead of a specific version * Prepare Changelog for PHP 8.0
130 lines
4.0 KiB
PHP
130 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* 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;
|
|
use Mailgun\Exception\InvalidArgumentException;
|
|
use Mailgun\Hydrator\ModelHydrator;
|
|
use Mailgun\Model\Stats\TotalResponse;
|
|
use Mailgun\Model\Stats\TotalResponseItem;
|
|
|
|
/**
|
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
|
*/
|
|
class StatsTest extends TestCase
|
|
{
|
|
protected function getApiClass()
|
|
{
|
|
return 'Mailgun\Api\Stats';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider totalProvider
|
|
*/
|
|
public function testTotal($queryParameters, $responseData)
|
|
{
|
|
$api = $this->getApiMock(null, null, new ModelHydrator());
|
|
$api->expects($this->once())
|
|
->method('httpGet')
|
|
->with('/v3/domain/stats/total', $queryParameters)
|
|
->willReturn(new Response(200, ['Content-Type' => 'application/json'], \json_encode($responseData)));
|
|
|
|
$total = $api->total('domain', $queryParameters);
|
|
|
|
$this->assertInstanceOf(TotalResponse::class, $total);
|
|
$this->assertCount(count($responseData['stats']), $total->getStats());
|
|
$this->assertContainsOnlyInstancesOf(TotalResponseItem::class, $total->getStats());
|
|
}
|
|
|
|
public function testTotalInvalidArgument()
|
|
{
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
$api = $this->getApiMock();
|
|
$api->total('');
|
|
}
|
|
|
|
public function totalProvider()
|
|
{
|
|
return [
|
|
'accepted events' => [
|
|
'queryParameters' => [
|
|
'event' => 'accepted',
|
|
],
|
|
'responseData' => $this->generateTotalResponsePayload([
|
|
[
|
|
'time' => $this->formatDate('-7 days'),
|
|
'accepted' => [
|
|
'outgoing' => 10,
|
|
'incoming' => 5,
|
|
'total' => 15,
|
|
],
|
|
],
|
|
]),
|
|
],
|
|
'failed events' => [
|
|
'queryParameters' => [
|
|
'event' => 'failed',
|
|
],
|
|
'responseData' => $this->generateTotalResponsePayload([
|
|
[
|
|
'time' => $this->formatDate('-7 days'),
|
|
'failed' => [
|
|
'permanent' => [
|
|
'bounce' => 4,
|
|
'delayed-bounce' => 1,
|
|
'suppress-bounce' => 1,
|
|
'suppress-unsubscribe' => 2,
|
|
'suppress-complaint' => 3,
|
|
'total' => 10,
|
|
],
|
|
'temporary' => [
|
|
'espblock' => 1,
|
|
],
|
|
],
|
|
],
|
|
]),
|
|
],
|
|
'delivered events' => [
|
|
'queryParameters' => [
|
|
'event' => 'delivered',
|
|
],
|
|
'responseData' => $this->generateTotalResponsePayload([
|
|
[
|
|
'time' => $this->formatDate('-7 days'),
|
|
'delivered' => [
|
|
'smtp' => 15,
|
|
'http' => 5,
|
|
'total' => 20,
|
|
],
|
|
],
|
|
]),
|
|
],
|
|
];
|
|
}
|
|
|
|
private function generateTotalResponsePayload(array $stats, $start = '-7 days', $end = 'now', $resolution = 'day')
|
|
{
|
|
return [
|
|
'end' => $this->formatDate($end),
|
|
'resolution' => $resolution,
|
|
'start' => $this->formatDate($start),
|
|
'stats' => $stats,
|
|
];
|
|
}
|
|
|
|
private function formatDate($time = 'now')
|
|
{
|
|
return (new \DateTime($time, new \DateTimeZone('UTC')))->format('D, d M Y H:i:s T');
|
|
}
|
|
}
|