55 lines
2.0 KiB
PHP
55 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Service;
|
|
|
|
use App\Service\MailjetApiClient;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\NullLogger;
|
|
use Symfony\Component\HttpClient\MockHttpClient;
|
|
use Symfony\Component\HttpClient\Response\MockResponse;
|
|
|
|
class MailjetNewsletterWebhookClientTest extends TestCase
|
|
{
|
|
public function testCreatesEventCallbackUrl(): void
|
|
{
|
|
$client = new MockHttpClient(static function (string $method, string $url, array $options): MockResponse {
|
|
self::assertSame('POST', $method);
|
|
self::assertSame('https://mailjet.test/eventcallbackurl', $url);
|
|
self::assertSame([
|
|
'EventType' => 'unsub',
|
|
'Url' => 'https://my.ep-reisen.de/webhooks/mailjet/newsletter',
|
|
'Version' => 2,
|
|
'isBackup' => false,
|
|
], json_decode((string) $options['body'], true, 512, JSON_THROW_ON_ERROR));
|
|
|
|
return new MockResponse(json_encode([
|
|
'Data' => [
|
|
[
|
|
'ID' => 456,
|
|
],
|
|
],
|
|
], JSON_THROW_ON_ERROR));
|
|
});
|
|
|
|
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
|
|
$response = $mailjet->createEventCallbackUrl('unsub', 'https://my.ep-reisen.de/webhooks/mailjet/newsletter');
|
|
|
|
self::assertSame(456, $response['Data'][0]['ID']);
|
|
}
|
|
|
|
public function testDeletesEventCallbackUrl(): void
|
|
{
|
|
$client = new MockHttpClient(static function (string $method, string $url, array $options): MockResponse {
|
|
self::assertSame('DELETE', $method);
|
|
self::assertSame('https://mailjet.test/eventcallbackurl/456', $url);
|
|
|
|
return new MockResponse('', ['http_code' => 204]);
|
|
});
|
|
|
|
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
|
|
$mailjet->deleteEventCallbackUrl(456);
|
|
}
|
|
}
|