Skip to content

Commit 4ed812d

Browse files
authored
Merge pull request #54 from rpkamp/fix-headers
Always pass Headers to new Messages
2 parents 9183452 + 5e279cb commit 4ed812d

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"phpmd/phpmd": "^2.9.1",
3434
"phpunit/phpunit": "^8.0",
3535
"php-http/curl-client": "^2.0",
36-
"swiftmailer/swiftmailer": "^6.2.3",
36+
"swiftmailer/swiftmailer": "6.2.3",
3737
"phpstan/phpstan": "^0.12.64",
3838
"pdepend/pdepend": "^2.5",
3939
"nyholm/psr7": "^1.2",

src/Message/Message.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ class Message
5151
public $attachments;
5252

5353
/**
54-
* @var array<string, array<int, string>>|null
54+
* @var Headers
5555
*/
5656
public $headers;
5757

5858
/**
59-
* @param Attachment[] $attachments
60-
* @param \rpkamp\Mailhog\Message\Headers $headers
59+
* @param Attachment[] $attachments
6160
*/
6261
public function __construct(
6362
string $messageId,

src/Specification/HeaderSpecification.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public function __construct(string $headerName, ?string $headerValue = null)
2525

2626
public function isSatisfiedBy(Message $message): bool
2727
{
28-
return
29-
$this->headerValue
28+
return $this->headerValue
3029
? $message->headers->get($this->headerName) === $this->headerValue
3130
: $message->headers->has($this->headerName);
3231
}

tests/unit/Message/MessageTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use InvalidArgumentException;
77
use rpkamp\Mailhog\Message\Contact;
88
use rpkamp\Mailhog\Message\ContactCollection;
9+
use rpkamp\Mailhog\Message\Headers;
910
use rpkamp\Mailhog\Message\Message;
1011
use PHPUnit\Framework\TestCase;
1112
use rpkamp\Mailhog\Message\Mime\Attachment;
@@ -22,6 +23,7 @@ public function it_should_return_values_it_was_instantiated_with(): void
2223
$attachments = [
2324
new Attachment('lorem-ipsum.text', 'text/plain', 'Lorem ipsum dolor sit amet!')
2425
];
26+
$headers = new Headers(['foo' => 'bar']);
2527

2628
$message = new Message(
2729
'123',
@@ -31,7 +33,8 @@ public function it_should_return_values_it_was_instantiated_with(): void
3133
new ContactCollection([new Contact('bcc@myself.example')]),
3234
'Heya',
3335
'Hello there!',
34-
$attachments
36+
$attachments,
37+
$headers
3538
);
3639

3740
$this->assertEquals('123', $message->messageId);
@@ -42,6 +45,7 @@ public function it_should_return_values_it_was_instantiated_with(): void
4245
$this->assertEquals('Heya', $message->subject);
4346
$this->assertEquals('Hello there!', $message->body);
4447
$this->assertEquals($attachments, $message->attachments);
48+
$this->assertEquals($headers, $message->headers);
4549
}
4650

4751
/**
@@ -58,7 +62,8 @@ public function it_should_throw_exception_when_non_attachment_supplied_as_attach
5862
new ContactCollection([new Contact('bcc@myself.example')]),
5963
'Heya',
6064
'Hello there!',
61-
[new stdClass()]
65+
[new stdClass()],
66+
new Headers([])
6267
);
6368
}
6469
}

tests/unit/Specification/Fixtures/MessageFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use rpkamp\Mailhog\Message\Contact;
77
use rpkamp\Mailhog\Message\ContactCollection;
8+
use rpkamp\Mailhog\Message\Headers;
89
use rpkamp\Mailhog\Message\Message;
910
use rpkamp\Mailhog\Message\Mime\Attachment;
1011

@@ -22,7 +23,8 @@ public static function dummy(): Message
2223
'Hi there',
2324
[
2425
new Attachment('lorem-ipsum.txt', 'text/plain', 'Lorem ipsum dolor sit amet!'),
25-
]
26+
],
27+
new Headers([])
2628
);
2729
}
2830
}

0 commit comments

Comments
 (0)