Skip to content

Commit

Permalink
[Tests] Use JsonMockResponse where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark authored and nicolas-grekas committed Oct 17, 2023
1 parent 0a149fa commit 3735cbd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
10 changes: 4 additions & 6 deletions Tests/Transport/MailgunApiTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\JsonMockResponse;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunApiTransport;
use Symfony\Component\Mailer\Envelope;
Expand Down Expand Up @@ -135,7 +136,7 @@ public function testSend()
$this->assertStringContainsString('"Fabien" <fabpot@symfony.com>', $content);
$this->assertStringContainsString('Hello There!', $content);

return new MockResponse(json_encode(['id' => 'foobar']), [
return new JsonMockResponse(['id' => 'foobar'], [
'http_code' => 200,
]);
});
Expand Down Expand Up @@ -164,7 +165,7 @@ public function testSendWithMultipleTagHeaders()
$this->assertStringContainsString("Content-Disposition: form-data; name=\"o:tag\"\r\n\r\npassword-reset\r\n", $content);
$this->assertStringContainsString("Content-Disposition: form-data; name=\"o:tag\"\r\n\r\nproduct-name\r\n", $content);

return new MockResponse(json_encode(['id' => 'foobar2']), [
return new JsonMockResponse(['id' => 'foobar2'], [
'http_code' => 200,
]);
});
Expand Down Expand Up @@ -192,11 +193,8 @@ public function testSendThrowsForErrorResponse()
$this->assertSame('https://api.mailgun.net:8984/v3/symfony/messages', $url);
$this->assertStringContainsStringIgnoringCase('Authorization: Basic YXBpOkFDQ0VTU19LRVk=', $options['headers'][2] ?? $options['request_headers'][1]);

return new MockResponse(json_encode(['message' => 'i\'m a teapot']), [
return new JsonMockResponse(['message' => 'i\'m a teapot'], [
'http_code' => 418,
'response_headers' => [
'content-type' => 'application/json',
],
]);
});
$transport = new MailgunApiTransport('ACCESS_KEY', 'symfony', 'us', $client);
Expand Down
9 changes: 3 additions & 6 deletions Tests/Transport/MailgunHttpTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Component\HttpClient\Response\JsonMockResponse;
use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunHttpTransport;
use Symfony\Component\Mailer\Exception\HttpTransportException;
use Symfony\Component\Mailer\Header\MetadataHeader;
Expand Down Expand Up @@ -71,7 +71,7 @@ public function testSend()
$this->assertStringContainsString('From: Fabien <fabpot@symfony.com>', $content);
$this->assertStringContainsString('Hello There!', $content);

return new MockResponse(json_encode(['id' => 'foobar']), [
return new JsonMockResponse(['id' => 'foobar'], [
'http_code' => 200,
]);
});
Expand All @@ -96,11 +96,8 @@ public function testSendThrowsForErrorResponse()
$this->assertSame('https://api.mailgun.net:8984/v3/symfony/messages.mime', $url);
$this->assertStringContainsString('Basic YXBpOkFDQ0VTU19LRVk=', $options['headers'][2] ?? $options['request_headers'][1]);

return new MockResponse(json_encode(['message' => 'i\'m a teapot']), [
return new JsonMockResponse(['message' => 'i\'m a teapot'], [
'http_code' => 418,
'response_headers' => [
'content-type' => 'application/json',
],
]);
});
$transport = new MailgunHttpTransport('ACCESS_KEY', 'symfony', 'us', $client);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"symfony/mailer": "^5.4.21|^6.2.7|^7.0"
},
"require-dev": {
"symfony/http-client": "^5.4|^6.0|^7.0",
"symfony/http-client": "^6.3|^7.0",
"symfony/webhook": "^6.3|^7.0"
},
"conflict": {
Expand Down

0 comments on commit 3735cbd

Please sign in to comment.