[Notifier][Discord] Make webhookId argument required
This commit is contained in:
parent
9052b2b1ee
commit
21c47680f9
@ -32,7 +32,7 @@ final class DiscordTransport extends AbstractTransport
|
||||
private $token;
|
||||
private $webhookId;
|
||||
|
||||
public function __construct(string $token, string $webhookId = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
|
||||
public function __construct(string $token, string $webhookId, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
|
||||
{
|
||||
$this->token = $token;
|
||||
$this->webhookId = $webhookId;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Notifier\Bridge\Discord;
|
||||
|
||||
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
|
||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
||||
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
|
||||
use Symfony\Component\Notifier\Transport\Dsn;
|
||||
@ -31,6 +32,11 @@ final class DiscordTransportFactory extends AbstractTransportFactory
|
||||
$scheme = $dsn->getScheme();
|
||||
$token = $this->getUser($dsn);
|
||||
$webhookId = $dsn->getOption('webhook_id');
|
||||
|
||||
if (!$webhookId) {
|
||||
throw new IncompleteDsnException('Missing webhook_id.', $dsn->getOriginalDsn());
|
||||
}
|
||||
|
||||
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
|
||||
$port = $dsn->getPort();
|
||||
|
||||
|
@ -31,6 +31,15 @@ final class DiscordTransportFactoryTest extends TestCase
|
||||
$this->assertSame(sprintf('discord://%s?webhook_id=%s', $host, $webhookId), (string) $transport);
|
||||
}
|
||||
|
||||
public function testCreateWithNoWebhookIdThrowsMalformed(): void
|
||||
{
|
||||
$factory = new DiscordTransportFactory();
|
||||
|
||||
$this->expectException(IncompleteDsnException::class);
|
||||
|
||||
$factory->create(Dsn::fromString('discord://token@host'));
|
||||
}
|
||||
|
||||
public function testCreateWithNoTokenThrowsMalformed()
|
||||
{
|
||||
$factory = new DiscordTransportFactory();
|
||||
|
Reference in New Issue
Block a user