[Notifier] Use abstract test cases in 5.2

This commit is contained in:
Oskar Stark 2021-01-06 13:52:21 +01:00 committed by Nicolas Grekas
parent d3739d4482
commit 8f6b08c131
34 changed files with 600 additions and 736 deletions

View File

@ -11,74 +11,43 @@
namespace Symfony\Component\Notifier\Bridge\Discord\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Discord\DiscordTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class DiscordTransportFactoryTest extends TestCase
final class DiscordTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('discord://token@host.test?webhook_id=testWebhookId'));
$this->assertSame('discord://host.test?webhook_id=testWebhookId', (string) $transport);
}
public function testCreateWithMissingOptionWebhookIdThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('discord://token@host'));
}
public function testCreateWithNoTokenThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('discord://host.test?webhook_id=testWebhookId'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('discord://host?webhook_id=testWebhookId')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host?webhook_id=testWebhookId')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://token@host?webhook_id=testWebhookId'));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
// unsupported scheme and missing "webhook_id" option
$factory->create(Dsn::fromString('somethingElse://token@host'));
}
private function createFactory(): DiscordTransportFactory
/**
* @return DiscordTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new DiscordTransportFactory();
}
public function createProvider(): iterable
{
yield [
'discord://host.test?webhook_id=testWebhookId',
'discord://token@host.test?webhook_id=testWebhookId',
];
}
public function supportsProvider(): iterable
{
yield [true, 'discord://host?webhook_id=testWebhookId'];
yield [false, 'somethingElse://host?webhook_id=testWebhookId'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing token' => ['discord://host.test?webhook_id=testWebhookId'];
yield 'missing option: webhook_id' => ['discord://token@host'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://token@host?webhook_id=testWebhookId'];
yield ['somethingElse://token@host']; // missing "webhook_id" option
}
}

View File

@ -11,40 +11,42 @@
namespace Symfony\Component\Notifier\Bridge\Discord\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Discord\DiscordTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
final class DiscordTransportTest extends TestCase
final class DiscordTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return DiscordTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('discord://host.test?webhook_id=testWebhookId', (string) $transport);
return (new DiscordTransport('testToken', 'testWebhookId', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
public function testSupportsChatMessage()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['discord://host.test?webhook_id=testWebhookId', $this->createTransport()];
}
public function testSendNonChatMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
yield [new ChatMessage('Hello!')];
}
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
public function unsupportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException()
@ -78,9 +80,4 @@ final class DiscordTransportTest extends TestCase
$transport->send(new ChatMessage('testMessage'));
}
private function createTransport(?HttpClientInterface $client = null): DiscordTransport
{
return (new DiscordTransport('testToken', 'testWebhookId', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
}

View File

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

View File

@ -44,7 +44,7 @@ final class EsendexTransport extends AbstractTransport
public function __toString(): string
{
return sprintf('esendex://%s', $this->getEndpoint());
return sprintf('esendex://%s?accountreference=%s&from=%s', $this->getEndpoint(), $this->accountReference, $this->from);
}
public function supports(MessageInterface $message): bool

View File

@ -11,75 +11,43 @@
namespace Symfony\Component\Notifier\Bridge\Esendex\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class EsendexTransportFactoryTest extends TestCase
final class EsendexTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('esendex://email:password@host.test?accountreference=testAccountreference&from=testFrom'));
$this->assertSame('esendex://host.test', (string) $transport);
}
public function testCreateWithMissingOptionAccountreferenceThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('esendex://email:password@host?from=FROM'));
}
public function testCreateWithMissingOptionFromThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('esendex://email:password@host?accountreference=ACCOUNTREFERENCE'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('esendex://email:password@host?accountreference=ACCOUNTREFERENCE&from=FROM')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://email:password@host?accountreference=ACCOUNTREFERENCE&from=FROM')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://email:password@host?accountreference=REFERENCE&from=FROM'));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
// unsupported scheme and missing "from" option
$factory->create(Dsn::fromString('somethingElse://email:password@host?accountreference=REFERENCE'));
}
private function createFactory(): EsendexTransportFactory
/**
* @return EsendexTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new EsendexTransportFactory();
}
public function createProvider(): iterable
{
yield [
'esendex://host.test?accountreference=ACCOUNTREFERENCE&from=FROM',
'esendex://email:password@host.test?accountreference=ACCOUNTREFERENCE&from=FROM',
];
}
public function supportsProvider(): iterable
{
yield [true, 'esendex://email:password@host?accountreference=ACCOUNTREFERENCE&from=FROM'];
yield [false, 'somethingElse://email:password@default'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing option: from' => ['esendex://email:password@host?accountreference=ACCOUNTREFERENCE'];
yield 'missing option: accountreference' => ['esendex://email:password@host?from=FROM'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://email:password@default?accountreference=ACCOUNTREFERENCE&from=FROM'];
yield ['somethingElse://email:password@host?accountreference=ACCOUNTREFERENCE']; // missing "from" option
}
}

View File

@ -11,42 +11,44 @@
namespace Symfony\Component\Notifier\Bridge\Esendex\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
final class EsendexTransportTest extends TestCase
final class EsendexTransportTest extends TransportTestCase
{
public function testToString()
/**
* @return EsendexTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('esendex://host.test', (string) $transport);
return (new EsendexTransport('testToken', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
public function testSupportsSmsMessage()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new SmsMessage('phone', 'testSmsMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['esendex://host.test?accountreference=testAccountReference&from=testFrom', $this->createTransport()];
}
public function testSendNonSmsMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new SmsMessage('0611223344', 'Hello!')];
}
public function testSendWithErrorResponseThrows()
public function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
public function testSendWithErrorResponseThrowsTransportException()
{
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
@ -65,7 +67,7 @@ final class EsendexTransportTest extends TestCase
$transport->send(new SmsMessage('phone', 'testMessage'));
}
public function testSendWithErrorResponseContainingDetailsThrows()
public function testSendWithErrorResponseContainingDetailsThrowsTransportException()
{
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
@ -86,9 +88,4 @@ final class EsendexTransportTest extends TestCase
$transport->send(new SmsMessage('phone', 'testMessage'));
}
private function createTransport(?HttpClientInterface $client = null): EsendexTransport
{
return (new EsendexTransport('testToken', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
}

View File

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

View File

@ -14,7 +14,7 @@ where:
- `ACCESS_KEY` is your Google Chat access key
- `ACCESS_TOKEN` is your Google Chat access token
- `SPACE` is the Google Chat space
- `THREAD_KEY` is the the Google Chat message thread to group messages into a single thread (optional)
- `THREAD_KEY` is the Google Chat message thread to group messages into a single thread (optional)
Resources
---------

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Notifier\Bridge\GoogleChat\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions;
class GoogleChatOptionsTest extends TestCase
final class GoogleChatOptionsTest extends TestCase
{
public function testToArray()
{

View File

@ -11,65 +11,46 @@
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class GoogleChatTransportFactoryTest extends TestCase
final class GoogleChatTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY'));
$this->assertSame('googlechat://chat.googleapis.com/AAAAA_YYYYY', (string) $transport);
}
public function testCreateWithThreadKeyInDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg'));
$this->assertSame('googlechat://chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg', (string) $transport);
}
public function testCreateRequiresCredentials()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('googlechat://chat.googleapis.com/v1/spaces/AAAAA_YYYYY/messages'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('googlechat://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'));
}
private function createFactory(): GoogleChatTransportFactory
/**
* @return GoogleChatTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new GoogleChatTransportFactory();
}
public function createProvider(): iterable
{
yield [
'googlechat://chat.googleapis.com/AAAAA_YYYYY',
'googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY',
];
yield [
'googlechat://chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg',
'googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg',
];
}
public function supportsProvider(): iterable
{
yield [true, 'googlechat://host/path'];
yield [false, 'somethingElse://host/path'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing credentials' => ['googlechat://chat.googleapis.com/v1/spaces/AAAAA_YYYYY/messages'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://host/path'];
}
}

View File

@ -20,38 +20,39 @@ use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
class GoogleChatTransportTest extends TestCase
final class GoogleChatTransportTest extends TestCase
{
public function testToStringContainsProperties()
/**
* @return GoogleChatTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$transport->setHost(null);
$this->assertSame('googlechat://chat.googleapis.com/My-Space', (string) $transport);
return new GoogleChatTransport('My-Space', 'theAccessKey', 'theAccessToken=', $client ?: $this->createMock(HttpClientInterface::class));
}
public function testSupportsChatMessage()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['googlechat://chat.googleapis.com/My-Space', $this->createTransport()];
}
public function testSendNonChatMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new ChatMessage('Hello!')];
}
public function testSendWithEmptyArrayResponseThrows()
public function unsupportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
public function testSendWithEmptyArrayResponseThrowsTransportException()
{
$this->expectException(TransportException::class);
$this->expectExceptionMessage('Unable to post the Google Chat message: "[]"');
@ -76,7 +77,7 @@ class GoogleChatTransportTest extends TestCase
$this->assertSame('spaces/My-Space/messages/abcdefg.hijklmno', $sentMessage->getMessageId());
}
public function testSendWithErrorResponseThrows()
public function testSendWithErrorResponseThrowsTransportException()
{
$this->expectException(TransportException::class);
$this->expectExceptionMessage('API key not valid. Please pass a valid API key.');
@ -208,9 +209,4 @@ class GoogleChatTransportTest extends TestCase
$this->assertSame('spaces/My-Space/messages/abcdefg.hijklmno', $sentMessage->getMessageId());
}
private function createTransport(?HttpClientInterface $client = null): GoogleChatTransport
{
return new GoogleChatTransport('My-Space', 'theAccessKey', 'theAccessToken=', $client ?: $this->createMock(HttpClientInterface::class));
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -2,55 +2,41 @@
namespace Symfony\Component\Notifier\Bridge\LinkedIn\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class LinkedInTransportFactoryTest extends TestCase
final class LinkedInTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('linkedin://accessToken:UserId@host.test'));
$this->assertSame('linkedin://host.test', (string) $transport);
}
public function testCreateWithOnlyAccessTokenOrUserIdThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('linkedin://AccessTokenOrUserId@default'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('linkedin://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://accessToken:UserId@default'));
}
private function createFactory(): LinkedInTransportFactory
/**
* @return LinkedInTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new LinkedInTransportFactory();
}
public function createProvider(): iterable
{
yield [
'linkedin://host.test',
'linkedin://accessToken:UserId@host.test',
];
}
public function supportsProvider(): iterable
{
yield [true, 'linkedin://host'];
yield [false, 'somethingElse://host'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing account or user_id' => ['linkedin://AccessTokenOrUserId@default'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://accessToken:UserId@default'];
}
}

View File

@ -2,7 +2,6 @@
namespace Symfony\Component\Notifier\Bridge\LinkedIn\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransport;
use Symfony\Component\Notifier\Exception\LogicException;
@ -10,39 +9,41 @@ use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
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\ResponseInterface;
final class LinkedInTransportTest extends TestCase
final class LinkedInTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return LinkedInTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('linkedin://host.test', (string) $transport);
return (new LinkedInTransport('AuthToken', 'AccountId', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
public function testSupportsChatMessage()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['linkedin://host.test', $this->createTransport()];
}
public function testSendNonChatMessageThrows()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new ChatMessage('Hello!')];
}
public function testSendWithEmptyArrayResponseThrows()
public function unsupportedMessagesProvider(): iterable
{
$this->expectException(TransportException::class);
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
public function testSendWithEmptyArrayResponseThrowsTransportException()
{
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
->method('getStatusCode')
@ -57,10 +58,12 @@ final class LinkedInTransportTest extends TestCase
$transport = $this->createTransport($client);
$this->expectException(TransportException::class);
$transport->send(new ChatMessage('testMessage'));
}
public function testSendWithErrorResponseThrows()
public function testSendWithErrorResponseThrowsTransportException()
{
$this->expectException(TransportException::class);
$this->expectExceptionMessage('testErrorCode');
@ -187,9 +190,4 @@ final class LinkedInTransportTest extends TestCase
$transport->send(new ChatMessage('testMessage', $this->createMock(MessageOptionsInterface::class)));
}
private function createTransport(?HttpClientInterface $client = null): LinkedInTransport
{
return (new LinkedInTransport('AuthToken', 'AccountId', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
}

View File

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

View File

@ -0,0 +1,61 @@
<?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\Bridge\Mobyt\Tests;
use Symfony\Component\Notifier\Bridge\Mobyt\MobytTransportFactory;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class MobytTransportFactoryTest extends TransportFactoryTestCase
{
/**
* @return MobytTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new MobytTransportFactory();
}
public function createProvider(): iterable
{
yield [
'mobyt://host.test?from=FROM&type_quality=LL',
'mobyt://accountSid:authToken@host.test?from=FROM',
];
yield [
'mobyt://host.test?from=FROM&type_quality=N',
'mobyt://accountSid:authToken@host.test?from=FROM&type_quality=N',
];
}
public function supportsProvider(): iterable
{
yield [true, 'mobyt://accountSid:authToken@host.test?from=FROM'];
yield [false, 'somethingElse://accountSid:authToken@host.test?from=FROM'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing token' => ['mobyt://host.test?from=FROM'];
yield 'missing option: from' => ['mobyt://accountSid:authToken@host'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://accountSid:authToken@host.test?from=FROM'];
yield ['somethingElse://accountSid:authToken@host.test']; // missing "from" option
}
}

View File

@ -0,0 +1,52 @@
<?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\Bridge\Mobyt\Tests;
use Symfony\Component\Notifier\Bridge\Mobyt\MobytOptions;
use Symfony\Component\Notifier\Bridge\Mobyt\MobytTransport;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* @author Oskar Stark <oskarstark@googlemail.com>
*/
final class MobytTransportTest extends TransportTestCase
{
/**
* @return MobytTransport
*/
public function createTransport(?HttpClientInterface $client = null, string $messageType = MobytOptions::MESSAGE_TYPE_QUALITY_LOW): TransportInterface
{
return (new MobytTransport('accountSid', 'authToken', 'from', $messageType, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
public function toStringProvider(): iterable
{
yield ['mobyt://host.test?from=from&type_quality=LL', $this->createTransport()];
yield ['mobyt://host.test?from=from&type_quality=N', $this->createTransport(null, MobytOptions::MESSAGE_TYPE_QUALITY_HIGH)];
}
public function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
}
public function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

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

View File

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

View File

@ -11,42 +11,44 @@
namespace Symfony\Component\Notifier\Bridge\Sendinblue\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Sendinblue\SendinblueTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
final class SendinblueTransportTest extends TestCase
final class SendinblueTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return SendinblueTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('sendinblue://host.test?sender=0611223344', (string) $transport);
return (new SendinblueTransport('api-key', '0611223344', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
public function testSupportsMessageInterface()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['sendinblue://host.test?sender=0611223344', $this->createTransport()];
}
public function testSendNonSmsMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new SmsMessage('0611223344', 'Hello!')];
}
public function testSendWithErrorResponseThrows()
public function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
public function testSendWithErrorResponseThrowsTransportException()
{
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
@ -64,11 +66,7 @@ final class SendinblueTransportTest extends TestCase
$this->expectException(TransportException::class);
$this->expectExceptionMessage('Unable to send the SMS: bad request');
$transport->send(new SmsMessage('phone', 'testMessage'));
}
private function createTransport(?HttpClientInterface $client = null): SendinblueTransport
{
return (new SendinblueTransport('api-key', '0611223344', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
}

View File

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

View File

@ -43,6 +43,10 @@ final class SlackTransport extends AbstractTransport
public function __toString(): string
{
if (null === $this->chatChannel) {
return sprintf('slack://%s', $this->getEndpoint());
}
return sprintf('slack://%s?channel=%s', $this->getEndpoint(), urlencode($this->chatChannel));
}

View File

@ -11,31 +11,38 @@
namespace Symfony\Component\Notifier\Bridge\Slack\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class SlackTransportFactoryTest extends TestCase
final class SlackTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
/**
* @return SlackTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('slack://testUser@host.test/?channel=testChannel'));
$this->assertSame('slack://host.test?channel=testChannel', (string) $transport);
return new SlackTransportFactory();
}
public function testCreateWithDsnWithoutPath()
public function createProvider(): iterable
{
$factory = $this->createFactory();
yield [
'slack://host.test',
'slack://testUser@host.test',
];
$transport = $factory->create(Dsn::fromString('slack://testUser@host.test?channel=testChannel'));
yield 'with path' => [
'slack://host.test?channel=testChannel',
'slack://testUser@host.test/?channel=testChannel',
];
$this->assertSame('slack://host.test?channel=testChannel', (string) $transport);
yield 'without path' => [
'slack://host.test?channel=testChannel',
'slack://testUser@host.test?channel=testChannel',
];
}
public function testCreateWithDeprecatedDsn()
@ -48,38 +55,19 @@ final class SlackTransportFactoryTest extends TestCase
$factory->create(Dsn::fromString('slack://default/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX'));
}
public function testCreateWithNoTokenThrowsInclompleteDsnException()
public function supportsProvider(): iterable
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('slack://host.test?channel=testChannel'));
yield [true, 'slack://host?channel=testChannel'];
yield [false, 'somethingElse://host?channel=testChannel'];
}
public function testSupportsReturnsTrueWithSupportedScheme()
public function incompleteDsnProvider(): iterable
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('slack://host?channel=testChannel')));
yield 'missing token' => ['slack://host.test?channel=testChannel'];
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
public function unsupportedSchemeProvider(): iterable
{
$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://host?channel=testChannel'));
}
private function createFactory(): SlackTransportFactory
{
return new SlackTransportFactory();
yield ['somethingElse://host?channel=testChannel'];
}
}

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\Notifier\Bridge\Slack\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
use Symfony\Component\Notifier\Bridge\Slack\SlackTransport;
@ -20,40 +19,41 @@ use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
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\ResponseInterface;
final class SlackTransportTest extends TestCase
final class SlackTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return SlackTransport
*/
public function createTransport(?HttpClientInterface $client = null, string $channel = null): TransportInterface
{
$channel = 'test Channel'; // invalid channel name to test url encoding of the channel
$transport = new SlackTransport('testToken', $channel, $this->createMock(HttpClientInterface::class));
$transport->setHost('host.test');
$this->assertSame('slack://host.test?channel=test+Channel', (string) $transport);
return new SlackTransport('testToken', $channel, $client ?: $this->createMock(HttpClientInterface::class));
}
public function testSupportsChatMessage()
public function toStringProvider(): iterable
{
$transport = new SlackTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['slack://slack.com', $this->createTransport()];
yield ['slack://slack.com?channel=test+Channel', $this->createTransport(null, 'test Channel')];
}
public function testSendNonChatMessageThrowsLogicException()
public function supportedMessagesProvider(): iterable
{
$transport = new SlackTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new ChatMessage('Hello!')];
}
public function testSendWithEmptyArrayResponseThrows()
public function unsupportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
public function testSendWithEmptyArrayResponseThrowsTransportException()
{
$this->expectException(TransportException::class);
@ -69,12 +69,12 @@ final class SlackTransportTest extends TestCase
return $response;
});
$transport = new SlackTransport('testToken', 'testChannel', $client);
$transport = $this->createTransport($client, 'testChannel');
$transport->send(new ChatMessage('testMessage'));
}
public function testSendWithErrorResponseThrows()
public function testSendWithErrorResponseThrowsTransportException()
{
$this->expectException(TransportException::class);
$this->expectExceptionMessageMatches('/testErrorCode/');
@ -92,14 +92,13 @@ final class SlackTransportTest extends TestCase
return $response;
});
$transport = new SlackTransport('testToken', 'testChannel', $client);
$transport = $this->createTransport($client, 'testChannel');
$transport->send(new ChatMessage('testMessage'));
}
public function testSendWithOptions()
{
$token = 'testToken';
$channel = 'testChannel';
$message = 'testMessage';
@ -121,14 +120,13 @@ final class SlackTransportTest extends TestCase
return $response;
});
$transport = new SlackTransport($token, $channel, $client);
$transport = $this->createTransport($client, $channel);
$transport->send(new ChatMessage('testMessage'));
}
public function testSendWithNotification()
{
$token = 'testToken';
$channel = 'testChannel';
$message = 'testMessage';
@ -158,7 +156,7 @@ final class SlackTransportTest extends TestCase
return $response;
});
$transport = new SlackTransport($token, $channel, $client);
$transport = $this->createTransport($client, $channel);
$transport->send($chatMessage);
}
@ -171,14 +169,13 @@ final class SlackTransportTest extends TestCase
return $this->createMock(ResponseInterface::class);
});
$transport = new SlackTransport('testToken', 'testChannel', $client);
$transport = $this->createTransport($client, 'testChannel');
$transport->send(new ChatMessage('testMessage', $this->createMock(MessageOptionsInterface::class)));
}
public function testSendWith200ResponseButNotOk()
{
$token = 'testToken';
$channel = 'testChannel';
$message = 'testMessage';
@ -202,7 +199,7 @@ final class SlackTransportTest extends TestCase
return $response;
});
$transport = new SlackTransport($token, $channel, $client);
$transport = $this->createTransport($client, $channel);
$transport->send(new ChatMessage('testMessage'));
}

View File

@ -11,74 +11,43 @@
namespace Symfony\Component\Notifier\Bridge\Smsapi\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Smsapi\SmsapiTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class SmsapiTransportFactoryTest extends TestCase
final class SmsapiTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('smsapi://token@host.test?from=testFrom'));
$this->assertSame('smsapi://host.test?from=testFrom', (string) $transport);
}
public function testCreateWithMissingOptionFromThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('smsapi://token@host'));
}
public function testCreateWithNoTokenThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('smsapi://host.test?from=testFrom'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('smsapi://host?from=testFrom')));
}
public function testSupportsReturnsFalseWithUnsupportedScheme()
{
$factory = $this->createFactory();
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host?from=testFrom')));
}
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
{
$factory = $this->createFactory();
$this->expectException(UnsupportedSchemeException::class);
$factory->create(Dsn::fromString('somethingElse://token@host?from=testFrom'));
}
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(): SmsapiTransportFactory
/**
* @return SmsapiTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new SmsapiTransportFactory();
}
public function createProvider(): iterable
{
yield [
'smsapi://host.test?from=testFrom',
'smsapi://token@host.test?from=testFrom',
];
}
public function supportsProvider(): iterable
{
yield [true, 'smsapi://host?from=testFrom'];
yield [false, 'somethingElse://host?from=testFrom'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing token' => ['smsapi://host.test?from=testFrom'];
yield 'missing option: from' => ['smsapi://token@host'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://token@host?from=testFrom'];
yield ['somethingElse://token@host']; // missing "from" option
}
}

View File

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

View File

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

View File

@ -50,7 +50,7 @@ final class TelegramTransportTest extends TransportTestCase
yield [$this->createMock(MessageInterface::class)];
}
public function testSendWithErrorResponseThrows()
public function testSendWithErrorResponseThrowsTransportException()
{
$this->expectException(TransportException::class);
$this->expectExceptionMessageMatches('/testDescription.+testErrorCode/');

View File

@ -11,74 +11,43 @@
namespace Symfony\Component\Notifier\Bridge\Zulip\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Tests\TransportFactoryTestCase;
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
final class ZulipTransportFactoryTest extends TestCase
final class ZulipTransportFactoryTest extends TransportFactoryTestCase
{
public function testCreateWithDsn()
{
$factory = $this->createFactory();
$transport = $factory->create(Dsn::fromString('zulip://email:token@host.test?channel=testChannel'));
$this->assertSame('zulip://host.test?channel=testChannel', (string) $transport);
}
public function testCreateWithMissingOptionChannelThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('zulip://email:token@host'));
}
public function testCreateWithOnlyEmailOrTokenThrowsIncompleteDsnException()
{
$factory = $this->createFactory();
$this->expectException(IncompleteDsnException::class);
$factory->create(Dsn::fromString('zulip://testOneOfEmailOrToken@host.test?channel=testChannel'));
}
public function testSupportsReturnsTrueWithSupportedScheme()
{
$factory = $this->createFactory();
$this->assertTrue($factory->supports(Dsn::fromString('zulip://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://email: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://email:token@host'));
}
private function createFactory(): ZulipTransportFactory
/**
* @return ZulipTransportFactory
*/
public function createFactory(): TransportFactoryInterface
{
return new ZulipTransportFactory();
}
public function createProvider(): iterable
{
yield [
'zulip://host.test?channel=testChannel',
'zulip://email:token@host.test?channel=testChannel',
];
}
public function supportsProvider(): iterable
{
yield [true, 'zulip://host?channel=testChannel'];
yield [false, 'somethingElse://host?channel=testChannel'];
}
public function incompleteDsnProvider(): iterable
{
yield 'missing email or token' => ['zulip://testOneOfEmailOrToken@host.test?channel=testChannel'];
yield 'missing option: channel' => ['zulip://email:token@host'];
}
public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://email:token@host?channel=testChannel'];
yield ['somethingElse://email:token@host']; // missing "channel" option
}
}

View File

@ -11,40 +11,37 @@
namespace Symfony\Component\Notifier\Bridge\Zulip\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransport;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Tests\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class ZulipTransportTest extends TestCase
final class ZulipTransportTest extends TransportTestCase
{
public function testToStringContainsProperties()
/**
* @return ZulipTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
$transport = $this->createTransport();
$this->assertSame('zulip://test.host?channel=testChannel', (string) $transport);
return (new ZulipTransport('testEmail', 'testToken', 'testChannel', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('test.host');
}
public function testSupportsChatMessage()
public function toStringProvider(): iterable
{
$transport = $this->createTransport();
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
yield ['zulip://test.host?channel=testChannel', $this->createTransport()];
}
public function testSendNonChatMessageThrows()
public function supportedMessagesProvider(): iterable
{
$transport = $this->createTransport();
$this->expectException(LogicException::class);
$transport->send($this->createMock(MessageInterface::class));
yield [new ChatMessage('Hello!')];
}
private function createTransport(): ZulipTransport
public function unsupportedMessagesProvider(): iterable
{
return (new ZulipTransport('testEmail', 'testToken', 'testChannel', $this->createMock(HttpClientInterface::class)))->setHost('test.host');
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
}
}

View File

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