Skip to content

Commit 94a156f

Browse files
committed
minor symfony#59234 [Notifier] unsupported options exception (raphael-geffroy)
This PR was squashed before being merged into the 7.3 branch. Discussion ---------- [Notifier] unsupported options exception | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | Fix symfony#59120 | License | MIT Streamline one more exception for the bridges regarding option classes. Commits ------- 27dfb8c [Notifier] unsupported options exception
2 parents dd882db + 27dfb8c commit 94a156f

File tree

14 files changed

+49
-22
lines changed

14 files changed

+49
-22
lines changed

src/Symfony/Component/Notifier/Bridge/GoIp/GoIpTransport.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Notifier\Exception\LogicException;
1515
use Symfony\Component\Notifier\Exception\TransportException;
1616
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
17+
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
1718
use Symfony\Component\Notifier\Message\MessageInterface;
1819
use Symfony\Component\Notifier\Message\SentMessage;
1920
use Symfony\Component\Notifier\Message\SmsMessage;
@@ -63,7 +64,7 @@ protected function doSend(MessageInterface $message): SentMessage
6364
}
6465

6566
if (($options = $message->getOptions()) && !$options instanceof GoIpOptions) {
66-
throw new LogicException(\sprintf('The "%s" transport only supports an instance of the "%s" as an option class.', __CLASS__, GoIpOptions::class));
67+
throw new UnsupportedOptionsException(__CLASS__, GoIpOptions::class, $options);
6768
}
6869

6970
if ('' !== $message->getFrom()) {

src/Symfony/Component/Notifier/Bridge/GoIp/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=8.2",
2020
"symfony/http-client": "^6.4|^7.0",
21-
"symfony/notifier": "^7.2"
21+
"symfony/notifier": "^7.3"
2222
},
2323
"autoload": {
2424
"psr-4": {

src/Symfony/Component/Notifier/Bridge/GoogleChat/GoogleChatTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat;
1313

1414
use Symfony\Component\HttpClient\Exception\JsonException;
15-
use Symfony\Component\Notifier\Exception\LogicException;
1615
use Symfony\Component\Notifier\Exception\TransportException;
1716
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
17+
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
1818
use Symfony\Component\Notifier\Message\ChatMessage;
1919
use Symfony\Component\Notifier\Message\MessageInterface;
2020
use Symfony\Component\Notifier\Message\SentMessage;
@@ -74,7 +74,7 @@ protected function doSend(MessageInterface $message): SentMessage
7474
}
7575

7676
if (($options = $message->getOptions()) && !$options instanceof GoogleChatOptions) {
77-
throw new LogicException(\sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, GoogleChatOptions::class));
77+
throw new UnsupportedOptionsException(__CLASS__, GoogleChatOptions::class, $options);
7878
}
7979

8080
if (!$options) {

src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatTransportTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use Symfony\Component\HttpClient\MockHttpClient;
1515
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions;
1616
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransport;
17-
use Symfony\Component\Notifier\Exception\LogicException;
1817
use Symfony\Component\Notifier\Exception\TransportException;
18+
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
1919
use Symfony\Component\Notifier\Message\ChatMessage;
2020
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
2121
use Symfony\Component\Notifier\Message\SmsMessage;
@@ -159,14 +159,15 @@ public function testSendWithNotification()
159159

160160
public function testSendWithInvalidOptions()
161161
{
162-
$this->expectException(LogicException::class);
163-
$this->expectExceptionMessage('The "'.GoogleChatTransport::class.'" transport only supports instances of "'.GoogleChatOptions::class.'" for options.');
162+
$options = $this->createMock(MessageOptionsInterface::class);
163+
$this->expectException(UnsupportedOptionsException::class);
164+
$this->expectExceptionMessage(\sprintf('The "%s" transport only supports instances of "%s" for options (instance of "%s" given).', GoogleChatTransport::class, GoogleChatOptions::class, get_debug_type($options)));
164165

165166
$client = new MockHttpClient(fn (string $method, string $url, array $options = []): ResponseInterface => $this->createMock(ResponseInterface::class));
166167

167168
$transport = self::createTransport($client);
168169

169-
$transport->send(new ChatMessage('testMessage', $this->createMock(MessageOptionsInterface::class)));
170+
$transport->send(new ChatMessage('testMessage', $options));
170171
}
171172

172173
public function testSendWith200ResponseButNotOk()

src/Symfony/Component/Notifier/Bridge/GoogleChat/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=8.2",
2020
"symfony/http-client": "^6.4|^7.0",
21-
"symfony/notifier": "^7.2"
21+
"symfony/notifier": "^7.3"
2222
},
2323
"autoload": {
2424
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\GoogleChat\\": "" },

src/Symfony/Component/Notifier/Bridge/JoliNotif/JoliNotifTransport.php

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

1414
use Joli\JoliNotif\DefaultNotifier as JoliNotifier;
1515
use Joli\JoliNotif\Notification as JoliNotification;
16-
use Symfony\Component\Notifier\Exception\LogicException;
1716
use Symfony\Component\Notifier\Exception\RuntimeException;
1817
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
18+
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
1919
use Symfony\Component\Notifier\Message\DesktopMessage;
2020
use Symfony\Component\Notifier\Message\MessageInterface;
2121
use Symfony\Component\Notifier\Message\SentMessage;
@@ -51,7 +51,7 @@ protected function doSend(MessageInterface $message): SentMessage
5151
}
5252

5353
if (($options = $message->getOptions()) && !$options instanceof JoliNotifOptions) {
54-
throw new LogicException(\sprintf('The "%s" transport only supports an instance of the "%s" as an option class.', __CLASS__, JoliNotifOptions::class));
54+
throw new UnsupportedOptionsException(__CLASS__, JoliNotifOptions::class, $options);
5555
}
5656

5757
$joliNotification = $this->buildJoliNotificationObject($message, $options);

src/Symfony/Component/Notifier/Bridge/JoliNotif/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"php": ">=8.2",
2525
"jolicode/jolinotif": "^2.7.2|^3.0",
2626
"symfony/http-client": "^7.2",
27-
"symfony/notifier": "^7.2"
27+
"symfony/notifier": "^7.3"
2828
},
2929
"autoload": {
3030
"psr-4": {

src/Symfony/Component/Notifier/Bridge/LinkedIn/LinkedInTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Component\Notifier\Bridge\LinkedIn;
1313

1414
use Symfony\Component\Notifier\Bridge\LinkedIn\Share\AuthorShare;
15-
use Symfony\Component\Notifier\Exception\LogicException;
1615
use Symfony\Component\Notifier\Exception\TransportException;
1716
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
17+
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
1818
use Symfony\Component\Notifier\Message\ChatMessage;
1919
use Symfony\Component\Notifier\Message\MessageInterface;
2020
use Symfony\Component\Notifier\Message\SentMessage;
@@ -61,7 +61,7 @@ protected function doSend(MessageInterface $message): SentMessage
6161
}
6262

6363
if (($options = $message->getOptions()) && !$options instanceof LinkedInOptions) {
64-
throw new LogicException(\sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, LinkedInOptions::class));
64+
throw new UnsupportedOptionsException(__CLASS__, LinkedInOptions::class, $options);
6565
}
6666

6767
if (!$options && $notification = $message->getNotification()) {

src/Symfony/Component/Notifier/Bridge/LinkedIn/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=8.2",
2020
"symfony/http-client": "^6.4|^7.0",
21-
"symfony/notifier": "^7.2"
21+
"symfony/notifier": "^7.3"
2222
},
2323
"autoload": {
2424
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LinkedIn\\": "" },

src/Symfony/Component/Notifier/Bridge/Mercure/MercureTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
use Symfony\Component\Mercure\Exception\RuntimeException as MercureRuntimeException;
1616
use Symfony\Component\Mercure\HubInterface;
1717
use Symfony\Component\Mercure\Update;
18-
use Symfony\Component\Notifier\Exception\LogicException;
1918
use Symfony\Component\Notifier\Exception\RuntimeException;
2019
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
20+
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
2121
use Symfony\Component\Notifier\Message\ChatMessage;
2222
use Symfony\Component\Notifier\Message\MessageInterface;
2323
use Symfony\Component\Notifier\Message\SentMessage;
@@ -67,7 +67,7 @@ protected function doSend(MessageInterface $message): SentMessage
6767
}
6868

6969
if (($options = $message->getOptions()) && !$options instanceof MercureOptions) {
70-
throw new LogicException(\sprintf('The "%s" transport only supports instances of "%s" for options.', __CLASS__, MercureOptions::class));
70+
throw new UnsupportedOptionsException(__CLASS__, MercureOptions::class, $options);
7171
}
7272

7373
$options ??= new MercureOptions($this->topics);

0 commit comments

Comments
 (0)