8000 [Tests] Use `JsonMockResponse` where applicable · symfony/symfony@bf12b72 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf12b72

Browse files
OskarStarknicolas-grekas
authored andcommitted
[Tests] Use JsonMockResponse where applicable
1 parent abe5555 commit bf12b72

File tree

32 files changed

+164
-186
lines changed

32 files changed

+164
-186
lines changed

src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapAuditorTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\AssetMapper\ImportMap\ImportMapPackageAuditVulnerability;
2222
use Symfony\Component\AssetMapper\ImportMap\ImportMapType;
2323
use Symfony\Component\HttpClient\MockHttpClient;
24+
use Symfony\Component\HttpClient\Response\JsonMockResponse;
2425
use Symfony\Component\HttpClient\Response\MockResponse;
2526
use Symfony\Contracts\HttpClient\HttpClientInterface;
2627

@@ -39,7 +40,7 @@ protected function setUp(): void
3940

4041
public function testAudit()
4142
{
42-
$this->httpClient->setResponseFactory(new MockResponse(json_encode([
43+
$this->httpClient->setResponseFactory(new JsonMockResponse([
4344
[
4445
'ghsa_id' => 'GHSA-abcd-1234-efgh',
4546
'cve_id' => 'CVE-2050-00000',
@@ -64,7 +65,7 @@ public function testAudit()
6465
],
6566
],
6667
],
67-
])));
68+
]));
6869
$this->importMapConfigReader->method('getEntries')->willReturn(new ImportMapEntries([
6970
self::createRemoteEntry('@hotwired/stimulus', '3.2.1'),
7071
self::createRemoteEntry('json5/some/file', '1.0.0'),
@@ -93,7 +94,7 @@ public function testAudit()
9394
*/
9495
public function testAuditWithVersionRange(bool $expectMatch, string $version, ?string $versionRange)
9596
{
96-
$this->httpClient->setResponseFactory(new MockResponse(json_encode([
97+
$this->httpClient->setResponseFactory(new JsonMockResponse([
9798
[
9899
'ghsa_id' => 'GHSA-abcd-1234-efgh',
99100
'cve_id' => 'CVE-2050-00000',
@@ -108,7 +109,7 @@ public function testAuditWithVersionRange(bool $expectMatch, string $version, ?s
108109
],
109110
],
110111
],
111-
])));
112+
]));
112113
$this->importMapConfigReader->method('getEntries')->willReturn(new ImportMapEntries([
113114
self::createRemoteEntry('json5', $version),
114115
]));

src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapUpdateCheckerTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\AssetMapper\ImportMap\ImportMapUpdateChecker;
2020
use Symfony\Component\AssetMapper\ImportMap\PackageUpdateInfo;
2121
use Symfony\Component\HttpClient\MockHttpClient;
22+
use Symfony\Component\HttpClient\Response\JsonMockResponse;
2223
use Symfony\Component\HttpClient\Response\MockResponse;
2324

2425
class ImportMapUpdateCheckerTest extends TestCase
@@ -187,18 +188,18 @@ private function responseFactory($method, $url): MockResponse
187188
{
188189
$this->assertSame('GET', $method);
189190
$map = [
190-
'https://registry.npmjs.org/@hotwired/stimulus' => new MockResponse(json_encode([
191+
'https://registry.npmjs.org/@hotwired/stimulus' => new JsonMockResponse([
191192
'dist-tags' => ['latest' => '4.0.1'], // Major update
192-
])),
193-
'https://registry.npmjs.org/json5' => new MockResponse(json_encode([
193+
]),
194+
'https://registry.npmjs.org/json5' => new JsonMockResponse([
194195
'dist-tags' => ['latest' => '1.2.0'], // Minor update
195-
])),
196-
'https://registry.npmjs.org/bootstrap' => new MockResponse(json_encode([
196+
]),
197+
'https://registry.npmjs.org/bootstrap' => new JsonMockResponse([
197198
'dist-tags' => ['latest' => '5.3.2'], // Patch update
198-
])),
199-
'https://registry.npmjs.org/lodash' => new MockResponse(json_encode([
199+
]),
200+
'https://registry.npmjs.org/lodash' => new JsonMockResponse([
200201
'dist-tags' => ['latest' => '4.17.21'], // no update
201-
])),
202+
]),
202203
];
203204

204205
return $map[$url] ?? new MockResponse('Not found', ['http_code' => 404]);

src/Symfony/Component/AssetMapper/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=8.1",
2020
"symfony/deprecation-contracts": "^2.5|^3",
2121
"symfony/filesystem": "^5.4|^6.0|^7.0",
22-
"symfony/http-client": "^5.4|^6.0|^7.0"
22+
"symfony/http-client": "^6.3|^7.0"
2323
},
2424
"require-dev": {
2525
"symfony/asset": "^5.4|^6.0|^7.0",

src/Symfony/Component/Mailer/Bridge/Brevo/Tests/Transport/BrevoApiTransportTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpClient\MockHttpClient;
16-
use Symfony\Component\HttpClient\Response\MockResponse;
16+
use Symfony\Component\HttpClient\Response\JsonMockResponse;
1717
use Symfony\Component\Mailer\Bridge\Brevo\Transport\BrevoApiTransport;
1818
use Symfony\Component\Mailer\Envelope;
1919
use Symfony\Component\Mailer\Exception\HttpTransportException;
@@ -91,11 +91,8 @@ public function testSendThrowsForErrorResponse()
9191
$this->assertSame('https://api.brevo.com:8984/v3/smtp/email', $url);
9292
$this->assertStringContainsString('Accept: */*', $options['headers'][2] ?? $options['request_headers'][1]);
9393

94-
return new MockResponse(json_encode(['message' => 'i\'m a teapot']), [
94+
return new JsonMockResponse(['message' => 'i\'m a teapot'], [
9595
'http_code' => 418,
96-
'response_headers' => [
97-
'content-type' => 'application/json',
98-
],
9996
]);
10097
});
10198

@@ -120,7 +117,7 @@ public function testSend()
120117
$this->assertSame('https://api.brevo.com:8984/v3/smtp/email', $url);
121118
$this->assertStringContainsString('Accept: */*', $options['headers'][2] ?? $options['request_headers'][1]);
122119

123-
return new MockResponse(json_encode(['messageId' => 'foobar']), [
120+
return new JsonMockResponse(['messageId' => 'foobar'], [
124121
'http_code' => 201,
125122
]);
126123
});
@@ -165,7 +162,7 @@ public function testSendForIdnDomains()
165162
$this->assertSame('info@xn--kltetechnik-xyz-0kb.de', $body['sender']['email']);
166163
$this->assertSame('Kältetechnik Xyz', $body['sender']['name']);
167164

168-
return new MockResponse(json_encode(['messageId' => 'foobar']), [
165+
return new JsonMockResponse(['messageId' => 'foobar'], [
169166
'http_code' => 201,
170167
]);
171168
});

src/Symfony/Component/Mailer/Bridge/Brevo/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/mailer": "^5.4.21|^6.2.7"
2121
},
2222
"require-dev": {
23-
"symfony/http-client": "^5.4|^6.0",
23+
"symfony/http-client": "^6.3",
2424
"symfony/webhook": "^6.4"
2525
},
2626
"conflict": {

src/Symfony/Component/Mailer/Bridge/MailPace/Tests/Transport/MailPaceApiTransportTest.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpClient\MockHttpClient;
16+
use Symfony\Component\HttpClient\Response\JsonMockResponse;
1617
use Symfony\Component\HttpClient\Response\MockResponse;
1718
use Symfony\Component\Mailer\Bridge\MailPace\Transport\MailPaceApiTransport;
1819
use Symfony\Component\Mailer\Envelope;
@@ -79,7 +80,7 @@ public function testSend()
7980
$this->assertSame('Hello!', $body['subject']);
8081
$this->assertSame('Hello There!', $body['textbody']);
8182

82-
return new MockResponse(json_encode(['id' => 'foobar', 'status' => 'pending']), [
83+
return new JsonMockResponse(['id' => 'foobar', 'status' => 'pending'], [
8384
'http_code' => 200,
8485
]);
8586
});
@@ -99,11 +100,8 @@ 38BA public function testSend()
99100

100101
public function testSendThrowsForErrorResponse()
101102
{
102-
$client = new MockHttpClient(static fn (string $method, string $url, array $options): ResponseInterface => new MockResponse(json_encode(['error' => 'i\'m a teapot']), [
103+
$client = new MockHttpClient(static fn (string $method, string $url, array $options): ResponseInterface => new JsonMockResponse(['error' => 'i\'m a teapot'], [
103104
'http_code' => 418,
104-
'response_headers' => [
105-
'content-type' => 'application/json',
106-
],
107105
]));
108106
$transport = new MailPaceApiTransport('KEY', $client);
109107
$transport->setPort(8984);
@@ -122,19 +120,16 @@ public function testSendThrowsForErrorResponse()
122120
public function testSendThrowsForErrorsResponse()
123121
{
124122
$client = new MockHttpClient(static function (string $method, string $url, array $options): ResponseInterface {
125-
return new MockResponse(json_encode([
123+
return new JsonMockResponse([
126124
'errors' => [
127125
'to' => [
128126
'contains a blocked address',
129127
'number of email addresses exceeds maximum volume',
130128
],
131129
'attachments.name' => ['Extension file type blocked, see Docs for full list of allowed file types'],
132130
],
133-
]), [
131+
], [
134132
'http_code' => 400,
135-
'response_headers' => [
136-
'content-type' => 'application/json',
137-
],
138133
]);
139134
});
140135
$transport = new MailPaceApiTransport('KEY', $client);

src/Symfony/Component/Mailer/Bridge/MailPace/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"symfony/mailer": "^5.4.21|^6.2.7|^7.0"
2626
},
2727
"require-dev": {
28-
"symfony/http-client": "^5.4|^6.0|^7.0"
28+
"symfony/http-client": "^6.3|^7.0"
2929
},
3030
"autoload": {
3131
"psr-4": { "Symfony\\Component\\Mailer\\Bridge\\MailPace\\": "" },

src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillApiTransportTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpClient\MockHttpClient;
16-
use Symfony\Component\HttpClient\Response\MockResponse;
16+
use Symfony\Component\HttpClient\Response\JsonMockResponse;
1717
use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillApiTransport;
1818
use Symfony\Component\Mailer\Envelope;
1919
use Symfony\Component\Mailer\Exception\HttpTransportException;
@@ -83,7 +83,7 @@ public function testSend()
8383
$this->assertSame('Hello!', $message['subject']);
8484
$this->assertSame('Hello There!', $message['text']);
8585

86-
return new MockResponse(json_encode([['_id' => 'foobar']]), [
86+
return new JsonMockResponse([['_id' => 'foobar']], [
8787
'http_code' => 200,
8888
]);
8989
});
@@ -103,7 +103,7 @@ public function testSend()
103103

104104
public function testSendThrowsForErrorResponse()
105105
{
106-
$client = new MockHttpClient(fn (string $method, string $url, array $options): ResponseInterface => new MockResponse(json_encode(['status' => 'error', 'message' => 'i\'m a teapot', 'code' => 418]), [
106+
$client = new MockHttpClient(fn (string $method, string $url, array $options): ResponseInterface => new JsonMockResponse(['status' => 'error', 'message' => 'i\'m a teapot', 'code' => 418], [
107107
'http_code' => 418,
108108
]));
109109

src/Symfony/Component/Mailer/Bridge/Mailchimp/Tests/Transport/MandrillHttpTransportTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpClient\MockHttpClient;
16-
use Symfony\Component\HttpClient\Response\MockResponse;
16+
use Symfony\Component\HttpClient\Response\JsonMockResponse;
1717
use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillHttpTransport;
1818
use Symfony\Component\Mailer\Exception\HttpTransportException;
1919
use Symfony\Component\Mailer\Header\MetadataHeader;
@@ -68,7 +68,7 @@ public function testSend()
6868
$this->assertStringContainsString('From: Fabien <fabpot@symfony.com>', $message);
6969
$this->assertStringContainsString('Hello There!', $message);
7070

71-
return new MockResponse(json_encode([['_id' => 'foobar']]), [
71+
return new JsonMockResponse([['_id' => 'foobar']], [
7272
'http_code' => 200,
7373
]);
7474
});
@@ -88,7 +88,7 @@ public function testSend()
8888

8989
public function testSendThrowsForErrorResponse()
9090
{
91-
$client = new MockHttpClient(fn (string $method, string $url, array $options): ResponseInterface => new MockResponse(json_encode(['status' => 'error', 'message' => 'i\'m a teapot', 'code' => 418]), [
91+
$client = new MockHttpClient(fn (string $method, string $url, array $options): ResponseInterface => new JsonMockResponse(['status' => 'error', 'message' => 'i\'m a teapot', 'code' => 418], [
9292
'http_code' => 418,
9393
]));
9494

src/Symfony/Component/Mailer/Bridge/Mailchimp/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/mailer": "^5.4.21|^6.2.7|^7.0"
2121
},
2222
"require-dev": {
23-
"symfony/http-client": "^5.4|^6.0|^7.0"
23+
"symfony/http-client": "^6.3|^7.0"
2424
},
2525
"autoload": {
2626
"psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Mailchimp\\": "" },

0 commit comments

Comments
 (0)
0