[Notifier] Use abstract test cases in 5.x
This commit is contained in:
parent
9f5d17839a
commit
c23363681f
@ -11,75 +11,47 @@
|
||||
|
||||
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\MissingRequiredOptionException;
|
||||
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 testCreateWithMissingOptionWebhookIdThrowsMissingRequiredOptionException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(MissingRequiredOptionException::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'];
|
||||
}
|
||||
|
||||
public function missingRequiredOptionProvider(): iterable
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -11,41 +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\LengthException;
|
||||
use Symfony\Component\Notifier\Exception\TransportException;
|
||||
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
|
||||
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(UnsupportedMessageTypeException::class);
|
||||
|
||||
$transport->send($this->createMock(MessageInterface::class));
|
||||
public function unsupportedMessagesProvider(): iterable
|
||||
{
|
||||
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||
yield [$this->createMock(MessageInterface::class)];
|
||||
}
|
||||
|
||||
public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException()
|
||||
@ -79,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');
|
||||
}
|
||||
}
|
||||
|
@ -11,94 +11,50 @@
|
||||
|
||||
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\MissingRequiredOptionException;
|
||||
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?accountreference=testAccountreference&from=testFrom', (string) $transport);
|
||||
}
|
||||
|
||||
public function testCreateWithMissingEmailThrowsIncompleteDsnException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(IncompleteDsnException::class);
|
||||
|
||||
$factory->create(Dsn::fromString('esendex://:password@host?accountreference=testAccountreference&from=FROM'));
|
||||
}
|
||||
|
||||
public function testCreateWithMissingPasswordThrowsIncompleteDsnException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(IncompleteDsnException::class);
|
||||
|
||||
$factory->create(Dsn::fromString('esendex://email:@host?accountreference=testAccountreference&from=FROM'));
|
||||
}
|
||||
|
||||
public function testCreateWithMissingOptionAccountreferenceThrowsMissingRequiredOptionException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(MissingRequiredOptionException::class);
|
||||
|
||||
$factory->create(Dsn::fromString('esendex://email:password@host?from=FROM'));
|
||||
}
|
||||
|
||||
public function testCreateWithMissingOptionFromThrowsMissingRequiredOptionException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(MissingRequiredOptionException::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 credentials' => ['esendex://host?accountreference=ACCOUNTREFERENCE&from=FROM'];
|
||||
yield 'missing email' => ['esendex://:password@host?accountreference=ACCOUNTREFERENCE&from=FROM'];
|
||||
yield 'missing password' => ['esendex://email:@host?accountreference=ACCOUNTREFERENCE&from=FROM'];
|
||||
}
|
||||
|
||||
public function missingRequiredOptionProvider(): 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
|
||||
}
|
||||
}
|
||||
|
@ -11,43 +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\TransportException;
|
||||
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
|
||||
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?accountreference=testAccountReference&from=testFrom', (string) $transport);
|
||||
return (new EsendexTransport('email', 'password', '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(UnsupportedMessageTypeException::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))
|
||||
@ -66,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))
|
||||
@ -87,9 +88,4 @@ final class EsendexTransportTest extends TestCase
|
||||
|
||||
$transport->send(new SmsMessage('phone', 'testMessage'));
|
||||
}
|
||||
|
||||
private function createTransport(?HttpClientInterface $client = null): EsendexTransport
|
||||
{
|
||||
return (new EsendexTransport('testEmail', 'testPassword', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
|
||||
}
|
||||
}
|
||||
|
@ -11,48 +11,48 @@
|
||||
|
||||
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpClient\MockHttpClient;
|
||||
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions;
|
||||
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransport;
|
||||
use Symfony\Component\Notifier\Exception\LogicException;
|
||||
use Symfony\Component\Notifier\Exception\TransportException;
|
||||
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
|
||||
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;
|
||||
|
||||
class GoogleChatTransportTest extends TestCase
|
||||
final class GoogleChatTransportTest extends TransportTestCase
|
||||
{
|
||||
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(UnsupportedMessageTypeException::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: "[]"');
|
||||
@ -77,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.');
|
||||
@ -209,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));
|
||||
}
|
||||
}
|
||||
|
@ -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\MissingRequiredOptionException;
|
||||
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 testCreateWithNoFromThrowsMissingRequiredOptionException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(MissingRequiredOptionException::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 missingRequiredOptionProvider(): 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
|
||||
}
|
||||
}
|
||||
|
@ -11,66 +11,49 @@
|
||||
|
||||
namespace Symfony\Component\Notifier\Bridge\Iqsms\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransportFactory;
|
||||
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 IqsmsTransportFactoryTest extends TestCase
|
||||
final class IqsmsTransportFactoryTest extends TransportFactoryTestCase
|
||||
{
|
||||
public function testCreateWithDsn()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$transport = $factory->create(Dsn::fromString('iqsms://login:password@host.test?from=some'));
|
||||
$this->assertSame('iqsms://host.test?from=some', (string) $transport);
|
||||
}
|
||||
|
||||
public function testCreateWithMissingOptionFromThrowsIncompleteDsnException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(IncompleteDsnException::class);
|
||||
|
||||
$factory->create(Dsn::fromString('iqsms://login:password@default'));
|
||||
}
|
||||
|
||||
public function testSupportsReturnsTrueWithSupportedScheme()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->assertTrue($factory->supports(Dsn::fromString('iqsms://login:password@default?from=some')));
|
||||
}
|
||||
|
||||
public function testSupportsReturnsFalseWithUnsupportedScheme()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://login:password@default?from=some')));
|
||||
}
|
||||
|
||||
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(UnsupportedSchemeException::class);
|
||||
|
||||
$factory->create(Dsn::fromString('somethingElse://login:password@default?from=some'));
|
||||
}
|
||||
|
||||
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(UnsupportedSchemeException::class);
|
||||
|
||||
// unsupported scheme and missing "from" option
|
||||
$factory->create(Dsn::fromString('somethingElse://login:password@default'));
|
||||
}
|
||||
|
||||
private function createFactory(): IqsmsTransportFactory
|
||||
/**
|
||||
* @return IqsmsTransportFactory
|
||||
*/
|
||||
public function createFactory(): TransportFactoryInterface
|
||||
{
|
||||
return new IqsmsTransportFactory();
|
||||
}
|
||||
|
||||
public function createProvider(): iterable
|
||||
{
|
||||
yield [
|
||||
'iqsms://host.test?from=FROM',
|
||||
'iqsms://login:password@host.test?from=FROM',
|
||||
];
|
||||
}
|
||||
|
||||
public function supportsProvider(): iterable
|
||||
{
|
||||
yield [true, 'iqsms://login:password@default?from=FROM'];
|
||||
yield [false, 'somethingElse://login:password@default?from=FROM'];
|
||||
}
|
||||
|
||||
public function incompleteDsnProvider(): iterable
|
||||
{
|
||||
yield 'missing login' => ['iqsms://:password@host.test?from=FROM'];
|
||||
yield 'missing password' => ['iqsms://login:@host.test?from=FROM'];
|
||||
yield 'missing credentials' => ['iqsms://@host.test?from=FROM'];
|
||||
}
|
||||
|
||||
public function missingRequiredOptionProvider(): iterable
|
||||
{
|
||||
yield 'missing option: from' => ['iqsms://login:password@default'];
|
||||
}
|
||||
|
||||
public function unsupportedSchemeProvider(): iterable
|
||||
{
|
||||
yield ['somethingElse://login:password@default?from=FROM'];
|
||||
yield ['somethingElse://login:password@default']; // missing "from" option
|
||||
}
|
||||
}
|
||||
|
@ -11,41 +11,37 @@
|
||||
|
||||
namespace Symfony\Component\Notifier\Bridge\Iqsms\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransport;
|
||||
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 IqsmsTransportTest extends TestCase
|
||||
final class IqsmsTransportTest extends TransportTestCase
|
||||
{
|
||||
public function testToStringContainsProperties()
|
||||
/**
|
||||
* @return IqsmsTransport
|
||||
*/
|
||||
public function createTransport(?HttpClientInterface $client = null): TransportInterface
|
||||
{
|
||||
$transport = $this->createTransport();
|
||||
|
||||
$this->assertSame('iqsms://host.test?from=sender', (string) $transport);
|
||||
return new IqsmsTransport('login', 'password', 'sender', $client ?: $this->createMock(HttpClientInterface::class));
|
||||
}
|
||||
|
||||
public function testSupportsMessageInterface()
|
||||
public function toStringProvider(): iterable
|
||||
{
|
||||
$transport = $this->createTransport();
|
||||
|
||||
$this->assertTrue($transport->supports(new SmsMessage('9031223344', 'Hello!')));
|
||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
||||
yield ['iqsms://api.iqsms.ru?from=sender', $this->createTransport()];
|
||||
}
|
||||
|
||||
public function testSendNonSmsMessageThrowsException()
|
||||
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(): IqsmsTransport
|
||||
public function unsupportedMessagesProvider(): iterable
|
||||
{
|
||||
return (new IqsmsTransport('login', 'password', 'sender', $this->createMock(HttpClientInterface::class)))->setHost('host.test');
|
||||
yield [new ChatMessage('Hello!')];
|
||||
yield [$this->createMock(MessageInterface::class)];
|
||||
}
|
||||
}
|
||||
|
@ -2,49 +2,48 @@
|
||||
|
||||
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;
|
||||
use Symfony\Component\Notifier\Exception\TransportException;
|
||||
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
|
||||
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(UnsupportedMessageTypeException::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')
|
||||
@ -59,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');
|
||||
@ -189,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');
|
||||
}
|
||||
}
|
||||
|
@ -11,77 +11,47 @@
|
||||
|
||||
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\MissingRequiredOptionException;
|
||||
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 testCreateWithMissingOptionSenderThrowsMissingRequiredOptionException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(MissingRequiredOptionException::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'];
|
||||
}
|
||||
|
||||
public function missingRequiredOptionProvider(): iterable
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -11,43 +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\TransportException;
|
||||
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
|
||||
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(UnsupportedMessageTypeException::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,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');
|
||||
}
|
||||
}
|
||||
|
@ -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://xoxb-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://xoxb-TestToken@host.test',
|
||||
];
|
||||
|
||||
$transport = $factory->create(Dsn::fromString('slack://xoxb-TestUser@host.test?channel=testChannel'));
|
||||
yield 'with path' => [
|
||||
'slack://host.test?channel=testChannel',
|
||||
'slack://xoxb-TestToken@host.test/?channel=testChannel',
|
||||
];
|
||||
|
||||
$this->assertSame('slack://host.test?channel=testChannel', (string) $transport);
|
||||
yield 'without path' => [
|
||||
'slack://host.test?channel=testChannel',
|
||||
'slack://xoxb-TestToken@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://xoxb-TestToken@host?channel=testChannel'];
|
||||
yield [false, 'somethingElse://xoxb-TestToken@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://xoxb-TestToken@host?channel=testChannel'];
|
||||
}
|
||||
}
|
||||
|
@ -11,31 +11,47 @@
|
||||
|
||||
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;
|
||||
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Notifier\Exception\LogicException;
|
||||
use Symfony\Component\Notifier\Exception\TransportException;
|
||||
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
|
||||
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
|
||||
return new SlackTransport('xoxb-TestToken', $channel, $client ?: $this->createMock(HttpClientInterface::class));
|
||||
}
|
||||
|
||||
$transport = new SlackTransport('xoxb-TestToken', $channel, $this->createMock(HttpClientInterface::class));
|
||||
$transport->setHost('host.test');
|
||||
public function toStringProvider(): iterable
|
||||
{
|
||||
yield ['slack://slack.com', $this->createTransport()];
|
||||
yield ['slack://slack.com?channel=test+Channel', $this->createTransport(null, 'test Channel')];
|
||||
}
|
||||
|
||||
$this->assertSame('slack://host.test?channel=test+Channel', (string) $transport);
|
||||
public function supportedMessagesProvider(): iterable
|
||||
{
|
||||
yield [new ChatMessage('Hello!')];
|
||||
}
|
||||
|
||||
public function unsupportedMessagesProvider(): iterable
|
||||
{
|
||||
yield [new SmsMessage('0611223344', 'Hello!')];
|
||||
yield [$this->createMock(MessageInterface::class)];
|
||||
}
|
||||
|
||||
public function testInstatiatingWithAnInvalidSlackTokenThrowsInvalidArgumentException()
|
||||
@ -46,24 +62,7 @@ final class SlackTransportTest extends TestCase
|
||||
new SlackTransport('token', 'testChannel', $this->createMock(HttpClientInterface::class));
|
||||
}
|
||||
|
||||
public function testSupportsChatMessage()
|
||||
{
|
||||
$transport = new SlackTransport('xoxb-TestToken', 'testChannel', $this->createMock(HttpClientInterface::class));
|
||||
|
||||
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
|
||||
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
|
||||
}
|
||||
|
||||
public function testSendNonChatMessageThrowsLogicException()
|
||||
{
|
||||
$transport = new SlackTransport('xoxb-TestToken', 'testChannel', $this->createMock(HttpClientInterface::class));
|
||||
|
||||
$this->expectException(UnsupportedMessageTypeException::class);
|
||||
|
||||
$transport->send($this->createMock(MessageInterface::class));
|
||||
}
|
||||
|
||||
public function testSendWithEmptyArrayResponseThrows()
|
||||
public function testSendWithEmptyArrayResponseThrowsTransportException()
|
||||
{
|
||||
$this->expectException(TransportException::class);
|
||||
|
||||
@ -79,12 +78,12 @@ final class SlackTransportTest extends TestCase
|
||||
return $response;
|
||||
});
|
||||
|
||||
$transport = new SlackTransport('xoxb-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/');
|
||||
@ -102,14 +101,13 @@ final class SlackTransportTest extends TestCase
|
||||
return $response;
|
||||
});
|
||||
|
||||
$transport = new SlackTransport('xoxb-TestToken', 'testChannel', $client);
|
||||
$transport = $this->createTransport($client, 'testChannel');
|
||||
|
||||
$transport->send(new ChatMessage('testMessage'));
|
||||
}
|
||||
|
||||
public function testSendWithOptions()
|
||||
{
|
||||
$token = 'xoxb-TestToken';
|
||||
$channel = 'testChannel';
|
||||
$message = 'testMessage';
|
||||
|
||||
@ -131,14 +129,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 = 'xoxb-TestToken';
|
||||
$channel = 'testChannel';
|
||||
$message = 'testMessage';
|
||||
|
||||
@ -168,7 +165,7 @@ final class SlackTransportTest extends TestCase
|
||||
return $response;
|
||||
});
|
||||
|
||||
$transport = new SlackTransport($token, $channel, $client);
|
||||
$transport = $this->createTransport($client, $channel);
|
||||
|
||||
$transport->send($chatMessage);
|
||||
}
|
||||
@ -181,14 +178,13 @@ final class SlackTransportTest extends TestCase
|
||||
return $this->createMock(ResponseInterface::class);
|
||||
});
|
||||
|
||||
$transport = new SlackTransport('xoxb-TestToken', 'testChannel', $client);
|
||||
$transport = $this->createTransport($client, 'testChannel');
|
||||
|
||||
$transport->send(new ChatMessage('testMessage', $this->createMock(MessageOptionsInterface::class)));
|
||||
}
|
||||
|
||||
public function testSendWith200ResponseButNotOk()
|
||||
{
|
||||
$token = 'xoxb-TestToken';
|
||||
$channel = 'testChannel';
|
||||
$message = 'testMessage';
|
||||
|
||||
@ -212,7 +208,7 @@ final class SlackTransportTest extends TestCase
|
||||
return $response;
|
||||
});
|
||||
|
||||
$transport = new SlackTransport($token, $channel, $client);
|
||||
$transport = $this->createTransport($client, $channel);
|
||||
|
||||
$transport->send(new ChatMessage('testMessage'));
|
||||
}
|
||||
|
@ -11,75 +11,47 @@
|
||||
|
||||
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\MissingRequiredOptionException;
|
||||
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 testCreateWithMissingOptionFromThrowsMissingRequiredOptionException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(MissingRequiredOptionException::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'];
|
||||
}
|
||||
|
||||
public function missingRequiredOptionProvider(): iterable
|
||||
{
|
||||
yield 'missing option: from' => ['smsapi://token@host'];
|
||||
}
|
||||
|
||||
public function unsupportedSchemeProvider(): iterable
|
||||
{
|
||||
yield ['somethingElse://token@host?from=testFrom'];
|
||||
yield ['somethingElse://token@host']; // missing "from" option
|
||||
}
|
||||
}
|
||||
|
@ -11,75 +11,47 @@
|
||||
|
||||
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\MissingRequiredOptionException;
|
||||
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 testCreateWithMissingOptionChannelThrowsMissingRequiredOptionException()
|
||||
{
|
||||
$factory = $this->createFactory();
|
||||
|
||||
$this->expectException(MissingRequiredOptionException::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'];
|
||||
}
|
||||
|
||||
public function missingRequiredOptionProvider(): iterable
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user