[Notifier][Discord] Make webhookId argument required

This commit is contained in:
Oskar Stark 2020-12-09 15:21:40 +01:00 committed by Fabien Potencier
parent 9052b2b1ee
commit 21c47680f9
3 changed files with 16 additions and 1 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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();