From a9d3c9b4eabfc7a240af7085fcb58a63cddc1cb2 Mon Sep 17 00:00:00 2001 From: Tim Geisendoerfer Date: Thu, 26 Sep 2024 16:27:03 +0200 Subject: [PATCH 1/6] fix failing tests --- src/Exceptions/InvalidResponse.php | 4 +--- src/Services/MicrosoftGraphApiService.php | 3 +-- tests/MicrosoftGraphTransportTest.php | 14 +++----------- tests/Stubs/TestMail.php | 4 +--- tests/Stubs/TestMailWithInlineImage.php | 15 +-------------- 5 files changed, 7 insertions(+), 33 deletions(-) diff --git a/src/Exceptions/InvalidResponse.php b/src/Exceptions/InvalidResponse.php index d63b963..d72a436 100644 --- a/src/Exceptions/InvalidResponse.php +++ b/src/Exceptions/InvalidResponse.php @@ -4,6 +4,4 @@ use Exception; -class InvalidResponse extends Exception -{ -} +class InvalidResponse extends Exception {} diff --git a/src/Services/MicrosoftGraphApiService.php b/src/Services/MicrosoftGraphApiService.php index 17e0c69..462144a 100644 --- a/src/Services/MicrosoftGraphApiService.php +++ b/src/Services/MicrosoftGraphApiService.php @@ -16,8 +16,7 @@ public function __construct( protected readonly string $clientId, protected readonly string $clientSecret, protected readonly int $accessTokenTtl - ) { - } + ) {} /** * @throws RequestException diff --git a/tests/MicrosoftGraphTransportTest.php b/tests/MicrosoftGraphTransportTest.php index 259d7bd..219f69b 100644 --- a/tests/MicrosoftGraphTransportTest.php +++ b/tests/MicrosoftGraphTransportTest.php @@ -33,7 +33,7 @@ Mail::to('caleb@livewire.com') ->bcc('tim@innoge.de') ->cc('nuno@laravel.com') - ->send(new TestMail()); + ->send(new TestMail); Http::assertSent(function (Request $value) { expect($value) @@ -371,11 +371,11 @@ Mail::to('caleb@livewire.com') ->bcc('tim@innoge.de') ->cc('nuno@laravel.com') - ->send(new TestMailWithInlineImage()); + ->send(new TestMailWithInlineImage); Http::assertSent(function (Request $value) { // ContentId gets random generated, so get this value first and check for equality later - $inlineImageContentId = json_decode($value->body())->message->attachments[1]->contentId; + $inlineImageContentId = json_decode($value->body())->message->attachments[0]->contentId; expect($value) ->url()->toBe('https://graph.microsoft.com/v1.0/users/taylor@laravel.com/sendMail') @@ -415,14 +415,6 @@ ], ], 'attachments' => [ - [ - '@odata.type' => '#microsoft.graph.fileAttachment', - 'name' => 'test-file-1.txt', - 'contentType' => 'text', - 'contentBytes' => 'Zm9vCg==', - 'contentId' => 'test-file-1.txt', - 'isInline' => false, - ], [ '@odata.type' => '#microsoft.graph.fileAttachment', 'name' => $inlineImageContentId, diff --git a/tests/Stubs/TestMail.php b/tests/Stubs/TestMail.php index 7a05440..4660801 100644 --- a/tests/Stubs/TestMail.php +++ b/tests/Stubs/TestMail.php @@ -18,9 +18,7 @@ class TestMail extends Mailable * * @return void */ - public function __construct(private readonly bool $isHtml = true) - { - } + public function __construct(private readonly bool $isHtml = true) {} /** * Get the message envelope. diff --git a/tests/Stubs/TestMailWithInlineImage.php b/tests/Stubs/TestMailWithInlineImage.php index f22f305..0bd0373 100644 --- a/tests/Stubs/TestMailWithInlineImage.php +++ b/tests/Stubs/TestMailWithInlineImage.php @@ -3,7 +3,6 @@ namespace InnoGE\LaravelMsGraphMail\Tests\Stubs; use Illuminate\Bus\Queueable; -use Illuminate\Mail\Attachment; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; @@ -18,9 +17,7 @@ class TestMailWithInlineImage extends Mailable * * @return void */ - public function __construct(private readonly bool $isHtml = true) - { - } + public function __construct(private readonly bool $isHtml = true) {} /** * Get the message envelope. @@ -47,14 +44,4 @@ public function content() return new Content(html: 'html-mail-with-inline-image'); } - - /** - * Get the attachments for the message. - */ - public function attachments(): array - { - return [ - Attachment::fromPath('tests/Resources/files/test-file-1.txt'), - ]; - } } From 2ff85be67c67d8acd9c54a7dacfcd93df066c2d9 Mon Sep 17 00:00:00 2001 From: Tim Geisendoerfer Date: Thu, 26 Sep 2024 16:27:12 +0200 Subject: [PATCH 2/6] add php 8.4 support --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 34ec4df..d2969c6 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,7 +13,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.3, 8.2, 8.1] + php: [8,4, 8.3, 8.2, 8.1] laravel: ["^11.0", "^10.0", "^9.38"] stability: [prefer-lowest, prefer-stable] include: From 9e23a0424d23ba554ffb38f7b43404e86b315ac5 Mon Sep 17 00:00:00 2001 From: Tim Geisendoerfer Date: Thu, 26 Sep 2024 16:27:57 +0200 Subject: [PATCH 3/6] add php 8.4 support --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d2969c6..5d0e2e8 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,7 +13,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8,4, 8.3, 8.2, 8.1] + php: [8.4, 8.3, 8.2, 8.1] laravel: ["^11.0", "^10.0", "^9.38"] stability: [prefer-lowest, prefer-stable] include: From f7b5274f5e415cae24bd0aad206c02b547b4c488 Mon Sep 17 00:00:00 2001 From: Tim Geisendoerfer Date: Thu, 26 Sep 2024 16:35:07 +0200 Subject: [PATCH 4/6] fix phpstan --- phpstan-baseline.neon | 20 ++++++++++++++++++++ phpstan.neon.dist | 2 -- src/MicrosoftGraphTransport.php | 4 ++++ src/Services/MicrosoftGraphApiService.php | 9 +-------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d2ecb11..5fc51d0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,15 @@ parameters: ignoreErrors: + - + message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:transformEmailAddress\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/MicrosoftGraphTransport.php + + - + message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:transformEmailAddresses\\(\\) should return array\\\\>\\> but returns array\\.$#" + count: 1 + path: src/MicrosoftGraphTransport.php + - message: "#^Parameter \\#1 \\$message of static method Symfony\\\\Component\\\\Mime\\\\MessageConverter\\:\\:toEmail\\(\\) expects Symfony\\\\Component\\\\Mime\\\\Message, Symfony\\\\Component\\\\Mime\\\\RawMessage given\\.$#" count: 1 @@ -9,3 +19,13 @@ parameters: message: "#^Parameter \\#2 \\$html of method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:prepareAttachments\\(\\) expects string\\|null, resource\\|string\\|null given\\.$#" count: 1 path: src/MicrosoftGraphTransport.php + + - + message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\Services\\\\MicrosoftGraphApiService\\:\\:getAccessToken\\(\\) should return string but returns mixed\\.$#" + count: 1 + path: src/Services/MicrosoftGraphApiService.php + + - + message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\Services\\\\MicrosoftGraphApiService\\:\\:sendMail\\(\\) has parameter \\$payload with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Services/MicrosoftGraphApiService.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9aa5399..40e24a1 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,5 +8,3 @@ parameters: tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false diff --git a/src/MicrosoftGraphTransport.php b/src/MicrosoftGraphTransport.php index 9264699..517100c 100644 --- a/src/MicrosoftGraphTransport.php +++ b/src/MicrosoftGraphTransport.php @@ -61,6 +61,9 @@ protected function doSend(SentMessage $message): void $this->microsoftGraphApiService->sendMail($envelope->getSender()->getAddress(), $payload); } + /** + * @return array, array>|string|null> + */ protected function prepareAttachments(Email $email, ?string $html): array { $attachments = []; @@ -83,6 +86,7 @@ protected function prepareAttachments(Email $email, ?string $html): array /** * @param Collection $recipients + * @return array>> */ protected function transformEmailAddresses(Collection $recipients): array { diff --git a/src/Services/MicrosoftGraphApiService.php b/src/Services/MicrosoftGraphApiService.php index 462144a..c11cf49 100644 --- a/src/Services/MicrosoftGraphApiService.php +++ b/src/Services/MicrosoftGraphApiService.php @@ -3,7 +3,6 @@ namespace InnoGE\LaravelMsGraphMail\Services; use Illuminate\Http\Client\PendingRequest; -use Illuminate\Http\Client\RequestException; use Illuminate\Http\Client\Response; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; @@ -18,9 +17,6 @@ public function __construct( protected readonly int $accessTokenTtl ) {} - /** - * @throws RequestException - */ public function sendMail(string $from, array $payload): Response { return $this->getBaseRequest() @@ -49,10 +45,7 @@ protected function getAccessToken(): string $response->throw(); $accessToken = $response->json('access_token'); - if (! is_string($accessToken)) { - $notString = var_export($accessToken, true); - throw new InvalidResponse("Expected response to contain key access_token of type string, got: {$notString}."); - } + throw_unless(is_string($accessToken), new InvalidResponse('Expected response to contain key access_token of type string, got: {'.var_export($accessToken, true).' }.')); return $accessToken; }); From 7190d0e696f63dce9a954ef6a21346d0a17345cd Mon Sep 17 00:00:00 2001 From: Tim Geisendoerfer Date: Thu, 26 Sep 2024 16:37:08 +0200 Subject: [PATCH 5/6] wip --- src/Services/MicrosoftGraphApiService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/MicrosoftGraphApiService.php b/src/Services/MicrosoftGraphApiService.php index c11cf49..08e7bb8 100644 --- a/src/Services/MicrosoftGraphApiService.php +++ b/src/Services/MicrosoftGraphApiService.php @@ -45,7 +45,7 @@ protected function getAccessToken(): string $response->throw(); $accessToken = $response->json('access_token'); - throw_unless(is_string($accessToken), new InvalidResponse('Expected response to contain key access_token of type string, got: {'.var_export($accessToken, true).' }.')); + throw_unless(is_string($accessToken), new InvalidResponse('Expected response to contain key access_token of type string, got: '.var_export($accessToken, true).'.')); return $accessToken; }); From 2459b11d803a9e17913df757a7b2bd06f9efb27d Mon Sep 17 00:00:00 2001 From: Tim Geisendoerfer Date: Thu, 26 Sep 2024 16:40:12 +0200 Subject: [PATCH 6/6] remove php 8.4 tests --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5d0e2e8..34ec4df 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,7 +13,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.4, 8.3, 8.2, 8.1] + php: [8.3, 8.2, 8.1] laravel: ["^11.0", "^10.0", "^9.38"] stability: [prefer-lowest, prefer-stable] include: