mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-18 05:43:15 +03:00
Add additional events to TotalResponseItem (#739)
This commit is contained in:
parent
66fd858a02
commit
a39d0b0651
@ -21,6 +21,10 @@ final class TotalResponseItem
|
||||
private $delivered;
|
||||
private $failed;
|
||||
private $complained;
|
||||
private $opened;
|
||||
private $clicked;
|
||||
private $unsubscribed;
|
||||
private $stored;
|
||||
|
||||
public static function create(array $data): self
|
||||
{
|
||||
@ -30,6 +34,10 @@ final class TotalResponseItem
|
||||
$model->delivered = $data['delivered'] ?? [];
|
||||
$model->failed = $data['failed'] ?? [];
|
||||
$model->complained = $data['complained'] ?? [];
|
||||
$model->opened = $data['opened'] ?? [];
|
||||
$model->clicked = $data['clicked'] ?? [];
|
||||
$model->unsubscribed = $data['unsubscribed'] ?? [];
|
||||
$model->stored = $data['stored'] ?? [];
|
||||
|
||||
return $model;
|
||||
}
|
||||
@ -62,4 +70,24 @@ final class TotalResponseItem
|
||||
{
|
||||
return $this->complained;
|
||||
}
|
||||
|
||||
public function getOpened(): array
|
||||
{
|
||||
return $this->opened;
|
||||
}
|
||||
|
||||
public function getClicked(): array
|
||||
{
|
||||
return $this->clicked;
|
||||
}
|
||||
|
||||
public function getUnsubscribed(): array
|
||||
{
|
||||
return $this->unsubscribed;
|
||||
}
|
||||
|
||||
public function getStored(): array
|
||||
{
|
||||
return $this->stored;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,22 @@ class StatsTest extends TestCase
|
||||
$this->assertInstanceOf(TotalResponse::class, $total);
|
||||
$this->assertCount(count($responseData['stats']), $total->getStats());
|
||||
$this->assertContainsOnlyInstancesOf(TotalResponseItem::class, $total->getStats());
|
||||
|
||||
$event = $queryParameters['event'];
|
||||
$responseStat = $total->getStats()[0];
|
||||
$statGetter = 'get'.ucwords($event);
|
||||
|
||||
if ('failed' !== $event) {
|
||||
$expectedTotal = $responseData['stats'][0][$event]['total'];
|
||||
$actualTotal = $responseStat->$statGetter()['total'];
|
||||
}
|
||||
|
||||
if ('failed' === $event) {
|
||||
$expectedTotal = $responseData['stats'][0][$event]['permanent']['total'];
|
||||
$actualTotal = $responseStat->$statGetter()['permanent']['total'];
|
||||
}
|
||||
|
||||
$this->assertEquals($expectedTotal, $actualTotal);
|
||||
}
|
||||
|
||||
public function testTotalInvalidArgument()
|
||||
@ -109,6 +125,58 @@ class StatsTest extends TestCase
|
||||
],
|
||||
]),
|
||||
],
|
||||
'clicked events' => [
|
||||
'queryParameters' => [
|
||||
'event' => 'clicked',
|
||||
],
|
||||
'responseData' => $this->generateTotalResponsePayload([
|
||||
[
|
||||
'time' => $this->formatDate('-7 days'),
|
||||
'clicked' => [
|
||||
'total' => 7,
|
||||
],
|
||||
],
|
||||
]),
|
||||
],
|
||||
'opened events' => [
|
||||
'queryParameters' => [
|
||||
'event' => 'opened',
|
||||
],
|
||||
'responseData' => $this->generateTotalResponsePayload([
|
||||
[
|
||||
'time' => $this->formatDate('-7 days'),
|
||||
'opened' => [
|
||||
'total' => 19,
|
||||
],
|
||||
],
|
||||
]),
|
||||
],
|
||||
'unsubscribed events' => [
|
||||
'queryParameters' => [
|
||||
'event' => 'unsubscribed',
|
||||
],
|
||||
'responseData' => $this->generateTotalResponsePayload([
|
||||
[
|
||||
'time' => $this->formatDate('-7 days'),
|
||||
'unsubscribed' => [
|
||||
'total' => 10,
|
||||
],
|
||||
],
|
||||
]),
|
||||
],
|
||||
'stored events' => [
|
||||
'queryParameters' => [
|
||||
'event' => 'stored',
|
||||
],
|
||||
'responseData' => $this->generateTotalResponsePayload([
|
||||
[
|
||||
'time' => $this->formatDate('-7 days'),
|
||||
'stored' => [
|
||||
'total' => 12,
|
||||
],
|
||||
],
|
||||
]),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user