Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Notifier] [DX] Dsn::getRequiredOption() #39457

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
merged 1 commit into from
Jan 6, 2021
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 @@ -11,7 +11,6 @@

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;
Expand All @@ -34,12 +33,7 @@ public function create(Dsn $dsn): TransportInterface
}

$token = $this->getUser($dsn);
$webhookId = $dsn->getOption('webhook_id');

if (!$webhookId) {
throw new IncompleteDsnException('Missing webhook_id.', $dsn->getOriginalDsn());
}

$webhookId = $dsn->getRequiredOption('webhook_id');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Discord\DiscordTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\MissingRequiredOptionException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;

Expand All @@ -28,11 +29,11 @@ public function testCreateWithDsn()
$this->assertSame('discord://host.test?webhook_id=testWebhookId', (string) $transport);
}

public function testCreateWithMissingOptionWebhookIdThrowsIncompleteDsnException()
public function testCreateWithMissingOptionWebhookIdThrowsMissingRequiredOptionException()
{
$factory = $this->createFactory();

$this->expectException(IncompleteDsnException::class);
$this->expectException(MissingRequiredOptionException::class);

$factory->create(Dsn::fromString('discord://token@host'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Notifier\Bridge\Esendex;

use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
Expand All @@ -32,18 +31,8 @@ public function create(Dsn $dsn): TransportInterface

$email = $this->getUser($dsn);
$password = $this->getPassword($dsn);
$accountReference = $dsn->getOption('accountreference');

if (!$accountReference) {
throw new IncompleteDsnException('Missing accountreference.', $dsn->getOriginalDsn());
}

$from = $dsn->getOption('from');

if (!$from) {
throw new IncompleteDsnException('Missing from.', $dsn->getOriginalDsn());
}

$accountReference = $dsn->getRequiredOption('accountreference');
$from = $dsn->getRequiredOption('from');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\MissingRequiredOptionException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;

Expand Down Expand Up @@ -46,20 +47,20 @@ public function testCreateWithMissingPasswordThrowsIncompleteDsnException()
$factory->create(Dsn::fromString('esendex://email:@host?accountreference=testAccountreference&from=FROM'));
}

public function testCreateWithMissingOptionAccountreferenceThrowsIncompleteDsnException()
public function testCreateWithMissingOptionAccountreferenceThrowsMissingRequiredOptionException()
{
$factory = $this->createFactory();

$this->expectException(IncompleteDsnException::class);
$this->expectException(MissingRequiredOptionException::class);

$factory->create(Dsn::fromString('esendex://email:password@host?from=FROM'));
}

public function testCreateWithMissingOptionFromThrowsIncompleteDsnException()
public function testCreateWithMissingOptionFromThrowsMissingRequiredOptionException()
{
$factory = $this->createFactory();

$this->expectException(IncompleteDsnException::class);
$this->expectException(MissingRequiredOptionException::class);

$factory->create(Dsn::fromString('esendex://email:password@host?accountreference=ACCOUNTREFERENCE'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Notifier\Bridge\FreeMobile;

use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
Expand All @@ -35,11 +34,7 @@ public function create(Dsn $dsn): TransportInterface

$login = $this->getUser($dsn);
$password = $this->getPassword($dsn);
$phone = $dsn->getOption('phone');

if (!$phone) {
throw new IncompleteDsnException('Missing phone.', $dsn->getOriginalDsn());
}
$phone = $dsn->getRequiredOption('phone');

$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function supportsProvider(): iterable
yield [false, 'somethingElse://login:pass@default?phone=0611223344'];
}

public function incompleteDsnProvider(): iterable
public function missingRequiredOptionProvider(): iterable
{
yield 'missing option: phone' => ['freemobile://login:pass@default'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Notifier\Bridge\Infobip;

use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
Expand All @@ -35,14 +34,10 @@ public function create(Dsn $dsn): TransportInterface
}

$authToken = $this->getUser($dsn);
$from = $dsn->getOption('from');
$from = $dsn->getRequiredOption('from');
$host = $dsn->getHost();
$port = $dsn->getPort();

if (!$from) {
throw new IncompleteDsnException('Missing from.', $dsn->getOriginalDsn());
}

return (new InfobipTransport($authToken, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Infobip\InfobipTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\MissingRequiredOptionException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;

Expand All @@ -28,11 +28,11 @@ public function testCreateWithDsn()
$this->assertSame('infobip://host.test?from=0611223344', (string) $transport);
}

public function testCreateWithNoFromThrowsIncompleteDsnException()
public function testCreateWithNoFromThrowsMissingRequiredOptionException()
{
$factory = $this->createFactory();

$this->expectException(IncompleteDsnException::class);
$this->expectException(MissingRequiredOptionException::class);
$factory->create(Dsn::fromString('infobip://authtoken@default'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Notifier\Bridge\Iqsms;

use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
Expand All @@ -35,12 +34,7 @@ public function create(Dsn $dsn): TransportInterface

$login = $this->getUser($dsn);
$password = $this->getPassword($dsn);
$from = $dsn->getOption('from');

if (!$from) {
throw new IncompleteDsnException('Missing from.', $dsn->getOriginalDsn());
}

$from = $dsn->getRequiredOption('from');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Notifier\Bridge\Mattermost;

use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
Expand All @@ -32,12 +31,7 @@ public function create(Dsn $dsn): TransportInterface

$path = $dsn->getPath();
$token = $this->getUser($dsn);
$channel = $dsn->getOption('channel');

if (!$channel) {
throw new IncompleteDsnException('Missing channel.', $dsn->getOriginalDsn());
}

$channel = $dsn->getRequiredOption('channel');
$host = $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public function supportsProvider(): iterable

public function incompleteDsnProvider(): iterable
{
yield 'missing option: token' => ['mattermost://host.test?channel=testChannel'];
yield 'missing token' => ['mattermost://host.test?channel=testChannel'];
}

public function missingRequiredOptionProvider(): iterable
{
yield 'missing option: channel' => ['mattermost://token@host'];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Notifier\Bridge\Mobyt;

use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
Expand All @@ -35,12 +34,7 @@ public function create(Dsn $dsn): TransportInterface

$accountSid = $this->getUser($dsn);
$authToken = $this->getPassword($dsn);
$from = $dsn->getOption('from');

if (!$from) {
throw new IncompleteDsnException('Missing from.', $dsn->getOriginalDsn());
}

$from = $dsn->getRequiredOption('from');
$typeQuality = $dsn->getOption('type_quality', MobytOptions::MESSAGE_TYPE_QUALITY_LOW);
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Notifier\Bridge\Nexmo;

use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
Expand All @@ -35,12 +34,7 @@ public function create(Dsn $dsn): TransportInterface

$apiKey = $this->getUser($dsn);
$apiSecret = $this->getPassword($dsn);
$from = $dsn->getOption('from');

if (!$from) {
throw new IncompleteDsnException('Missing from.', $dsn->getOriginalDsn());
}

$from = $dsn->getRequiredOption('from');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function supportsProvider(): iterable
yield [false, 'somethingElse://apiKey:apiSecret@default?from=0611223344'];
}

public function incompleteDsnProvider(): iterable
public function missingRequiredOptionProvider(): iterable
{
yield 'missing option: from' => ['nexmo://apiKey:apiSecret@default'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Notifier\Bridge\OvhCloud;

use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
Expand All @@ -32,18 +31,8 @@ public function create(Dsn $dsn): TransportInterface

$applicationKey = $this->getUser($dsn);
$applicationSecret = $this->getPassword($dsn);
$consumerKey = $dsn->getOption('consumer_key');

if (!$consumerKey) {
throw new IncompleteDsnException('Missing consumer_key.', $dsn->getOriginalDsn());
}

$serviceName = $dsn->getOption('service_name');

if (!$serviceName) {
throw new IncompleteDsnException('Missing service_name.', $dsn->getOriginalDsn());
}

$consumerKey = $dsn->getRequiredOption('consumer_key');
$serviceName = $dsn->getRequiredOption('service_name');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less noise by using the new method

$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function supportsProvider(): iterable
yield [false, 'somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
}

public function incompleteDsnProvider(): iterable
public function missingRequiredOptionProvider(): iterable
{
yield 'missing option: consumer_key' => ['ovhcloud://key:secret@default?service_name=serviceName'];
yield 'missing option: service_name' => ['ovhcloud://key:secret@default?consumer_key=consumerKey'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function supportsProvider(): iterable

public function incompleteDsnProvider(): iterable
{
yield 'missing option: token' => ['rocketchat://host.test?channel=testChannel'];
yield 'missing token' => ['rocketchat://host.test?channel=testChannel'];
}

public function unsupportedSchemeProvider(): iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Notifier\Bridge\Sendinblue;

use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
Expand All @@ -34,12 +33,7 @@ public function create(Dsn $dsn): TransportInterface
}

$apiKey = $this->getUser($dsn);
$sender = $dsn->getOption('sender');

if (!$sender) {
throw new IncompleteDsnException('Missing sender.', $dsn->getOriginalDsn());
}

$sender = $dsn->getRequiredOption('sender');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Sendinblue\SendinblueTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\MissingRequiredOptionException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;

Expand All @@ -28,11 +29,11 @@ public function testCreateWithDsn()
$this->assertSame('sendinblue://host.test?sender=0611223344', (string) $transport);
}

public function testCreateWithMissingOptionSenderThrowsIncompleteDsnException()
public function testCreateWithMissingOptionSenderThrowsMissingRequiredOptionException()
{
$factory = $this->createFactory();

$this->expectException(IncompleteDsnException::class);
$this->expectException(MissingRequiredOptionException::class);

$factory->create(Dsn::fromString('sendinblue://apiKey@host.test'));
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.