[Notifier] [DX] Abstract test cases
This commit is contained in:
parent
74b132fca2
commit
79379b71f4
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 testSendNonSmsMessageThrowsException()
|
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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"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,52 +11,38 @@
|
||||||
|
|
||||||
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()
|
/**
|
||||||
|
* @return FreeMobileTransport
|
||||||
|
*/
|
||||||
|
public function createTransport(?HttpClientInterface $client = null): TransportInterface
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
return new FreeMobileTransport('login', 'pass', '0611223344', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('freemobile://host.test?phone=0611223344', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsMessageInterface()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['freemobile://smsapi.free-mobile.fr/sendmsg?phone=0611223344', $this->createTransport()];
|
||||||
|
|
||||||
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
|
|
||||||
|
|
||||||
$this->assertFalse($transport->supports(new SmsMessage('0699887766', 'Hello!'))); // because this phone number is not configured on the transport!
|
|
||||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendNonSmsMessageThrowsException()
|
public function supportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
|
||||||
$this->expectException(LogicException::class);
|
|
||||||
|
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendSmsMessageButInvalidPhoneThrowsException()
|
public function unsupportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
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(): FreeMobileTransport
|
|
||||||
{
|
|
||||||
return (new FreeMobileTransport('login', 'pass', '0611223344', $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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FreeMobile\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FreeMobile\\": "" },
|
||||||
|
|
|
@ -11,96 +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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"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 testSendNonSmsMessageThrowsException()
|
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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"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 testSendNonSmsMessageThrowsException()
|
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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" },
|
||||||
|
|
|
@ -11,59 +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,43 +11,40 @@
|
||||||
|
|
||||||
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): TransportInterface
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
return new RocketChatTransport('testAccessToken', 'testChannel', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('rocketchat://host.test?channel=testChannel', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsChatMessage()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['rocketchat://rocketchat.com?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(): RocketChatTransport
|
public function unsupportedMessagesProvider(): iterable
|
||||||
{
|
{
|
||||||
return (new RocketChatTransport('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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"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 testSendNonSmsMessageThrowsException()
|
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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sinch\\": "" },
|
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sinch\\": "" },
|
||||||
|
|
|
@ -11,67 +11,42 @@
|
||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Slack\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Slack\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
|
use Symfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
|
||||||
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 SlackTransportFactoryTest extends TestCase
|
final class SlackTransportFactoryTest extends TransportFactoryTestCase
|
||||||
{
|
{
|
||||||
public function testCreateWithDsn()
|
/**
|
||||||
{
|
* @return SlackTransportFactory
|
||||||
$factory = $this->createFactory();
|
*/
|
||||||
|
public function createFactory(): TransportFactoryInterface
|
||||||
$transport = $factory->create(Dsn::fromString('slack://host.test/testPath'));
|
|
||||||
|
|
||||||
$this->assertSame('slack://host.test/testPath', (string) $transport);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCreateWithMissingOptionIdThrowsIncompleteDsnException()
|
|
||||||
{
|
|
||||||
$factory = $this->createFactory();
|
|
||||||
|
|
||||||
$this->expectException(IncompleteDsnException::class);
|
|
||||||
|
|
||||||
$factory->create(Dsn::fromString('slack://host'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSupportsReturnsTrueWithSupportedScheme()
|
|
||||||
{
|
|
||||||
$factory = $this->createFactory();
|
|
||||||
|
|
||||||
$this->assertTrue($factory->supports(Dsn::fromString('slack://host/path')));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSupportsReturnsFalseWithUnsupportedScheme()
|
|
||||||
{
|
|
||||||
$factory = $this->createFactory();
|
|
||||||
|
|
||||||
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host/path')));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
|
|
||||||
{
|
|
||||||
$factory = $this->createFactory();
|
|
||||||
|
|
||||||
$this->expectException(UnsupportedSchemeException::class);
|
|
||||||
|
|
||||||
$factory->create(Dsn::fromString('somethingElse://host/path'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
|
|
||||||
{
|
|
||||||
$factory = $this->createFactory();
|
|
||||||
|
|
||||||
$this->expectException(UnsupportedSchemeException::class);
|
|
||||||
|
|
||||||
// unsupported scheme and missing "id" option
|
|
||||||
$factory->create(Dsn::fromString('somethingElse://host'));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createFactory(): SlackTransportFactory
|
|
||||||
{
|
{
|
||||||
return new SlackTransportFactory();
|
return new SlackTransportFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createProvider(): iterable
|
||||||
|
{
|
||||||
|
yield [
|
||||||
|
'slack://host.test/id',
|
||||||
|
'slack://host.test/id',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsProvider(): iterable
|
||||||
|
{
|
||||||
|
yield [true, 'slack://host.test/id'];
|
||||||
|
yield [false, 'somethingElse://host.test/id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function incompleteDsnProvider(): iterable
|
||||||
|
{
|
||||||
|
yield 'missing path' => ['slack://host.test'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unsupportedSchemeProvider(): iterable
|
||||||
|
{
|
||||||
|
yield ['somethingElse://host.test/id'];
|
||||||
|
yield ['somethingElse://host.test']; // missing "id"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
namespace Symfony\Component\Notifier\Bridge\Slack\Tests;
|
namespace Symfony\Component\Notifier\Bridge\Slack\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\HttpClient\MockHttpClient;
|
use Symfony\Component\HttpClient\MockHttpClient;
|
||||||
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
|
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
|
||||||
use Symfony\Component\Notifier\Bridge\Slack\SlackTransport;
|
use Symfony\Component\Notifier\Bridge\Slack\SlackTransport;
|
||||||
|
@ -20,34 +19,37 @@ 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\MessageOptionsInterface;
|
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
|
||||||
|
use Symfony\Component\Notifier\Message\SmsMessage;
|
||||||
use Symfony\Component\Notifier\Notification\Notification;
|
use Symfony\Component\Notifier\Notification\Notification;
|
||||||
|
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 SlackTransportTest extends TestCase
|
final class SlackTransportTest extends TransportTestCase
|
||||||
{
|
{
|
||||||
public function testToStringContainsProperties()
|
/**
|
||||||
|
* @return SlackTransport
|
||||||
|
*/
|
||||||
|
public function createTransport(?HttpClientInterface $client = null): TransportInterface
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
return new SlackTransport('id', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('slack://host.test/testPath', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsChatMessage()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['slack://hooks.slack.com/id', $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);
|
public function unsupportedMessagesProvider(): iterable
|
||||||
|
{
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
yield [$this->createMock(MessageInterface::class)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendWithEmptyArrayResponseThrows()
|
public function testSendWithEmptyArrayResponseThrows()
|
||||||
|
@ -196,9 +198,4 @@ final class SlackTransportTest extends TestCase
|
||||||
|
|
||||||
$transport->send(new ChatMessage($message));
|
$transport->send(new ChatMessage($message));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createTransport(?HttpClientInterface $client = null): SlackTransport
|
|
||||||
{
|
|
||||||
return (new SlackTransport('testPath', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/event-dispatcher": "^4.3|^5.0"
|
"symfony/event-dispatcher": "^4.3|^5.0"
|
||||||
|
|
|
@ -11,64 +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,41 +11,42 @@
|
||||||
|
|
||||||
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\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\MessageOptionsInterface;
|
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
|
||||||
|
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): TransportInterface
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
return new TelegramTransport('token', 'testChannel', $client ?: $this->createMock(HttpClientInterface::class));
|
||||||
|
|
||||||
$this->assertSame('telegram://host.test?channel=testChannel', (string) $transport);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsChatMessage()
|
public function toStringProvider(): iterable
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
yield ['telegram://api.telegram.org?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);
|
public function unsupportedMessagesProvider(): iterable
|
||||||
|
{
|
||||||
$transport->send($this->createMock(MessageInterface::class));
|
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||||
|
yield [$this->createMock(MessageInterface::class)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendWithErrorResponseThrows()
|
public function testSendWithErrorResponseThrows()
|
||||||
|
@ -65,15 +66,13 @@ final class TelegramTransportTest extends TestCase
|
||||||
return $response;
|
return $response;
|
||||||
});
|
});
|
||||||
|
|
||||||
$transport = $this->createTransport('testChannel', $client);
|
$transport = $this->createTransport($client);
|
||||||
|
|
||||||
$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')
|
||||||
|
@ -83,7 +82,7 @@ final class TelegramTransportTest extends TestCase
|
||||||
->willReturn('');
|
->willReturn('');
|
||||||
|
|
||||||
$expectedBody = [
|
$expectedBody = [
|
||||||
'chat_id' => $channel,
|
'chat_id' => 'testChannel',
|
||||||
'text' => 'testMessage',
|
'text' => 'testMessage',
|
||||||
'parse_mode' => 'Markdown',
|
'parse_mode' => 'Markdown',
|
||||||
];
|
];
|
||||||
|
@ -94,7 +93,7 @@ final class TelegramTransportTest extends TestCase
|
||||||
return $response;
|
return $response;
|
||||||
});
|
});
|
||||||
|
|
||||||
$transport = $this->createTransport($channel, $client);
|
$transport = $this->createTransport($client);
|
||||||
|
|
||||||
$transport->send(new ChatMessage('testMessage'));
|
$transport->send(new ChatMessage('testMessage'));
|
||||||
}
|
}
|
||||||
|
@ -123,7 +122,7 @@ final class TelegramTransportTest extends TestCase
|
||||||
return $response;
|
return $response;
|
||||||
});
|
});
|
||||||
|
|
||||||
$transport = $this->createTransport('defaultChannel', $client);
|
$transport = new TelegramTransport('token', $channelOverride, $client);
|
||||||
|
|
||||||
$messageOptions = $this->createMock(MessageOptionsInterface::class);
|
$messageOptions = $this->createMock(MessageOptionsInterface::class);
|
||||||
$messageOptions
|
$messageOptions
|
||||||
|
@ -133,9 +132,4 @@ final class TelegramTransportTest extends TestCase
|
||||||
|
|
||||||
$transport->send(new ChatMessage('testMessage', $messageOptions));
|
$transport->send(new ChatMessage('testMessage', $messageOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createTransport($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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"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 testSendNonSmsMessageThrowsException()
|
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.1.0"
|
"symfony/notifier": "~5.1.11"
|
||||||
},
|
},
|
||||||
"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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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