Skip to content

Commit 801c521

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: (99 commits) [HttpClient][Messenger] add `PingWebhookMessage` and `PingWebhookMessageHandler` Use Stringable interface as much as possible [Messenger][Process] add `RunProcessMessage` and `RunProcessMessageHandler` Add generics to the progress bar iteration methods [SecurityBundle] Allow an array of `pattern` in firewall configuration [FrameworkBundle] Simplify marking store configuration [PsrHttpMessageBridge] Patch return types and fix CS [PsrHttpMessageBridge] Import the bridge into the monorepo Prepare release 2.3.1 Fix CS Don't rely on Request::getPayload() to populate the parsed body Prepare release 2.3.0 Implement ValueResolverInterface Leverage `Request::getPayload()` to populate the parsed body of PSR-7 requests Add native types where possible cs fix Prepare the 2.2.0 release Bump psr/http-message version Drop support for Symfony 4 Adjustments for PHP CS Fixer 3 ...
2 parents 2be89fa + e87b4f8 commit 801c521

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212

1313
* Add `HarFileResponseFactory` testing utility, allow to replay responses from `.har` files
1414
* Add `max_retries` option to `RetryableHttpClient` to adjust the retry logic on a per request level
15+
* Add `PingWehookMessage` and `PingWebhookMessageHandler`
1516

1617
6.3
1718
---

Messenger/PingWebhookMessage.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpClient\Messenger;
13+
14+
/**
15+
* @author Kevin Bond <[email protected]>
16+
*/
17+
final class PingWebhookMessage implements \Stringable
18+
{
19+
public function __construct(
20+
public readonly string $method,
21+
public readonly string $url,
22+
public readonly array $options = [],
23+
public readonly bool $throw = true,
24+
) {
25+
}
26+
27+
public function __toString(): string
28+
{
29+
return "[{$this->method}] {$this->url}";
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpClient\Messenger;
13+
14+
use Symfony\Contracts\HttpClient\HttpClientInterface;
15+
use Symfony\Contracts\HttpClient\ResponseInterface;
16+
17+
/**
18+
* @author Kevin Bond <[email protected]>
19+
*/
20+
class PingWebhookMessageHandler
21+
{
22+
public function __construct(
23+
private readonly HttpClientInterface $httpClient,
24+
) {
25+
}
26+
27+
public function __invoke(PingWebhookMessage $message): ResponseInterface
28+
{
29+
$response = $this->httpClient->request($message->method, $message->url, $message->options);
30+
$response->getHeaders($message->throw);
31+
32+
return $response;
33+
}
34+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpClient\Tests\Messenger;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpClient\Exception\ClientException;
16+
use Symfony\Component\HttpClient\Messenger\PingWebhookMessage;
17+
use Symfony\Component\HttpClient\Messenger\PingWebhookMessageHandler;
18+
use Symfony\Component\HttpClient\MockHttpClient;
19+
use Symfony\Component\HttpClient\Response\MockResponse;
20+
21+
/**
22+
* @author Kevin Bond <[email protected]>
23+
*/
24+
final class PingWebhookMessageHandlerTest extends TestCase
25+
{
26+
public function testSuccessfulPing()
27+
{
28+
$client = new MockHttpClient([
29+
function ($method, $url) {
30+
$this->assertSame('POST', $method);
31+
$this->assertSame('https://endpoint.com/key', $url);
32+
33+
return new MockResponse('a response');
34+
},
35+
]);
36+
$handler = new PingWebhookMessageHandler($client);
37+
$response = $handler(new PingWebhookMessage('POST', 'https://endpoint.com/key'));
38+
39+
$this->assertSame(200, $response->getStatusCode());
40+
$this->assertSame('a response', $response->getContent());
41+
$this->assertSame('https://endpoint.com/key', $response->getInfo('url'));
42+
}
43+
44+
public function testPingErrorThrowsException()
45+
{
46+
$client = new MockHttpClient([
47+
function ($method, $url) {
48+
$this->assertSame('POST', $method);
49+
$this->assertSame('https://endpoint.com/key', $url);
50+
51+
return new MockResponse('a response', ['http_code' => 404]);
52+
},
53+
]);
54+
55+
$handler = new PingWebhookMessageHandler($client);
56+
57+
$this->expectException(ClientException::class);
58+
59+
$handler(new PingWebhookMessage('POST', 'https://endpoint.com/key'));
60+
}
61+
62+
public function testPingErrorDoesNotThrowException()
63+
{
64+
$client = new MockHttpClient([
65+
function ($method, $url) {
66+
$this->assertSame('POST', $method);
67+
$this->assertSame('https://endpoint.com/key', $url);
68+
69+
return new MockResponse('a response', ['http_code' => 404]);
70+
},
71+
]);
72+
73+
$handler = new PingWebhookMessageHandler($client);
74+
$response = $handler(new PingWebhookMessage('POST', 'https://endpoint.com/key', throw: false));
75+
76+
$this->assertSame(404, $response->getStatusCode());
77+
$this->assertSame('a response', $response->getContent(false));
78+
$this->assertSame('https://endpoint.com/key', $response->getInfo('url'));
79+
}
80+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"psr/http-client": "^1.0",
3939
"symfony/dependency-injection": "^6.4|^7.0",
4040
"symfony/http-kernel": "^6.4|^7.0",
41+
"symfony/messenger": "^6.4|^7.0",
4142
"symfony/process": "^6.4|^7.0",
4243
"symfony/stopwatch": "^6.4|^7.0"
4344
},

0 commit comments

Comments
 (0)