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:
commit
3c753e6eff
1
.github/composer-config.json
vendored
1
.github/composer-config.json
vendored
@ -4,6 +4,7 @@
|
|||||||
"preferred-install": {
|
"preferred-install": {
|
||||||
"symfony/form": "source",
|
"symfony/form": "source",
|
||||||
"symfony/http-kernel": "source",
|
"symfony/http-kernel": "source",
|
||||||
|
"symfony/notifier": "source",
|
||||||
"symfony/validator": "source",
|
"symfony/validator": "source",
|
||||||
"*": "dist"
|
"*": "dist"
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ final class Intl
|
|||||||
*/
|
*/
|
||||||
public static function getIcuStubVersion(): string
|
public static function getIcuStubVersion(): string
|
||||||
{
|
{
|
||||||
return '68.1';
|
return '68.2';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -731,8 +731,8 @@
|
|||||||
"ALL": 8,
|
"ALL": 8,
|
||||||
"DZD": 12,
|
"DZD": 12,
|
||||||
"ADP": 20,
|
"ADP": 20,
|
||||||
"AON": 24,
|
|
||||||
"AOK": 24,
|
"AOK": 24,
|
||||||
|
"AON": 24,
|
||||||
"AZM": 31,
|
"AZM": 31,
|
||||||
"ARA": 32,
|
"ARA": 32,
|
||||||
"ARP": 32,
|
"ARP": 32,
|
||||||
@ -751,16 +751,16 @@
|
|||||||
"BOP": 68,
|
"BOP": 68,
|
||||||
"BAD": 70,
|
"BAD": 70,
|
||||||
"BWP": 72,
|
"BWP": 72,
|
||||||
"BRN": 76,
|
|
||||||
"BRE": 76,
|
|
||||||
"BRC": 76,
|
|
||||||
"BRB": 76,
|
"BRB": 76,
|
||||||
|
"BRC": 76,
|
||||||
|
"BRE": 76,
|
||||||
|
"BRN": 76,
|
||||||
"BZD": 84,
|
"BZD": 84,
|
||||||
"SBD": 90,
|
"SBD": 90,
|
||||||
"BND": 96,
|
"BND": 96,
|
||||||
"BGL": 100,
|
"BGL": 100,
|
||||||
"MMK": 104,
|
|
||||||
"BUK": 104,
|
"BUK": 104,
|
||||||
|
"MMK": 104,
|
||||||
"BIF": 108,
|
"BIF": 108,
|
||||||
"BYB": 112,
|
"BYB": 112,
|
||||||
"KHR": 116,
|
"KHR": 116,
|
||||||
@ -772,11 +772,11 @@
|
|||||||
"CNY": 156,
|
"CNY": 156,
|
||||||
"COP": 170,
|
"COP": 170,
|
||||||
"KMF": 174,
|
"KMF": 174,
|
||||||
"ZRZ": 180,
|
|
||||||
"ZRN": 180,
|
"ZRN": 180,
|
||||||
|
"ZRZ": 180,
|
||||||
"CRC": 188,
|
"CRC": 188,
|
||||||
"HRK": 191,
|
|
||||||
"HRD": 191,
|
"HRD": 191,
|
||||||
|
"HRK": 191,
|
||||||
"CUP": 192,
|
"CUP": 192,
|
||||||
"CYP": 196,
|
"CYP": 196,
|
||||||
"CSK": 200,
|
"CSK": 200,
|
||||||
@ -802,8 +802,8 @@
|
|||||||
"GIP": 292,
|
"GIP": 292,
|
||||||
"GRD": 300,
|
"GRD": 300,
|
||||||
"GTQ": 320,
|
"GTQ": 320,
|
||||||
"GNS": 324,
|
|
||||||
"GNF": 324,
|
"GNF": 324,
|
||||||
|
"GNS": 324,
|
||||||
"GYD": 328,
|
"GYD": 328,
|
||||||
"HTG": 332,
|
"HTG": 332,
|
||||||
"HNL": 340,
|
"HNL": 340,
|
||||||
@ -832,8 +832,8 @@
|
|||||||
"LAK": 418,
|
"LAK": 418,
|
||||||
"LBP": 422,
|
"LBP": 422,
|
||||||
"LSL": 426,
|
"LSL": 426,
|
||||||
"LVR": 428,
|
|
||||||
"LVL": 428,
|
"LVL": 428,
|
||||||
|
"LVR": 428,
|
||||||
"LRD": 430,
|
"LRD": 430,
|
||||||
"LYD": 434,
|
"LYD": 434,
|
||||||
"LTL": 440,
|
"LTL": 440,
|
||||||
@ -849,8 +849,8 @@
|
|||||||
"MTP": 470,
|
"MTP": 470,
|
||||||
"MRO": 478,
|
"MRO": 478,
|
||||||
"MUR": 480,
|
"MUR": 480,
|
||||||
"MXP": 484,
|
|
||||||
"MXN": 484,
|
"MXN": 484,
|
||||||
|
"MXP": 484,
|
||||||
"MNT": 496,
|
"MNT": 496,
|
||||||
"MDL": 498,
|
"MDL": 498,
|
||||||
"MAD": 504,
|
"MAD": 504,
|
||||||
@ -873,13 +873,13 @@
|
|||||||
"PGK": 598,
|
"PGK": 598,
|
||||||
"PYG": 600,
|
"PYG": 600,
|
||||||
"PEI": 604,
|
"PEI": 604,
|
||||||
"PES": 604,
|
|
||||||
"PEN": 604,
|
"PEN": 604,
|
||||||
|
"PES": 604,
|
||||||
"PHP": 608,
|
"PHP": 608,
|
||||||
"PLZ": 616,
|
"PLZ": 616,
|
||||||
"PTE": 620,
|
"PTE": 620,
|
||||||
"GWP": 624,
|
|
||||||
"GWE": 624,
|
"GWE": 624,
|
||||||
|
"GWP": 624,
|
||||||
"TPE": 626,
|
"TPE": 626,
|
||||||
"QAR": 634,
|
"QAR": 634,
|
||||||
"ROL": 642,
|
"ROL": 642,
|
||||||
@ -896,8 +896,8 @@
|
|||||||
"SIT": 705,
|
"SIT": 705,
|
||||||
"SOS": 706,
|
"SOS": 706,
|
||||||
"ZAR": 710,
|
"ZAR": 710,
|
||||||
"ZWD": 716,
|
|
||||||
"RHD": 716,
|
"RHD": 716,
|
||||||
|
"ZWD": 716,
|
||||||
"YDD": 720,
|
"YDD": 720,
|
||||||
"ESP": 724,
|
"ESP": 724,
|
||||||
"SSP": 728,
|
"SSP": 728,
|
||||||
@ -916,8 +916,8 @@
|
|||||||
"TND": 788,
|
"TND": 788,
|
||||||
"TRL": 792,
|
"TRL": 792,
|
||||||
"TMM": 795,
|
"TMM": 795,
|
||||||
"UGX": 800,
|
|
||||||
"UGS": 800,
|
"UGS": 800,
|
||||||
|
"UGX": 800,
|
||||||
"UAK": 804,
|
"UAK": 804,
|
||||||
"MKD": 807,
|
"MKD": 807,
|
||||||
"RUR": 810,
|
"RUR": 810,
|
||||||
@ -932,10 +932,10 @@
|
|||||||
"VEB": 862,
|
"VEB": 862,
|
||||||
"WST": 882,
|
"WST": 882,
|
||||||
"YER": 886,
|
"YER": 886,
|
||||||
"YUN": 890,
|
|
||||||
"YUD": 890,
|
"YUD": 890,
|
||||||
"YUM": 891,
|
"YUN": 890,
|
||||||
"CSD": 891,
|
"CSD": 891,
|
||||||
|
"YUM": 891,
|
||||||
"ZMK": 894,
|
"ZMK": 894,
|
||||||
"TWD": 901,
|
"TWD": 901,
|
||||||
"UYW": 927,
|
"UYW": 927,
|
||||||
@ -1010,8 +1010,8 @@
|
|||||||
"ADP"
|
"ADP"
|
||||||
],
|
],
|
||||||
"24": [
|
"24": [
|
||||||
"AON",
|
"AOK",
|
||||||
"AOK"
|
"AON"
|
||||||
],
|
],
|
||||||
"31": [
|
"31": [
|
||||||
"AZM"
|
"AZM"
|
||||||
@ -1062,10 +1062,10 @@
|
|||||||
"BWP"
|
"BWP"
|
||||||
],
|
],
|
||||||
"76": [
|
"76": [
|
||||||
"BRN",
|
"BRB",
|
||||||
"BRE",
|
|
||||||
"BRC",
|
"BRC",
|
||||||
"BRB"
|
"BRE",
|
||||||
|
"BRN"
|
||||||
],
|
],
|
||||||
"84": [
|
"84": [
|
||||||
"BZD"
|
"BZD"
|
||||||
@ -1080,8 +1080,8 @@
|
|||||||
"BGL"
|
"BGL"
|
||||||
],
|
],
|
||||||
"104": [
|
"104": [
|
||||||
"MMK",
|
"BUK",
|
||||||
"BUK"
|
"MMK"
|
||||||
],
|
],
|
||||||
"108": [
|
"108": [
|
||||||
"BIF"
|
"BIF"
|
||||||
@ -1117,15 +1117,15 @@
|
|||||||
"KMF"
|
"KMF"
|
||||||
],
|
],
|
||||||
"180": [
|
"180": [
|
||||||
"ZRZ",
|
"ZRN",
|
||||||
"ZRN"
|
"ZRZ"
|
||||||
],
|
],
|
||||||
"188": [
|
"188": [
|
||||||
"CRC"
|
"CRC"
|
||||||
],
|
],
|
||||||
"191": [
|
"191": [
|
||||||
"HRK",
|
"HRD",
|
||||||
"HRD"
|
"HRK"
|
||||||
],
|
],
|
||||||
"192": [
|
"192": [
|
||||||
"CUP"
|
"CUP"
|
||||||
@ -1203,8 +1203,8 @@
|
|||||||
"GTQ"
|
"GTQ"
|
||||||
],
|
],
|
||||||
"324": [
|
"324": [
|
||||||
"GNS",
|
"GNF",
|
||||||
"GNF"
|
"GNS"
|
||||||
],
|
],
|
||||||
"328": [
|
"328": [
|
||||||
"GYD"
|
"GYD"
|
||||||
@ -1285,8 +1285,8 @@
|
|||||||
"LSL"
|
"LSL"
|
||||||
],
|
],
|
||||||
"428": [
|
"428": [
|
||||||
"LVR",
|
"LVL",
|
||||||
"LVL"
|
"LVR"
|
||||||
],
|
],
|
||||||
"430": [
|
"430": [
|
||||||
"LRD"
|
"LRD"
|
||||||
@ -1330,8 +1330,8 @@
|
|||||||
"MUR"
|
"MUR"
|
||||||
],
|
],
|
||||||
"484": [
|
"484": [
|
||||||
"MXP",
|
"MXN",
|
||||||
"MXN"
|
"MXP"
|
||||||
],
|
],
|
||||||
"496": [
|
"496": [
|
||||||
"MNT"
|
"MNT"
|
||||||
@ -1394,8 +1394,8 @@
|
|||||||
],
|
],
|
||||||
"604": [
|
"604": [
|
||||||
"PEI",
|
"PEI",
|
||||||
"PES",
|
"PEN",
|
||||||
"PEN"
|
"PES"
|
||||||
],
|
],
|
||||||
"608": [
|
"608": [
|
||||||
"PHP"
|
"PHP"
|
||||||
@ -1407,8 +1407,8 @@
|
|||||||
"PTE"
|
"PTE"
|
||||||
],
|
],
|
||||||
"624": [
|
"624": [
|
||||||
"GWP",
|
"GWE",
|
||||||
"GWE"
|
"GWP"
|
||||||
],
|
],
|
||||||
"626": [
|
"626": [
|
||||||
"TPE"
|
"TPE"
|
||||||
@ -1459,8 +1459,8 @@
|
|||||||
"ZAR"
|
"ZAR"
|
||||||
],
|
],
|
||||||
"716": [
|
"716": [
|
||||||
"ZWD",
|
"RHD",
|
||||||
"RHD"
|
"ZWD"
|
||||||
],
|
],
|
||||||
"720": [
|
"720": [
|
||||||
"YDD"
|
"YDD"
|
||||||
@ -1515,8 +1515,8 @@
|
|||||||
"TMM"
|
"TMM"
|
||||||
],
|
],
|
||||||
"800": [
|
"800": [
|
||||||
"UGX",
|
"UGS",
|
||||||
"UGS"
|
"UGX"
|
||||||
],
|
],
|
||||||
"804": [
|
"804": [
|
||||||
"UAK"
|
"UAK"
|
||||||
@ -1557,12 +1557,12 @@
|
|||||||
"YER"
|
"YER"
|
||||||
],
|
],
|
||||||
"890": [
|
"890": [
|
||||||
"YUN",
|
"YUD",
|
||||||
"YUD"
|
"YUN"
|
||||||
],
|
],
|
||||||
"891": [
|
"891": [
|
||||||
"YUM",
|
"CSD",
|
||||||
"CSD"
|
"YUM"
|
||||||
],
|
],
|
||||||
"894": [
|
"894": [
|
||||||
"ZMK"
|
"ZMK"
|
||||||
|
@ -2,6 +2,6 @@ Git information
|
|||||||
===============
|
===============
|
||||||
|
|
||||||
URL: https://github.com/unicode-org/icu.git
|
URL: https://github.com/unicode-org/icu.git
|
||||||
Revision: 5d81f6f9a0edc47892a1d2af7024f835b47deb82
|
Revision: 84e1f26ea77152936e70d53178a816dbfbf69989
|
||||||
Author: Jeff Genovy
|
Author: Peter Edberg
|
||||||
Date: 2020-10-27T10:20:57-07:00
|
Date: 2020-12-13T21:28:54-08:00
|
||||||
|
@ -1 +1 @@
|
|||||||
68.1
|
68.2
|
||||||
|
@ -11,50 +11,39 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Firebase\FirebaseTransportFactory;
|
use Symfony\Component\Notifier\Bridge\Firebase\FirebaseTransportFactory;
|
||||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oskar Stark <oskarstark@googlemail.com>
|
* @author Oskar Stark <oskarstark@googlemail.com>
|
||||||
*/
|
*/
|
||||||
final class FirebaseTransportFactoryTest extends TestCase
|
final class FirebaseTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return FirebaseTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$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 new FirebaseTransportFactory();
|
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'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,44 +11,40 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Firebase\FirebaseTransport;
|
use Symfony\Component\Notifier\Bridge\Firebase\FirebaseTransport;
|
||||||
use Symfony\Component\Notifier\Exception\LogicException;
|
|
||||||
use Symfony\Component\Notifier\Message\ChatMessage;
|
use Symfony\Component\Notifier\Message\ChatMessage;
|
||||||
use Symfony\Component\Notifier\Message\MessageInterface;
|
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\HttpClientInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oskar Stark <oskarstark@googlemail.com>
|
* @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();
|
return new FirebaseTransport('username:password', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('firebase://host.test', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsMessageInterface()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['firebase://fcm.googleapis.com/fcm/send', $this->createTransport()];
|
||||||
|
|
||||||
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
|
|
||||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonSmsMessageThrowsLogicException()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new ChatMessage('Hello!')];
|
||||||
|
|
||||||
$this->expectException(LogicException::class);
|
|
||||||
|
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"symfony/http-client": "^4.3|^5.0",
|
"symfony/http-client": "^4.3|^5.0",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Firebase\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Firebase\\": "" },
|
||||||
|
@ -11,67 +11,42 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\FreeMobile\Tests;
|
namespace Symfony\Component\Notifier\Bridge\FreeMobile\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransportFactory;
|
use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransportFactory;
|
||||||
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
|
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
|
||||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
|
||||||
|
|
||||||
final class FreeMobileTransportFactoryTest extends TestCase
|
final class FreeMobileTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return FreeMobileTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$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 new FreeMobileTransportFactory();
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,65 +11,39 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\FreeMobile\Tests;
|
namespace Symfony\Component\Notifier\Bridge\FreeMobile\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransport;
|
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\MessageInterface;
|
||||||
use Symfony\Component\Notifier\Message\SmsMessage;
|
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\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);
|
return new FreeMobileTransport('login', 'pass', '0611223344', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame($expected, $transport->supports($message));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function toStringProvider(): iterable
|
||||||
* @return iterable<array{0: bool, 1: string, 2: MessageInterface}>
|
|
||||||
*/
|
|
||||||
public function supportsProvider(): iterable
|
|
||||||
{
|
{
|
||||||
yield [true, '0611223344', new SmsMessage('0611223344', 'Hello!')];
|
yield ['freemobile://smsapi.free-mobile.fr/sendmsg?phone=0611223344', $this->createTransport()];
|
||||||
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!')];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonSmsMessageThrowsLogicException()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport('0611223344');
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
yield [new SmsMessage('+33611223344', 'Hello!')];
|
||||||
$this->expectException(LogicException::class);
|
|
||||||
|
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendSmsMessageButInvalidPhoneThrowsLogicException()
|
public function unsupportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport('0611223344');
|
yield [new SmsMessage('0699887766', 'Hello!')]; // because this phone number is not configured on the transport!
|
||||||
|
yield [new ChatMessage('Hello!')];
|
||||||
$this->expectException(LogicException::class);
|
yield [$this->createMock(MessageInterface::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');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"symfony/http-client": "^4.3|^5.1",
|
"symfony/http-client": "^4.3|^5.1",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FreeMobile\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FreeMobile\\": "" },
|
||||||
|
@ -11,97 +11,61 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Mattermost\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Mattermost\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransportFactory;
|
use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransportFactory;
|
||||||
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
|
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
|
||||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oskar Stark <oskarstark@googlemail.com>
|
* @author Oskar Stark <oskarstark@googlemail.com>
|
||||||
*/
|
*/
|
||||||
final class MattermostTransportFactoryTest extends TestCase
|
final class MattermostTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return MattermostTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$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 new MattermostTransportFactory();
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,44 +11,40 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Mattermost\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Mattermost\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransport;
|
use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransport;
|
||||||
use Symfony\Component\Notifier\Exception\LogicException;
|
|
||||||
use Symfony\Component\Notifier\Message\ChatMessage;
|
use Symfony\Component\Notifier\Message\ChatMessage;
|
||||||
use Symfony\Component\Notifier\Message\MessageInterface;
|
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;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oskar Stark <oskarstark@googlemail.com>
|
* @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();
|
return (new MattermostTransport('testAccessToken', 'testChannel', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
|
||||||
|
|
||||||
$this->assertSame('mattermost://host.test?channel=testChannel', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsChatMessage()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['mattermost://host.test?channel=testChannel', $this->createTransport()];
|
||||||
|
|
||||||
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
|
|
||||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonChatMessageThrowsLogicException()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new ChatMessage('Hello!')];
|
||||||
|
|
||||||
$this->expectException(LogicException::class);
|
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"symfony/http-client": "^4.3|^5.0",
|
"symfony/http-client": "^4.3|^5.0",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mattermost\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mattermost\\": "" },
|
||||||
|
@ -11,67 +11,42 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Nexmo\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Nexmo\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Nexmo\NexmoTransportFactory;
|
use Symfony\Component\Notifier\Bridge\Nexmo\NexmoTransportFactory;
|
||||||
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
|
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
|
||||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
|
||||||
|
|
||||||
final class NexmoTransportFactoryTest extends TestCase
|
final class NexmoTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return NexmoTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$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 new NexmoTransportFactory();
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,41 +11,37 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Nexmo\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Nexmo\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Nexmo\NexmoTransport;
|
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\MessageInterface;
|
||||||
use Symfony\Component\Notifier\Message\SmsMessage;
|
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\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();
|
return new NexmoTransport('apiKey', 'apiSecret', 'sender', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('nexmo://host.test?from=sender', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsMessageInterface()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['nexmo://rest.nexmo.com?from=sender', $this->createTransport()];
|
||||||
|
|
||||||
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
|
|
||||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonSmsMessageThrowsLogicException()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
|
||||||
$this->expectException(LogicException::class);
|
|
||||||
|
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"symfony/http-client": "^4.3|^5.0",
|
"symfony/http-client": "^4.3|^5.0",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Nexmo\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Nexmo\\": "" },
|
||||||
|
@ -11,76 +11,44 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\OvhCloud\Tests;
|
namespace Symfony\Component\Notifier\Bridge\OvhCloud\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransportFactory;
|
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransportFactory;
|
||||||
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
|
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
|
||||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
|
||||||
|
|
||||||
final class OvhCloudTransportFactoryTest extends TestCase
|
final class OvhCloudTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return OvhCloudTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$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 new OvhCloudTransportFactory();
|
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'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,41 +11,37 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\OvhCloud\Tests;
|
namespace Symfony\Component\Notifier\Bridge\OvhCloud\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransport;
|
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\MessageInterface;
|
||||||
use Symfony\Component\Notifier\Message\SmsMessage;
|
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\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();
|
return new OvhCloudTransport('applicationKey', 'applicationSecret', 'consumerKey', 'serviceName', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsMessageInterface()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName', $this->createTransport()];
|
||||||
|
|
||||||
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
|
|
||||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonSmsMessageThrowsLogicException()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
|
||||||
$this->expectException(LogicException::class);
|
|
||||||
|
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"symfony/http-client": "^4.3|^5.0",
|
"symfony/http-client": "^4.3|^5.0",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" },
|
||||||
|
@ -11,60 +11,44 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\RocketChat\Tests;
|
namespace Symfony\Component\Notifier\Bridge\RocketChat\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransportFactory;
|
use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransportFactory;
|
||||||
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
|
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
|
||||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oskar Stark <oskarstark@googlemail.com>
|
* @author Oskar Stark <oskarstark@googlemail.com>
|
||||||
*/
|
*/
|
||||||
final class RocketChatTransportFactoryTest extends TestCase
|
final class RocketChatTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return RocketChatTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$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 new RocketChatTransportFactory();
|
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'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,50 +11,41 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\RocketChat\Tests;
|
namespace Symfony\Component\Notifier\Bridge\RocketChat\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransport;
|
use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransport;
|
||||||
use Symfony\Component\Notifier\Exception\LogicException;
|
|
||||||
use Symfony\Component\Notifier\Message\ChatMessage;
|
use Symfony\Component\Notifier\Message\ChatMessage;
|
||||||
use Symfony\Component\Notifier\Message\MessageInterface;
|
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\HttpClientInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oskar Stark <oskarstark@googlemail.com>
|
* @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();
|
return new RocketChatTransport('testAccessToken', $channel, $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('rocketchat://host.test?channel=testChannel', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testToStringContainsNoChannelBecauseItsOptional()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport(null);
|
yield ['rocketchat://rocketchat.com', $this->createTransport()];
|
||||||
|
yield ['rocketchat://rocketchat.com?channel=testChannel', $this->createTransport(null, 'testChannel')];
|
||||||
$this->assertSame('rocketchat://host.test', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsChatMessage()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new ChatMessage('Hello!')];
|
||||||
|
|
||||||
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
|
|
||||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonChatMessageThrowsLogicException()
|
public function unsupportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
yield [$this->createMock(MessageInterface::class)];
|
||||||
$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');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"symfony/http-client": "^4.3|^5.0",
|
"symfony/http-client": "^4.3|^5.0",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\RocketChat\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\RocketChat\\": "" },
|
||||||
|
@ -11,67 +11,42 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Sinch\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Sinch\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Sinch\SinchTransportFactory;
|
use Symfony\Component\Notifier\Bridge\Sinch\SinchTransportFactory;
|
||||||
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
|
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
|
||||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
|
||||||
|
|
||||||
final class SinchTransportFactoryTest extends TestCase
|
final class SinchTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return SinchTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$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 new SinchTransportFactory();
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,41 +11,37 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Sinch\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Sinch\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Sinch\SinchTransport;
|
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\MessageInterface;
|
||||||
use Symfony\Component\Notifier\Message\SmsMessage;
|
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\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();
|
return new SinchTransport('accountSid', 'authToken', 'sender', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('sinch://host.test?from=sender', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsMessageInterface()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['sinch://sms.api.sinch.com?from=sender', $this->createTransport()];
|
||||||
|
|
||||||
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
|
|
||||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonSmsMessageThrowsLogicException()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
|
||||||
$this->expectException(LogicException::class);
|
|
||||||
|
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"symfony/http-client": "^4.3|^5.0",
|
"symfony/http-client": "^4.3|^5.0",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sinch\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sinch\\": "" },
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"symfony/deprecation-contracts": "^2.1",
|
"symfony/deprecation-contracts": "^2.1",
|
||||||
"symfony/http-client": "^4.3|^5.0",
|
"symfony/http-client": "^4.3|^5.0",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/event-dispatcher": "^4.3|^5.0"
|
"symfony/event-dispatcher": "^4.3|^5.0"
|
||||||
|
@ -11,66 +11,42 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Telegram\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Telegram\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
|
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
|
||||||
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
|
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
|
||||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
|
||||||
|
|
||||||
final class TelegramTransportFactoryTest extends TestCase
|
final class TelegramTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return TelegramTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$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 new TelegramTransportFactory();
|
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'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,48 +11,43 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Telegram\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Telegram\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\HttpClient\MockHttpClient;
|
use Symfony\Component\HttpClient\MockHttpClient;
|
||||||
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
|
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
|
||||||
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransport;
|
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransport;
|
||||||
use Symfony\Component\Notifier\Exception\LogicException;
|
|
||||||
use Symfony\Component\Notifier\Exception\TransportException;
|
use Symfony\Component\Notifier\Exception\TransportException;
|
||||||
use Symfony\Component\Notifier\Message\ChatMessage;
|
use Symfony\Component\Notifier\Message\ChatMessage;
|
||||||
use Symfony\Component\Notifier\Message\MessageInterface;
|
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\HttpClientInterface;
|
||||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
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();
|
return new TelegramTransport('token', $channel, $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('telegram://host.test?channel=testChannel', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testToStringContainsNoChannelBecauseItsOptional()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport(null);
|
yield ['telegram://api.telegram.org', $this->createTransport()];
|
||||||
|
yield ['telegram://api.telegram.org?channel=testChannel', $this->createTransport(null, 'testChannel')];
|
||||||
$this->assertSame('telegram://host.test', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsChatMessage()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new ChatMessage('Hello!')];
|
||||||
|
|
||||||
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
|
|
||||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonChatMessageThrowsLogicException()
|
public function unsupportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
yield [$this->createMock(MessageInterface::class)];
|
||||||
$this->expectException(LogicException::class);
|
|
||||||
|
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendWithErrorResponseThrows()
|
public function testSendWithErrorResponseThrows()
|
||||||
@ -72,15 +67,13 @@ final class TelegramTransportTest extends TestCase
|
|||||||
return $response;
|
return $response;
|
||||||
});
|
});
|
||||||
|
|
||||||
$transport = $this->createTransport('testChannel', $client);
|
$transport = $this->createTransport($client, 'testChannel');
|
||||||
|
|
||||||
$transport->send(new ChatMessage('testMessage'));
|
$transport->send(new ChatMessage('testMessage'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendWithOptions()
|
public function testSendWithOptions()
|
||||||
{
|
{
|
||||||
$channel = 'testChannel';
|
|
||||||
|
|
||||||
$response = $this->createMock(ResponseInterface::class);
|
$response = $this->createMock(ResponseInterface::class);
|
||||||
$response->expects($this->exactly(2))
|
$response->expects($this->exactly(2))
|
||||||
->method('getStatusCode')
|
->method('getStatusCode')
|
||||||
@ -115,7 +108,7 @@ JSON;
|
|||||||
;
|
;
|
||||||
|
|
||||||
$expectedBody = [
|
$expectedBody = [
|
||||||
'chat_id' => $channel,
|
'chat_id' => 'testChannel',
|
||||||
'text' => 'testMessage',
|
'text' => 'testMessage',
|
||||||
'parse_mode' => 'MarkdownV2',
|
'parse_mode' => 'MarkdownV2',
|
||||||
];
|
];
|
||||||
@ -126,7 +119,7 @@ JSON;
|
|||||||
return $response;
|
return $response;
|
||||||
});
|
});
|
||||||
|
|
||||||
$transport = $this->createTransport($channel, $client);
|
$transport = $this->createTransport($client, 'testChannel');
|
||||||
|
|
||||||
$sentMessage = $transport->send(new ChatMessage('testMessage'));
|
$sentMessage = $transport->send(new ChatMessage('testMessage'));
|
||||||
|
|
||||||
@ -182,7 +175,7 @@ JSON;
|
|||||||
return $response;
|
return $response;
|
||||||
});
|
});
|
||||||
|
|
||||||
$transport = $this->createTransport('defaultChannel', $client);
|
$transport = $this->createTransport($client, 'defaultChannel');
|
||||||
|
|
||||||
$messageOptions = new TelegramOptions();
|
$messageOptions = new TelegramOptions();
|
||||||
$messageOptions->chatId($channelOverride);
|
$messageOptions->chatId($channelOverride);
|
||||||
@ -192,9 +185,4 @@ JSON;
|
|||||||
$this->assertEquals(1, $sentMessage->getMessageId());
|
$this->assertEquals(1, $sentMessage->getMessageId());
|
||||||
$this->assertEquals('telegram://host.test?channel=defaultChannel', $sentMessage->getTransport());
|
$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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"symfony/http-client": "^4.3|^5.0",
|
"symfony/http-client": "^4.3|^5.0",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/event-dispatcher": "^4.3|^5.0"
|
"symfony/event-dispatcher": "^4.3|^5.0"
|
||||||
|
@ -11,67 +11,42 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Twilio\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Twilio\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
|
use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
|
||||||
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
|
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
|
||||||
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
|
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
|
||||||
use Symfony\Component\Notifier\Transport\Dsn;
|
|
||||||
|
|
||||||
final class TwilioTransportFactoryTest extends TestCase
|
final class TwilioTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return TwilioTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$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 new TwilioTransportFactory();
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,41 +11,37 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Twilio\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Twilio\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransport;
|
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\MessageInterface;
|
||||||
use Symfony\Component\Notifier\Message\SmsMessage;
|
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\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();
|
return new TwilioTransport('accountSid', 'authToken', 'from', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('twilio://host.test?from=sender', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsMessageInterface()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['twilio://api.twilio.com?from=from', $this->createTransport()];
|
||||||
|
|
||||||
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
|
|
||||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonSmsMessageThrowsLogicException()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
|
||||||
$this->expectException(LogicException::class);
|
|
||||||
|
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.5",
|
"php": ">=7.2.5",
|
||||||
"symfony/http-client": "^4.3|^5.0",
|
"symfony/http-client": "^4.3|^5.0",
|
||||||
"symfony/notifier": "~5.2.0"
|
"symfony/notifier": "~5.2.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Twilio\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Twilio\\": "" },
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
123
src/Symfony/Component/Notifier/Tests/TransportTestCase.php
Normal file
123
src/Symfony/Component/Notifier/Tests/TransportTestCase.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user