Skip to content

[Notifier] unsupported options exception #59234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
Expand Down Expand Up @@ -63,7 +64,7 @@ protected function doSend(MessageInterface $message): SentMessage
}

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

if ('' !== $message->getFrom()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Bridge/GoIp/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=8.2",
"symfony/http-client": "^6.4|^7.0",
"symfony/notifier": "^7.2"
"symfony/notifier": "^7.3"
},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Symfony\Component\Notifier\Bridge\GoogleChat;

use Symfony\Component\HttpClient\Exception\JsonException;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
Expand Down Expand Up @@ -74,7 +74,7 @@ protected function doSend(MessageInterface $message): SentMessage
}

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

if (!$options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions;
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
Expand Down Expand Up @@ -159,14 +159,15 @@ public function testSendWithNotification()

public function testSendWithInvalidOptions()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('The "'.GoogleChatTransport::class.'" transport only supports instances of "'.GoogleChatOptions::class.'" for options.');
$options = $this->createMock(MessageOptionsInterface::class);
$this->expectException(UnsupportedOptionsException::class);
$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)));

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

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

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

public function testSendWith200ResponseButNotOk()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=8.2",
"symfony/http-client": "^6.4|^7.0",
"symfony/notifier": "^7.2"
"symfony/notifier": "^7.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\GoogleChat\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

use Joli\JoliNotif\DefaultNotifier as JoliNotifier;
use Joli\JoliNotif\Notification as JoliNotification;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\RuntimeException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
use Symfony\Component\Notifier\Message\DesktopMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
Expand Down Expand Up @@ -51,7 +51,7 @@ protected function doSend(MessageInterface $message): SentMessage
}

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

$joliNotification = $this->buildJoliNotificationObject($message, $options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"php": ">=8.2",
"jolicode/jolinotif": "^2.7.2|^3.0",
"symfony/http-client": "^7.2",
"symfony/notifier": "^7.2"
"symfony/notifier": "^7.3"
},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Symfony\Component\Notifier\Bridge\LinkedIn;

use Symfony\Component\Notifier\Bridge\LinkedIn\Share\AuthorShare;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
Expand Down Expand Up @@ -61,7 +61,7 @@ protected function doSend(MessageInterface $message): SentMessage
}

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

if (!$options && $notification = $message->getNotification()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=8.2",
"symfony/http-client": "^6.4|^7.0",
"symfony/notifier": "^7.2"
"symfony/notifier": "^7.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LinkedIn\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
use Symfony\Component\Mercure\Exception\RuntimeException as MercureRuntimeException;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\RuntimeException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
Expand Down Expand Up @@ -67,7 +67,7 @@ protected function doSend(MessageInterface $message): SentMessage
}

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

$options ??= new MercureOptions($this->topics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=8.2",
"symfony/mercure": "^0.5.2|^0.6",
"symfony/notifier": "^7.2",
"symfony/notifier": "^7.3",
"symfony/service-contracts": "^2.5|^3"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace Symfony\Component\Notifier\Bridge\Ntfy;

use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Exception\UnsupportedOptionsException;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\PushMessage;
use Symfony\Component\Notifier\Message\SentMessage;
Expand Down Expand Up @@ -65,8 +65,8 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, PushMessage::class, $message);
}

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

if (!($opts = $message->getOptions()) && $notification = $message->getNotification()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Bridge/Ntfy/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=8.2",
"symfony/clock": "^6.4|^7.0",
"symfony/http-client": "^6.4|^7.0",
"symfony/notifier": "^7.2"
"symfony/notifier": "^7.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Ntfy\\": "" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Notifier\Exception;

use Symfony\Component\Notifier\Message\MessageOptionsInterface;

/**
* @author Raphaël Geffroy <raphael@geffroy.dev>
*/
class UnsupportedOptionsException extends LogicException
{
public function __construct(string $transport, string $supported, MessageOptionsInterface $given)
{
parent::__construct(\sprintf('The "%s" transport only supports instances of "%s" for options (instance of "%s" given).', $transport, $supported, get_debug_type($given)));
}
}