Merge branch '5.1' into 5.2

* 5.1:
  [Notifier] [DX] Abstract test cases
  [Intl] Update the ICU data to 68.2
This commit is contained in:
Alexander M. Turek 2020-12-22 15:40:43 +01:00
commit 3c753e6eff
35 changed files with 742 additions and 799 deletions

View File

@ -4,6 +4,7 @@
"preferred-install": {
"symfony/form": "source",
"symfony/http-kernel": "source",
"symfony/notifier": "source",
"symfony/validator": "source",
"*": "dist"
}

View File

@ -125,7 +125,7 @@ final class Intl
*/
public static function getIcuStubVersion(): string
{
return '68.1';
return '68.2';
}
/**

View File

@ -731,8 +731,8 @@
"ALL": 8,
"DZD": 12,
"ADP": 20,
"AON": 24,
"AOK": 24,
"AON": 24,
"AZM": 31,
"ARA": 32,
"ARP": 32,
@ -751,16 +751,16 @@
"BOP": 68,
"BAD": 70,
"BWP": 72,
"BRN": 76,
"BRE": 76,
"BRC": 76,
"BRB": 76,
"BRC": 76,
"BRE": 76,
"BRN": 76,
"BZD": 84,
"SBD": 90,
"BND": 96,
"BGL": 100,
"MMK": 104,
"BUK": 104,
"MMK": 104,
"BIF": 108,
"BYB": 112,
"KHR": 116,
@ -772,11 +772,11 @@
"CNY": 156,
"COP": 170,
"KMF": 174,
"ZRZ": 180,
"ZRN": 180,
"ZRZ": 180,
"CRC": 188,
"HRK": 191,
"HRD": 191,
"HRK": 191,
"CUP": 192,
"CYP": 196,
"CSK": 200,
@ -802,8 +802,8 @@
"GIP": 292,
"GRD": 300,
"GTQ": 320,
"GNS": 324,
"GNF": 324,
"GNS": 324,
"GYD": 328,
"HTG": 332,
"HNL": 340,
@ -832,8 +832,8 @@
"LAK": 418,
"LBP": 422,
"LSL": 426,
"LVR": 428,
"LVL": 428,
"LVR": 428,
"LRD": 430,
"LYD": 434,
"LTL": 440,
@ -849,8 +849,8 @@
"MTP": 470,
"MRO": 478,
"MUR": 480,
"MXP": 484,
"MXN": 484,
"MXP": 484,
"MNT": 496,
"MDL": 498,
"MAD": 504,
@ -873,13 +873,13 @@
"PGK": 598,
"PYG": 600,
"PEI": 604,
"PES": 604,
"PEN": 604,
"PES": 604,
"PHP": 608,
"PLZ": 616,
"PTE": 620,
"GWP": 624,
"GWE": 624,
"GWP": 624,
"TPE": 626,
"QAR": 634,
"ROL": 642,
@ -896,8 +896,8 @@
"SIT": 705,
"SOS": 706,
"ZAR": 710,
"ZWD": 716,
"RHD": 716,
"ZWD": 716,
"YDD": 720,
"ESP": 724,
"SSP": 728,
@ -916,8 +916,8 @@
"TND": 788,
"TRL": 792,
"TMM": 795,
"UGX": 800,
"UGS": 800,
"UGX": 800,
"UAK": 804,
"MKD": 807,
"RUR": 810,
@ -932,10 +932,10 @@
"VEB": 862,
"WST": 882,
"YER": 886,
"YUN": 890,
"YUD": 890,
"YUM": 891,
"YUN": 890,
"CSD": 891,
"YUM": 891,
"ZMK": 894,
"TWD": 901,
"UYW": 927,
@ -1010,8 +1010,8 @@
"ADP"
],
"24": [
"AON",
"AOK"
"AOK",
"AON"
],
"31": [
"AZM"
@ -1062,10 +1062,10 @@
"BWP"
],
"76": [
"BRN",
"BRE",
"BRB",
"BRC",
"BRB"
"BRE",
"BRN"
],
"84": [
"BZD"
@ -1080,8 +1080,8 @@
"BGL"
],
"104": [
"MMK",
"BUK"
"BUK",
"MMK"
],
"108": [
"BIF"
@ -1117,15 +1117,15 @@
"KMF"
],
"180": [
"ZRZ",
"ZRN"
"ZRN",
"ZRZ"
],
"188": [
"CRC"
],
"191": [
"HRK",
"HRD"
"HRD",
"HRK"
],
"192": [
"CUP"
@ -1203,8 +1203,8 @@
"GTQ"
],
"324": [
"GNS",
"GNF"
"GNF",
"GNS"
],
"328": [
"GYD"
@ -1285,8 +1285,8 @@
"LSL"
],
"428": [
"LVR",
"LVL"
"LVL",
"LVR"
],
"430": [
"LRD"
@ -1330,8 +1330,8 @@
"MUR"
],
"484": [
"MXP",
"MXN"
"MXN",
"MXP"
],
"496": [
"MNT"
@ -1394,8 +1394,8 @@
],
"604": [
"PEI",
"PES",
"PEN"
"PEN",
"PES"
],
"608": [
"PHP"
@ -1407,8 +1407,8 @@
"PTE"
],
"624": [
"GWP",
"GWE"
"GWE",
"GWP"
],
"626": [
"TPE"
@ -1459,8 +1459,8 @@
"ZAR"
],
"716": [
"ZWD",
"RHD"
"RHD",
"ZWD"
],
"720": [
"YDD"
@ -1515,8 +1515,8 @@
"TMM"
],
"800": [
"UGX",
"UGS"
"UGS",
"UGX"
],
"804": [
"UAK"
@ -1557,12 +1557,12 @@
"YER"
],
"890": [
"YUN",
"YUD"
"YUD",
"YUN"
],
"891": [
"YUM",
"CSD"
"CSD",
"YUM"
],
"894": [
"ZMK"

View File

@ -2,6 +2,6 @@ Git information
===============
URL: https://github.com/unicode-org/icu.git
Revision: 5d81f6f9a0edc47892a1d2af7024f835b47deb82
Author: Jeff Genovy
Date: 2020-10-27T10:20:57-07:00
Revision: 84e1f26ea77152936e70d53178a816dbfbf69989
Author: Peter Edberg
Date: 2020-12-13T21:28:54-08:00

View File

@ -1 +1 @@
68.1
68.2

View File

@ -11,50 +11,39 @@
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Firebase\FirebaseTransportFactory;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class FirebaseTransportFactoryTest extends TestCase
final class FirebaseTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('firebase://username:password@host.test'));
$this->assertSame('firebase://host.test', (string) $transport);
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('firebase://username:password@default')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://username:password@default')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://username:password@default'));
}
private function createFactory(): FirebaseTransportFactory
/**
* @return FirebaseTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new FirebaseTransportFactory();
}
public function createProvider(): iterable
{
yield [
'firebase://host.test',
'firebase://username:password@host.test',
];
}
public function supportsProvider(): iterable
{
yield [true, 'firebase://username:password@default'];
yield [false, 'somethingElse://username:password@default'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://username:password@default'];
}
}

View File

@ -11,44 +11,40 @@
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Firebase\FirebaseTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class FirebaseTransportTest extends TestCase
final class FirebaseTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return FirebaseTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('firebase://host.test', (string) $transport);
return new FirebaseTransport('username:password', $client ?: $this->createMock(HttpClientInterface::class));
}
public function testSupportsMessageInterface()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['firebase://fcm.googleapis.com/fcm/send', $this->createTransport()];
}
public function testSendNonSmsMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new ChatMessage('Hello!')];
}
private function createTransport(): FirebaseTransport
public function unsupportedMessagesProvider(): iterable
{
return (new FirebaseTransport('username:password', $this->createMock(HttpClientInterface::class)))->setHost('host.test');
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Firebase\\": "" },

View File

@ -11,67 +11,42 @@
namespace Symfony\Component\Notifier\Bridge\FreeMobile\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class FreeMobileTransportFactoryTest extends TestCase
final class FreeMobileTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('freemobile://login:pass@host.test?phone=0611223344'));
$this->assertSame('freemobile://host.test?phone=0611223344', (string) $transport);
}
public function testCreateWithNoPhoneThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('freemobile://login:pass@default'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('freemobile://login:pass@default?phone=0611223344')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://login:pass@default?phone=0611223344')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://login:pass@default?phone=0611223344'));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
// unsupported scheme and missing "phone" option
$factory->create(Dsn::fromString('somethingElse://login:pass@default'));
}
private function createFactory(): FreeMobileTransportFactory
/**
* @return FreeMobileTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new FreeMobileTransportFactory();
}
public function createProvider(): iterable
{
yield [
'freemobile://host.test?phone=0611223344',
'freemobile://login:pass@host.test?phone=0611223344',
];
}
public function supportsProvider(): iterable
{
yield [true, 'freemobile://login:pass@default?phone=0611223344'];
yield [false, 'somethingElse://login:pass@default?phone=0611223344'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing option: phone' => ['freemobile://login:pass@default'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://login:pass@default?phone=0611223344'];
yield ['somethingElse://login:pass@default']; // missing "phone" option
}
}

View File

@ -11,65 +11,39 @@
namespace Symfony\Component\Notifier\Bridge\FreeMobile\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class FreeMobileTransportTest extends TestCase
final class FreeMobileTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
{
$transport = $this->createTransport('0611223344');
$this->assertSame('freemobile://host.test?phone=0611223344', (string) $transport);
}
/**
* @dataProvider supportsProvider
* @return FreeMobileTransport
*/
public function testSupportsMessageInterface(bool $expected, string $configuredPhoneNumber, MessageInterface $message)
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport($configuredPhoneNumber);
$this->assertSame($expected, $transport->supports($message));
return new FreeMobileTransport('login', 'pass', '0611223344', $client ?: $this->createMock(HttpClientInterface::class));
}
/**
* @return iterable<array{0: bool, 1: string, 2: MessageInterface}>
*/
public function supportsProvider(): iterable
public function toStringProvider(): iterable
{
yield [true, '0611223344', new SmsMessage('0611223344', 'Hello!')];
yield [true, '0611223344', new SmsMessage('+33611223344', 'Hello!')];
yield [false, '0611223344', new SmsMessage('0699887766', 'Hello!')];
yield [false, '0611223344', $this->createMock(MessageInterface::class)];
yield [true, '+33611223344', new SmsMessage('0611223344', 'Hello!')];
yield [true, '+33611223344', new SmsMessage('+33611223344', 'Hello!')];
yield ['freemobile://smsapi.free-mobile.fr/sendmsg?phone=0611223344', $this->createTransport()];
}
public function testSendNonSmsMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport('0611223344');
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new SmsMessage('0611223344', 'Hello!')];
yield [new SmsMessage('+33611223344', 'Hello!')];
}
public function testSendSmsMessageButInvalidPhoneThrowsLogicException()
public function unsupportedMessagesProvider(): iterable
{
$transport = $this->createTransport('0611223344');
$this->expectException(LogicException::class);
$transport->send(new SmsMessage('0699887766', 'Hello!'));
}
private function createTransport(string $phone): FreeMobileTransport
{
return (new FreeMobileTransport('login', 'pass', $phone, $this->createMock(HttpClientInterface::class)))->setHost('host.test');
yield [new SmsMessage('0699887766', 'Hello!')]; // because this phone number is not configured on the transport!
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

@ -19,7 +19,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.1",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FreeMobile\\": "" },

View File

@ -11,97 +11,61 @@
namespace Symfony\Component\Notifier\Bridge\Mattermost\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class MattermostTransportFactoryTest extends TestCase
final class MattermostTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('mattermost://accessToken@host.test?channel=testChannel'));
$this->assertSame('mattermost://host.test?channel=testChannel', (string) $transport);
}
public function testCreateWithDsnHostWithSubfolder()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('mattermost://accessToken@example.com/sub?channel=testChannel'));
$this->assertSame('mattermost://example.com/sub?channel=testChannel', (string) $transport);
}
public function testCreateWithDsnHostWithSubfolderWithTrailingSlash()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('mattermost://accessToken@example.com/sub/?channel=testChannel'));
$this->assertSame('mattermost://example.com/sub?channel=testChannel', (string) $transport);
}
public function testCreateWithMissingOptionChannelThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('mattermost://token@host'));
}
public function testCreateWithNoTokenThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('mattermost://host.test?channel=testChannel'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('mattermost://token@host?channel=testChannel')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host?channel=testChannel')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://token@host?channel=testChannel'));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
// unsupported scheme and missing "channel" option
$factory->create(Dsn::fromString('somethingElse://token@host'));
}
private function createFactory(): MattermostTransportFactory
/**
* @return MattermostTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new MattermostTransportFactory();
}
public function createProvider(): iterable
{
yield [
'mattermost://host.test?channel=testChannel',
'mattermost://accessToken@host.test?channel=testChannel',
];
yield [
'mattermost://example.com/sub?channel=testChannel',
'mattermost://accessToken@example.com/sub?channel=testChannel',
];
yield [
'mattermost://example.com/sub?channel=testChannel',
'mattermost://accessToken@example.com/sub/?channel=testChannel',
];
yield [
'mattermost://example.com/sub/sub-2?channel=testChannel',
'mattermost://accessToken@example.com/sub/sub-2?channel=testChannel',
];
}
public function supportsProvider(): iterable
{
yield [true, 'mattermost://token@host?channel=testChannel'];
yield [false, 'somethingElse://token@host?channel=testChannel'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing option: token' => ['mattermost://host.test?channel=testChannel'];
yield 'missing option: channel' => ['mattermost://token@host'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://token@host?channel=testChannel'];
yield ['somethingElse://token@host']; // missing "channel" option
}
}

View File

@ -11,44 +11,40 @@
namespace Symfony\Component\Notifier\Bridge\Mattermost\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class MattermostTransportTest extends TestCase
final class MattermostTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return MattermostTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('mattermost://host.test?channel=testChannel', (string) $transport);
return (new MattermostTransport('testAccessToken', 'testChannel', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
public function testSupportsChatMessage()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['mattermost://host.test?channel=testChannel', $this->createTransport()];
}
public function testSendNonChatMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new ChatMessage('Hello!')];
}
private function createTransport(): MattermostTransport
public function unsupportedMessagesProvider(): iterable
{
return (new MattermostTransport('testAccessToken', 'testChannel', $this->createMock(HttpClientInterface::class)))->setHost('host.test');
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mattermost\\": "" },

View File

@ -11,67 +11,42 @@
namespace Symfony\Component\Notifier\Bridge\Nexmo\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Nexmo\NexmoTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class NexmoTransportFactoryTest extends TestCase
final class NexmoTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('nexmo://apiKey:apiSecret@host.test?from=0611223344'));
$this->assertSame('nexmo://host.test?from=0611223344', (string) $transport);
}
public function testCreateWithMissingOptionFromThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('nexmo://apiKey:apiSecret@default'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('nexmo://apiKey:apiSecret@default?from=0611223344')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('nexmoo://apiKey:apiSecret@default?from=0611223344')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://apiKey:apiSecret@default?from=0611223344'));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
// unsupported scheme and missing "from" option
$factory->create(Dsn::fromString('somethingElse://apiKey:apiSecret@default'));
}
private function createFactory(): NexmoTransportFactory
/**
* @return NexmoTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new NexmoTransportFactory();
}
public function createProvider(): iterable
{
yield [
'nexmo://host.test?from=0611223344',
'nexmo://apiKey:apiSecret@host.test?from=0611223344',
];
}
public function supportsProvider(): iterable
{
yield [true, 'nexmo://apiKey:apiSecret@default?from=0611223344'];
yield [false, 'somethingElse://apiKey:apiSecret@default?from=0611223344'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing option: from' => ['nexmo://apiKey:apiSecret@default'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://apiKey:apiSecret@default?from=0611223344'];
yield ['somethingElse://apiKey:apiSecret@default']; // missing "from" option
}
}

View File

@ -11,41 +11,37 @@
namespace Symfony\Component\Notifier\Bridge\Nexmo\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Nexmo\NexmoTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class NexmoTransportTest extends TestCase
final class NexmoTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return NexmoTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('nexmo://host.test?from=sender', (string) $transport);
return new NexmoTransport('apiKey', 'apiSecret', 'sender', $client ?: $this->createMock(HttpClientInterface::class));
}
public function testSupportsMessageInterface()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['nexmo://rest.nexmo.com?from=sender', $this->createTransport()];
}
public function testSendNonSmsMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new SmsMessage('0611223344', 'Hello!')];
}
private function createTransport(): NexmoTransport
public function unsupportedMessagesProvider(): iterable
{
return (new NexmoTransport('apiKey', 'apiSecret', 'sender', $this->createMock(HttpClientInterface::class)))->setHost('host.test');
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Nexmo\\": "" },

View File

@ -11,76 +11,44 @@
namespace Symfony\Component\Notifier\Bridge\OvhCloud\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class OvhCloudTransportFactoryTest extends TestCase
final class OvhCloudTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('ovhcloud://applicationKey:applicationSecret@host.test?consumer_key=consumerKey&service_name=serviceName'));
$this->assertSame('ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName', (string) $transport);
}
public function testCreateWithMissingOptionConsumerKeyThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('ovhcloud://applicationKey:applicationSecret@default?service_name=serviceName'));
}
public function testCreateWithMissingOptionServiceNameThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('ovhcloud://applicationKey:applicationSecret@default?consumeer_key=consumerKey'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('ovhcloud://applicationKey:applicationSecret@default?consumer_key=consumerKey&service_name=serviceName')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://applicationKey:applicationSecret@default?consumer_key=consumerKey&service_name=serviceName')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://applicationKey:applicationSecret@default?consumer_key=consumerKey&service_name=serviceName'));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
// unsupported scheme and missing "service_name" option
$factory->create(Dsn::fromString('somethingElse://applicationKey:applicationSecret@default?consumer_key=consumerKey'));
}
private function createFactory(): OvhCloudTransportFactory
/**
* @return OvhCloudTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new OvhCloudTransportFactory();
}
public function createProvider(): iterable
{
yield [
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName',
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName',
];
}
public function supportsProvider(): iterable
{
yield [true, 'ovhcloud://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
yield [false, 'somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
}
public function incompleteDsnProvider(): 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'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
yield ['somethingElse://key:secret@default?service_name=serviceName'];
yield ['somethingElse://key:secret@default?consumer_key=consumerKey'];
}
}

View File

@ -11,41 +11,37 @@
namespace Symfony\Component\Notifier\Bridge\OvhCloud\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class OvhCloudTransportTest extends TestCase
final class OvhCloudTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return OvhCloudTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName', (string) $transport);
return new OvhCloudTransport('applicationKey', 'applicationSecret', 'consumerKey', 'serviceName', $client ?: $this->createMock(HttpClientInterface::class));
}
public function testSupportsMessageInterface()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName', $this->createTransport()];
}
public function testSendNonSmsMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new SmsMessage('0611223344', 'Hello!')];
}
private function createTransport(): OvhCloudTransport
public function unsupportedMessagesProvider(): iterable
{
return (new OvhCloudTransport('applicationKey', 'applicationSecret', 'consumerKey', 'serviceName', $this->createMock(HttpClientInterface::class)))->setHost('host.test');
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" },

View File

@ -11,60 +11,44 @@
namespace Symfony\Component\Notifier\Bridge\RocketChat\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class RocketChatTransportFactoryTest extends TestCase
final class RocketChatTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('rocketchat://accessToken@host.test?channel=testChannel'));
$this->assertSame('rocketchat://host.test?channel=testChannel', (string) $transport);
}
public function testCreateWithNoTokenThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('rocketchat://host.test?channel=testChannel'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('rocketchat://token@host?channel=testChannel')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host?channel=testChannel')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://token@host?channel=testChannel'));
}
private function createFactory(): RocketChatTransportFactory
/**
* @return RocketChatTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new RocketChatTransportFactory();
}
public function createProvider(): iterable
{
yield [
'rocketchat://host.test?channel=testChannel',
'rocketchat://accessToken@host.test?channel=testChannel',
];
}
public function supportsProvider(): iterable
{
yield [true, 'rocketchat://token@host?channel=testChannel'];
yield [false, 'somethingElse://token@host?channel=testChannel'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing option: token' => ['rocketchat://host.test?channel=testChannel'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://token@host?channel=testChannel'];
}
}

View File

@ -11,50 +11,41 @@
namespace Symfony\Component\Notifier\Bridge\RocketChat\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class RocketChatTransportTest extends TestCase
final class RocketChatTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return RocketChatTransport
*/
public function createTransport(?HttpClientInterface $client = null, string $channel = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('rocketchat://host.test?channel=testChannel', (string) $transport);
return new RocketChatTransport('testAccessToken', $channel, $client ?: $this->createMock(HttpClientInterface::class));
}
public function testToStringContainsNoChannelBecauseItsOptional()
public function toStringProvider(): iterable
{
$transport = $this->createTransport(null);
$this->assertSame('rocketchat://host.test', (string) $transport);
yield ['rocketchat://rocketchat.com', $this->createTransport()];
yield ['rocketchat://rocketchat.com?channel=testChannel', $this->createTransport(null, 'testChannel')];
}
public function testSupportsChatMessage()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield [new ChatMessage('Hello!')];
}
public function testSendNonChatMessageThrowsLogicException()
public function unsupportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
}
private function createTransport(?string $channel = 'testChannel'): RocketChatTransport
{
return (new RocketChatTransport('testAccessToken', $channel, $this->createMock(HttpClientInterface::class)))->setHost('host.test');
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\RocketChat\\": "" },

View File

@ -11,67 +11,42 @@
namespace Symfony\Component\Notifier\Bridge\Sinch\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Sinch\SinchTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class SinchTransportFactoryTest extends TestCase
final class SinchTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('sinch://accountSid:authToken@host.test?from=0611223344'));
$this->assertSame('sinch://host.test?from=0611223344', (string) $transport);
}
public function testCreateWithMissingOptionFromThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('sinch://accountSid:authToken@default'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('sinch://accountSid:authToken@default?from=0611223344')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://accountSid:authToken@default?from=0611223344')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://accountSid:authToken@default?from=0611223344'));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
// unsupported scheme and missing "from" option
$factory->create(Dsn::fromString('somethingElse://accountSid:authToken@default'));
}
private function createFactory(): SinchTransportFactory
/**
* @return SinchTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new SinchTransportFactory();
}
public function createProvider(): iterable
{
yield [
'sinch://host.test?from=0611223344',
'sinch://accountSid:authToken@host.test?from=0611223344',
];
}
public function supportsProvider(): iterable
{
yield [true, 'sinch://accountSid:authToken@default?from=0611223344'];
yield [false, 'somethingElse://accountSid:authToken@default?from=0611223344'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing option: from' => ['sinch://accountSid:authToken@default'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://accountSid:authToken@default?from=0611223344'];
yield ['somethingElse://accountSid:authToken@default']; // missing "from" option
}
}

View File

@ -11,41 +11,37 @@
namespace Symfony\Component\Notifier\Bridge\Sinch\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Sinch\SinchTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class SinchTransportTest extends TestCase
final class SinchTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return SinchTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('sinch://host.test?from=sender', (string) $transport);
return new SinchTransport('accountSid', 'authToken', 'sender', $client ?: $this->createMock(HttpClientInterface::class));
}
public function testSupportsMessageInterface()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['sinch://sms.api.sinch.com?from=sender', $this->createTransport()];
}
public function testSendNonSmsMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new SmsMessage('0611223344', 'Hello!')];
}
private function createTransport(): SinchTransport
public function unsupportedMessagesProvider(): iterable
{
return (new SinchTransport('accountSid', 'authToken', 'sender', $this->createMock(HttpClientInterface::class)))->setHost('host.test');
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

@ -19,7 +19,7 @@
"php": ">=7.2.5",
"ext-json": "*",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sinch\\": "" },

View File

@ -19,7 +19,7 @@
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"require-dev": {
"symfony/event-dispatcher": "^4.3|^5.0"

View File

@ -11,66 +11,42 @@
namespace Symfony\Component\Notifier\Bridge\Telegram\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class TelegramTransportFactoryTest extends TestCase
final class TelegramTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('telegram://user:password@host.test?channel=testChannel'));
$this->assertSame('telegram://host.test?channel=testChannel', (string) $transport);
}
public function testCreateWithNoPasswordThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('telegram://simpleToken@host.test?channel=testChannel'));
}
public function testCreateWithNoTokenThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('telegram://host.test?channel=testChannel'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('telegram://host?channel=testChannel')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host?channel=testChannel')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://user:pwd@host?channel=testChannel'));
}
private function createFactory(): TelegramTransportFactory
/**
* @return TelegramTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new TelegramTransportFactory();
}
public function createProvider(): iterable
{
yield [
'telegram://host.test?channel=testChannel',
'telegram://user:password@host.test?channel=testChannel',
];
}
public function supportsProvider(): iterable
{
yield [true, 'telegram://host?channel=testChannel'];
yield [false, 'somethingElse://host?channel=testChannel'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing password' => ['telegram://token@host.test?channel=testChannel'];
yield 'missing token' => ['telegram://host.test?channel=testChannel'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://user:pwd@host'];
}
}

View File

@ -11,48 +11,43 @@
namespace Symfony\Component\Notifier\Bridge\Telegram\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
final class TelegramTransportTest extends TestCase
final class TelegramTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return TelegramTransport
*/
public function createTransport(?HttpClientInterface $client = null, string $channel = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('telegram://host.test?channel=testChannel', (string) $transport);
return new TelegramTransport('token', $channel, $client ?: $this->createMock(HttpClientInterface::class));
}
public function testToStringContainsNoChannelBecauseItsOptional()
public function toStringProvider(): iterable
{
$transport = $this->createTransport(null);
$this->assertSame('telegram://host.test', (string) $transport);
yield ['telegram://api.telegram.org', $this->createTransport()];
yield ['telegram://api.telegram.org?channel=testChannel', $this->createTransport(null, 'testChannel')];
}
public function testSupportsChatMessage()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield [new ChatMessage('Hello!')];
}
public function testSendNonChatMessageThrowsLogicException()
public function unsupportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
public function testSendWithErrorResponseThrows()
@ -72,15 +67,13 @@ final class TelegramTransportTest extends TestCase
return $response;
});
$transport = $this->createTransport('testChannel', $client);
$transport = $this->createTransport($client, 'testChannel');
$transport->send(new ChatMessage('testMessage'));
}
public function testSendWithOptions()
{
$channel = 'testChannel';
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
->method('getStatusCode')
@ -115,7 +108,7 @@ JSON;
;
$expectedBody = [
'chat_id' => $channel,
'chat_id' => 'testChannel',
'text' => 'testMessage',
'parse_mode' => 'MarkdownV2',
];
@ -126,7 +119,7 @@ JSON;
return $response;
});
$transport = $this->createTransport($channel, $client);
$transport = $this->createTransport($client, 'testChannel');
$sentMessage = $transport->send(new ChatMessage('testMessage'));
@ -182,7 +175,7 @@ JSON;
return $response;
});
$transport = $this->createTransport('defaultChannel', $client);
$transport = $this->createTransport($client, 'defaultChannel');
$messageOptions = new TelegramOptions();
$messageOptions->chatId($channelOverride);
@ -192,9 +185,4 @@ JSON;
$this->assertEquals(1, $sentMessage->getMessageId());
$this->assertEquals('telegram://host.test?channel=defaultChannel', $sentMessage->getTransport());
}
private function createTransport(?string $channel = 'testChannel', ?HttpClientInterface $client = null): TelegramTransport
{
return (new TelegramTransport('token', $channel, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
}

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"require-dev": {
"symfony/event-dispatcher": "^4.3|^5.0"

View File

@ -11,67 +11,42 @@
namespace Symfony\Component\Notifier\Bridge\Twilio\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class TwilioTransportFactoryTest extends TestCase
final class TwilioTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('twilio://accountSid:authToken@host.test?from=0611223344'));
$this->assertSame('twilio://host.test?from=0611223344', (string) $transport);
}
public function testCreateWithNoFromThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('twilio://accountSid:authToken@default'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('twilio://accountSid:authToken@default?from=0611223344')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://accountSid:authToken@default?from=0611223344')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://accountSid:authToken@default?from=0611223344'));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
// unsupported scheme and missing "from" option
$factory->create(Dsn::fromString('somethingElse://token@host'));
}
private function createFactory(): TwilioTransportFactory
/**
* @return TwilioTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new TwilioTransportFactory();
}
public function createProvider(): iterable
{
yield [
'twilio://host.test?from=0611223344',
'twilio://accountSid:authToken@host.test?from=0611223344',
];
}
public function supportsProvider(): iterable
{
yield [true, 'twilio://accountSid:authToken@default?from=0611223344'];
yield [false, 'somethingElse://accountSid:authToken@default?from=0611223344'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing option: from' => ['twilio://accountSid:authToken@default'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://accountSid:authToken@default?from=0611223344'];
yield ['somethingElse://accountSid:authToken@default']; // missing "from" option
}
}

View File

@ -11,41 +11,37 @@
namespace Symfony\Component\Notifier\Bridge\Twilio\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class TwilioTransportTest extends TestCase
final class TwilioTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return TwilioTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('twilio://host.test?from=sender', (string) $transport);
return new TwilioTransport('accountSid', 'authToken', 'from', $client ?: $this->createMock(HttpClientInterface::class));
}
public function testSupportsMessageInterface()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['twilio://api.twilio.com?from=from', $this->createTransport()];
}
public function testSendNonSmsMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new SmsMessage('0611223344', 'Hello!')];
}
private function createTransport(): TwilioTransport
public function unsupportedMessagesProvider(): iterable
{
return (new TwilioTransport('accountSid', 'authToken', 'sender', $this->createMock(HttpClientInterface::class)))->setHost('host.test');
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "~5.2.0"
"symfony/notifier": "~5.2.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Twilio\\": "" },

View File

@ -0,0 +1,109 @@
<?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\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
/**
* A test case to ease testing a notifier transport factory.
*
* @author Oskar Stark <oskarstark@googlemail.com>
*/
abstract class TransportFactoryTestCase extends TestCase
{
abstract public function createFactory(): TransportFactoryInterface;
/**
* @return iterable<array{0: bool, 1: string}>
*/
abstract public function supportsProvider(): iterable;
/**
* @return iterable<array{0: string, 1: string, 2: TransportInterface}>
*/
abstract public function createProvider(): iterable;
/**
* @return iterable<array{0: string, 1: string|null}>
*/
public function unsupportedSchemeProvider(): iterable
{
return [];
}
/**
* @return iterable<array{0: string, 1: string|null}>
*/
public function incompleteDsnProvider(): iterable
{
return [];
}
/**
* @dataProvider supportsProvider
*/
public function testSupports(bool $expected, string $dsn): void
{
$factory = $this->createFactory();
$this->assertSame($expected, $factory->supports(Dsn::fromString($dsn)));
}
/**
* @dataProvider createProvider
*/
public function testCreate(string $expected, string $dsn): void
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString($dsn));
$this->assertSame($expected, (string) $transport);
}
/**
* @dataProvider unsupportedSchemeProvider
*/
public function testUnsupportedSchemeException(string $dsn, string $message = null): void
{
$factory = $this->createFactory();
$dsn = Dsn::fromString($dsn);
$this->expectException(UnsupportedSchemeException::class);
if (null !== $message) {
$this->expectExceptionMessage($message);
}
$factory->create($dsn);
}
/**
* @dataProvider incompleteDsnProvider
*/
public function testIncompleteDsnException(string $dsn, string $message = null): void
{
$factory = $this->createFactory();
$dsn = Dsn::fromString($dsn);
$this->expectException(IncompleteDsnException::class);
if (null !== $message) {
$this->expectExceptionMessage($message);
}
$factory->create($dsn);
}
}

View File

@ -0,0 +1,123 @@
<?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\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* A test case to ease testing a Notifier transport.
*
* @author Oskar Stark <oskarstark@googlemail.com>
*/
abstract class TransportTestCase extends TestCase
{
protected const CUSTOM_HOST = 'host.test';
protected const CUSTOM_PORT = 42;
abstract public function createTransport(?HttpClientInterface $client = null): TransportInterface;
/**
* @return iterable<array{0: string, 1: TransportInterface}>
*/
abstract public function toStringProvider(): iterable;
/**
* @return iterable<array{0: MessageInterface, 1: TransportInterface}>
*/
abstract public function supportedMessagesProvider(): iterable;
/**
* @return iterable<array{0: MessageInterface, 1: TransportInterface}>
*/
abstract public function unsupportedMessagesProvider(): iterable;
/**
* @dataProvider toStringProvider
*/
public function testToString(string $expected, TransportInterface $transport): void
{
$this->assertSame($expected, (string) $transport);
}
/**
* @dataProvider supportedMessagesProvider
*/
public function testSupportedMessages(MessageInterface $message, ?TransportInterface $transport = null): void
{
if (null === $transport) {
$transport = $this->createTransport();
}
$this->assertTrue($transport->supports($message));
}
/**
* @dataProvider unsupportedMessagesProvider
*/
public function testUnsupportedMessages(MessageInterface $message, ?TransportInterface $transport = null): void
{
if (null === $transport) {
$transport = $this->createTransport();
}
$this->assertFalse($transport->supports($message));
}
/**
* @dataProvider unsupportedMessagesProvider
*/
public function testUnsupportedMessagesTrowLogicExceptionWhenSend(MessageInterface $message, ?TransportInterface $transport = null): void
{
if (null === $transport) {
$transport = $this->createTransport();
}
$this->expectException(LogicException::class);
$transport->send($message);
}
public function testCanSetCustomHost(): void
{
$transport = $this->createTransport();
$transport->setHost($customHost = self::CUSTOM_HOST);
$this->assertStringContainsString(sprintf('://%s', $customHost), (string) $transport);
}
public function testCanSetCustomPort(): void
{
$transport = $this->createTransport();
$transport->setPort($customPort = self::CUSTOM_PORT);
/*
* @see https://regex101.com/r/0xQKuY/2
*/
$this->assertMatchesRegularExpression(sprintf('/^.*\/\/.*\:%s.*$/', $customPort), (string) $transport);
}
public function testCanSetCustomHostAndPort(): void
{
$transport = $this->createTransport();
$transport->setHost($customHost = self::CUSTOM_HOST);
$transport->setPort($customPort = self::CUSTOM_PORT);
$this->assertStringContainsString(sprintf('://%s:%s', $customHost, $customPort), (string) $transport);
}
}