Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Fix static analysis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ts-navghane committed Jul 17, 2023
1 parent b7489b0 commit 8f0db96
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 73 deletions.
13 changes: 5 additions & 8 deletions Tests/Unit/Mailer/Factory/SparkpostTransportFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,21 @@
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class SparkpostTransportFactoryTest extends TestCase
{
private SparkpostTransportFactory $sparkpostTransportFactory;

protected function setUp(): void
{
$translatorMock = $this->createMock(TranslatorInterface::class);
$eventDispatcherMock = $this->createMock(EventDispatcherInterface::class);
$transportCallbackMock = $this->createMock(TransportCallback::class);
$httpClientMock = $this->createMock(HttpClientInterface::class);
$loggerMock = $this->createMock(LoggerInterface::class);
$eventDispatcherMock = $this->createMock(EventDispatcherInterface::class);
$transportCallbackMock = $this->createMock(TransportCallback::class);
$httpClientMock = $this->createMock(HttpClientInterface::class);
$loggerMock = $this->createMock(LoggerInterface::class);

$this->sparkpostTransportFactory = new SparkpostTransportFactory(
$translatorMock,
$eventDispatcherMock,
$transportCallbackMock,
$eventDispatcherMock,
$httpClientMock,
$loggerMock
);
Expand Down
112 changes: 47 additions & 65 deletions Tests/Unit/Mailer/Transport/SparkpostTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
use Symfony\Component\Mime\Header\Headers;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class SparkpostTransportTest extends TestCase
{
private TranslatorInterface|MockObject $translatorMock;

private TransportCallback|MockObject $transportCallbackMock;

private HttpClientInterface|MockObject $httpClientMock;
Expand All @@ -37,80 +34,65 @@ class SparkpostTransportTest extends TestCase

protected function setUp(): void
{
$this->translatorMock = $this->createMock(TranslatorInterface::class);
$this->transportCallbackMock = $this->createMock(TransportCallback::class);
$this->httpClientMock = $this->createMock(HttpClientInterface::class);
$this->eventDispatcherMock = $this->createMock(EventDispatcherInterface::class);
$this->loggerMock = $this->createMock(LoggerInterface::class);
$this->transport = new SparkpostTransport(
$this->transportCallbackMock = $this->createMock(TransportCallback::class);
$this->httpClientMock = $this->createMock(HttpClientInterface::class);
$this->eventDispatcherMock = $this->createMock(EventDispatcherInterface::class);
$this->loggerMock = $this->createMock(LoggerInterface::class);
$this->transport = new SparkpostTransport(
'api-key',
'some-region',
$this->translatorMock,
$this->transportCallbackMock,
$this->httpClientMock,
$this->eventDispatcherMock,
$this->loggerMock
);
}

public function testInstanceOfSparkpostTransport(): void
public function testSendEmail(): void
{
Assert::assertInstanceOf(SparkpostTransport::class, $this->transport);
}
$sentMessageMock = $this->createMock(SentMessage::class);
$mauticMessageMock = $this->createMock(MauticMessage::class);
$responseMock = $this->createMock(ResponseInterface::class);

$sentMessageMock->method('getOriginalMessage')
->willReturn($mauticMessageMock);

$fromAddress = new Address('[email protected]', 'From Name');
$replyToAddress = new Address('[email protected]', 'Reply To Name');

$mauticMessageMock->method('getFrom')
->willReturn([$fromAddress]);

$mauticMessageMock->method('getReplyTo')
->willReturn([$replyToAddress]);

// public function testSendEmail(): void
// {
// $sentMessageMock = $this->createMock(SentMessage::class);
// $mauticMessageMock = $this->createMock(MauticMessage::class);
//
// $sentMessageMock->method('getOriginalMessage')
// ->willReturn($mauticMessageMock);
//
// $fromAddress = new Address('[email protected]', 'From Name');
// $replyToAddress = new Address('[email protected]', 'Reply To Name');
//
// $mauticMessageMock->method('getFrom')
// ->willReturn([$fromAddress]);
//
// $mauticMessageMock->method('getReplyTo')
// ->willReturn([$replyToAddress]);
//
// $mauticMessageMock->method('getHeaders')
// ->willReturn(new Headers());
//
// $payload = [
// 'content' => [
// 'from' => 'From Name <[email protected]>',
// 'subject' => null,
// 'headers' => new \stdClass(),
// 'html' => null,
// 'text' => null,
// 'reply_to' => '[email protected]',
// 'attachments' => [],
// ],
// 'recipients' => [],
// 'inline_css' => null,
// 'tags' => [],
// 'campaign_id' => '',
// 'options' => [
// 'open_tracking' => false,
// 'click_tracking' => false,
// ],
// ];
//
// $response = $this->invokeInaccessibleMethod(
// $this->transport,
// 'doSendApi',
// [
// $sentMessageMock,
// $this->createMock(Email::class),
// $this->createMock(Envelope::class),
// ]
// );
//
// Assert::assertInstanceOf(ResponseInterface::class, $response);
// }
$mauticMessageMock->method('getHeaders')
->willReturn(new Headers());

$responseMock->method('getStatusCode')
->willReturn(200);

$this->httpClientMock->method('request')
->willReturn($responseMock);

$response = $this->invokeInaccessibleMethod(
$this->transport,
'doSendApi',
[
$sentMessageMock,
$this->createMock(Email::class),
$this->createMock(Envelope::class),
]
);

Assert::assertInstanceOf(ResponseInterface::class, $response);
}

/**
* @param array<mixed> $args
*
* @throws \ReflectionException
*/
private function invokeInaccessibleMethod(object $object, string $methodName, array $args = []): mixed
{
$reflection = new \ReflectionClass(get_class($object));
Expand Down

0 comments on commit 8f0db96

Please sign in to comment.