Skip to content

Commit fb1e86e

Browse files
authored
Fix tests with newer Laravel 11 versions (InnoGE#33)
fix Failing tests for newer Laravel 11 versions
1 parent 8718b7f commit fb1e86e

8 files changed

+32
-43
lines changed

Diff for: phpstan-baseline.neon

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:transformEmailAddress\\(\\) return type has no value type specified in iterable type array\\.$#"
5+
count: 1
6+
path: src/MicrosoftGraphTransport.php
7+
8+
-
9+
message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:transformEmailAddresses\\(\\) should return array\\<array\\<string, array\\<string, string\\>\\>\\> but returns array\\.$#"
10+
count: 1
11+
path: src/MicrosoftGraphTransport.php
12+
313
-
414
message: "#^Parameter \\#1 \\$message of static method Symfony\\\\Component\\\\Mime\\\\MessageConverter\\:\\:toEmail\\(\\) expects Symfony\\\\Component\\\\Mime\\\\Message, Symfony\\\\Component\\\\Mime\\\\RawMessage given\\.$#"
515
count: 1
@@ -9,3 +19,13 @@ parameters:
919
message: "#^Parameter \\#2 \\$html of method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:prepareAttachments\\(\\) expects string\\|null, resource\\|string\\|null given\\.$#"
1020
count: 1
1121
path: src/MicrosoftGraphTransport.php
22+
23+
-
24+
message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\Services\\\\MicrosoftGraphApiService\\:\\:getAccessToken\\(\\) should return string but returns mixed\\.$#"
25+
count: 1
26+
path: src/Services/MicrosoftGraphApiService.php
27+
28+
-
29+
message: "#^Method InnoGE\\\\LaravelMsGraphMail\\\\Services\\\\MicrosoftGraphApiService\\:\\:sendMail\\(\\) has parameter \\$payload with no value type specified in iterable type array\\.$#"
30+
count: 1
31+
path: src/Services/MicrosoftGraphApiService.php

Diff for: phpstan.neon.dist

-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@ parameters:
88
tmpDir: build/phpstan
99
checkOctaneCompatibility: true
1010
checkModelProperties: true
11-
checkMissingIterableValueType: false
12-
checkGenericClassInNonGenericObjectType: false

Diff for: src/Exceptions/InvalidResponse.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
use Exception;
66

7-
class InvalidResponse extends Exception
8-
{
9-
}
7+
class InvalidResponse extends Exception {}

Diff for: src/MicrosoftGraphTransport.php

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ protected function doSend(SentMessage $message): void
6161
$this->microsoftGraphApiService->sendMail($envelope->getSender()->getAddress(), $payload);
6262
}
6363

64+
/**
65+
* @return array<int, array<int<0, max>, array<string, bool|string|null>>|string|null>
66+
*/
6467
protected function prepareAttachments(Email $email, ?string $html): array
6568
{
6669
$attachments = [];
@@ -83,6 +86,7 @@ protected function prepareAttachments(Email $email, ?string $html): array
8386

8487
/**
8588
* @param Collection<array-key, Address> $recipients
89+
* @return array<array-key, array<string, array<string, string>>>
8690
*/
8791
protected function transformEmailAddresses(Collection $recipients): array
8892
{

Diff for: src/Services/MicrosoftGraphApiService.php

+2-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace InnoGE\LaravelMsGraphMail\Services;
44

55
use Illuminate\Http\Client\PendingRequest;
6-
use Illuminate\Http\Client\RequestException;
76
use Illuminate\Http\Client\Response;
87
use Illuminate\Support\Facades\Cache;
98
use Illuminate\Support\Facades\Http;
@@ -16,12 +15,8 @@ public function __construct(
1615
protected readonly string $clientId,
1716
protected readonly string $clientSecret,
1817
protected readonly int $accessTokenTtl
19-
) {
20-
}
18+
) {}
2119

22-
/**
23-
* @throws RequestException
24-
*/
2520
public function sendMail(string $from, array $payload): Response
2621
{
2722
return $this->getBaseRequest()
@@ -50,10 +45,7 @@ protected function getAccessToken(): string
5045
$response->throw();
5146

5247
$accessToken = $response->json('access_token');
53-
if (! is_string($accessToken)) {
54-
$notString = var_export($accessToken, true);
55-
throw new InvalidResponse("Expected response to contain key access_token of type string, got: {$notString}.");
56-
}
48+
throw_unless(is_string($accessToken), new InvalidResponse('Expected response to contain key access_token of type string, got: '.var_export($accessToken, true).'.'));
5749

5850
return $accessToken;
5951
});

Diff for: tests/MicrosoftGraphTransportTest.php

+3-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
Mail::to('[email protected]')
3434
3535
36-
->send(new TestMail());
36+
->send(new TestMail);
3737

3838
Http::assertSent(function (Request $value) {
3939
expect($value)
@@ -371,11 +371,11 @@
371371
Mail::to('[email protected]')
372372
373373
374-
->send(new TestMailWithInlineImage());
374+
->send(new TestMailWithInlineImage);
375375

376376
Http::assertSent(function (Request $value) {
377377
// ContentId gets random generated, so get this value first and check for equality later
378-
$inlineImageContentId = json_decode($value->body())->message->attachments[1]->contentId;
378+
$inlineImageContentId = json_decode($value->body())->message->attachments[0]->contentId;
379379

380380
expect($value)
381381
->url()->toBe('https://graph.microsoft.com/v1.0/users/[email protected]/sendMail')
@@ -415,14 +415,6 @@
415415
],
416416
],
417417
'attachments' => [
418-
[
419-
'@odata.type' => '#microsoft.graph.fileAttachment',
420-
'name' => 'test-file-1.txt',
421-
'contentType' => 'text',
422-
'contentBytes' => 'Zm9vCg==',
423-
'contentId' => 'test-file-1.txt',
424-
'isInline' => false,
425-
],
426418
[
427419
'@odata.type' => '#microsoft.graph.fileAttachment',
428420
'name' => $inlineImageContentId,

Diff for: tests/Stubs/TestMail.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class TestMail extends Mailable
1818
*
1919
* @return void
2020
*/
21-
public function __construct(private readonly bool $isHtml = true)
22-
{
23-
}
21+
public function __construct(private readonly bool $isHtml = true) {}
2422

2523
/**
2624
* Get the message envelope.

Diff for: tests/Stubs/TestMailWithInlineImage.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace InnoGE\LaravelMsGraphMail\Tests\Stubs;
44

55
use Illuminate\Bus\Queueable;
6-
use Illuminate\Mail\Attachment;
76
use Illuminate\Mail\Mailable;
87
use Illuminate\Mail\Mailables\Content;
98
use Illuminate\Mail\Mailables\Envelope;
@@ -18,9 +17,7 @@ class TestMailWithInlineImage extends Mailable
1817
*
1918
* @return void
2019
*/
21-
public function __construct(private readonly bool $isHtml = true)
22-
{
23-
}
20+
public function __construct(private readonly bool $isHtml = true) {}
2421

2522
/**
2623
* Get the message envelope.
@@ -47,14 +44,4 @@ public function content()
4744

4845
return new Content(html: 'html-mail-with-inline-image');
4946
}
50-
51-
/**
52-
* Get the attachments for the message.
53-
*/
54-
public function attachments(): array
55-
{
56-
return [
57-
Attachment::fromPath('tests/Resources/files/test-file-1.txt'),
58-
];
59-
}
6047
}

0 commit comments

Comments
 (0)