Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Notifier] Make TransportTestCase data providers static #49385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 6 UPGRADE-5.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ Monolog
* Deprecate `ResetLoggersWorkerSubscriber` to reset buffered logs in messenger
workers, use `framework.messenger.reset_on_message` option in FrameworkBundle messenger configuration instead.

Notifier
--------

* [BC BREAK] The following data providers for `TransportTestCase` are now static: `toStringProvider()`, `supportedMessagesProvider()` and `unsupportedMessagesProvider()`
* [BC BREAK] The `TransportTestCase::createTransport()` method is now static

SecurityBundle
--------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

use Symfony\Component\Notifier\Bridge\AllMySms\AllMySmsTransport;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

Expand All @@ -24,25 +25,25 @@ final class AllMySmsTransportTest extends TransportTestCase
/**
* @return AllMySmsTransport
*/
public function createTransport(HttpClientInterface $client = null, string $from = null): TransportInterface
public static function createTransport(HttpClientInterface $client = null, string $from = null): TransportInterface
{
return new AllMySmsTransport('login', 'apiKey', $from, $client ?? $this->createMock(HttpClientInterface::class));
return new AllMySmsTransport('login', 'apiKey', $from, $client ?? new DummyHttpClient());
}

public function toStringProvider(): iterable
public static function toStringProvider(): iterable
{
yield ['allmysms://api.allmysms.com', $this->createTransport()];
yield ['allmysms://api.allmysms.com?from=TEST', $this->createTransport(null, 'TEST')];
yield ['allmysms://api.allmysms.com', self::createTransport()];
yield ['allmysms://api.allmysms.com?from=TEST', self::createTransport(null, 'TEST')];
}

public function supportedMessagesProvider(): iterable
public static function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
}

public function unsupportedMessagesProvider(): iterable
public static function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
yield [new DummyMessage()];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0|^6.0",
"symfony/notifier": "^5.3|^6.0"
"symfony/notifier": "^5.4.21|^6.2.7"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\AllMySms\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,36 @@
use Symfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsOptions;
use Symfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsTransport;
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\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
use Symfony\Component\Notifier\Tests\Fixtures\TestOptions;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class AmazonSnsTransportTest extends TransportTestCase
{
public function createTransport(HttpClientInterface $client = null): TransportInterface
public static function createTransport(HttpClientInterface $client = null): TransportInterface
{
return (new AmazonSnsTransport(new SnsClient(['region' => 'eu-west-3']), $client ?? $this->createMock(HttpClientInterface::class)))->setHost('host.test');
return (new AmazonSnsTransport(new SnsClient(['region' => 'eu-west-3']), $client ?? new DummyHttpClient()))->setHost('host.test');
}

public function toStringProvider(): iterable
public static function toStringProvider(): iterable
{
yield ['sns://host.test?region=eu-west-3', $this->createTransport()];
yield ['sns://host.test?region=eu-west-3', self::createTransport()];
}

public function supportedMessagesProvider(): iterable
public static function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('0601020304', 'Hello!')];
yield [new ChatMessage('Hello', new AmazonSnsOptions('my-topic'))];
}

public function unsupportedMessagesProvider(): iterable
public static function unsupportedMessagesProvider(): iterable
{
yield [$this->createMock(MessageInterface::class)];
yield [new ChatMessage('hello', $this->createMock(MessageOptionsInterface::class))];
yield [new DummyMessage()];
yield [new ChatMessage('hello', new TestOptions())];
}

public function testSmsMessageOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.4|^5.2|^6.0",
"symfony/notifier": "^5.4|^6.0",
"symfony/notifier": "^5.4.21|^6.2.7",
"async-aws/sns": "^1.0"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
Expand All @@ -28,31 +30,31 @@ final class ClickatellTransportTest extends TransportTestCase
/**
* @return ClickatellTransport
*/
public function createTransport(HttpClientInterface $client = null, string $from = null): TransportInterface
public static function createTransport(HttpClientInterface $client = null, string $from = null): TransportInterface
{
return new ClickatellTransport('authToken', $from, $client ?? $this->createMock(HttpClientInterface::class));
return new ClickatellTransport('authToken', $from, $client ?? new DummyHttpClient());
}

public function toStringProvider(): iterable
public static function toStringProvider(): iterable
{
yield ['clickatell://api.clickatell.com', $this->createTransport()];
yield ['clickatell://api.clickatell.com?from=TEST', $this->createTransport(null, 'TEST')];
yield ['clickatell://api.clickatell.com', self::createTransport()];
yield ['clickatell://api.clickatell.com?from=TEST', self::createTransport(null, 'TEST')];
}

public function supportedMessagesProvider(): iterable
public static function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('+33612345678', 'Hello!')];
}

public function unsupportedMessagesProvider(): iterable
public static function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
yield [new DummyMessage()];
}

public function testExceptionIsThrownWhenNonMessageIsSend()
{
$transport = $this->createTransport();
$transport = self::createTransport();

$this->expectException(LogicException::class);

Expand All @@ -77,7 +79,7 @@ public function testExceptionIsThrownWhenHttpSendFailed()

$client = new MockHttpClient($response);

$transport = $this->createTransport($client);
$transport = self::createTransport($client);

$this->expectException(TransportException::class);
$this->expectExceptionMessage('Unable to send SMS with Clickatell: Error code 105 with message "Invalid Account Reference EX0000000" (https://documentation-page).');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0|^6.0",
"symfony/notifier": "^5.3|^6.0"
"symfony/notifier": "^5.4.21|^6.2.7"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Clickatell\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
use Symfony\Component\Notifier\Exception\LengthException;
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\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
Expand All @@ -28,30 +29,30 @@ final class DiscordTransportTest extends TransportTestCase
/**
* @return DiscordTransport
*/
public function createTransport(HttpClientInterface $client = null): TransportInterface
public static function createTransport(HttpClientInterface $client = null): TransportInterface
{
return (new DiscordTransport('testToken', 'testWebhookId', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('host.test');
return (new DiscordTransport('testToken', 'testWebhookId', $client ?? new DummyHttpClient()))->setHost('host.test');
}

public function toStringProvider(): iterable
public static function toStringProvider(): iterable
{
yield ['discord://host.test?webhook_id=testWebhookId', $this->createTransport()];
yield ['discord://host.test?webhook_id=testWebhookId', self::createTransport()];
}

public function supportedMessagesProvider(): iterable
public static function supportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
}

public function unsupportedMessagesProvider(): iterable
public static function unsupportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
yield [new DummyMessage()];
}

public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException()
{
$transport = $this->createTransport();
$transport = self::createTransport();

$this->expectException(LengthException::class);
$this->expectExceptionMessage('The subject length of a Discord message must not exceed 2000 characters.');
Expand All @@ -73,7 +74,7 @@ public function testSendWithErrorResponseThrows()
return $response;
});

$transport = $this->createTransport($client);
$transport = self::createTransport($client);

$this->expectException(TransportException::class);
$this->expectExceptionMessageMatches('/testDescription.+testErrorCode/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0|^6.0",
"symfony/notifier": "^5.3|^6.0",
"symfony/notifier": "^5.4.21|^6.2.7",
"symfony/polyfill-mbstring": "^1.0"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransport;
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\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand All @@ -28,25 +29,25 @@ final class EsendexTransportTest extends TransportTestCase
/**
* @return EsendexTransport
*/
public function createTransport(HttpClientInterface $client = null): TransportInterface
public static function createTransport(HttpClientInterface $client = null): TransportInterface
{
return (new EsendexTransport('email', 'password', 'testAccountReference', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('host.test');
return (new EsendexTransport('email', 'password', 'testAccountReference', 'testFrom', $client ?? new DummyHttpClient()))->setHost('host.test');
}

public function toStringProvider(): iterable
public static function toStringProvider(): iterable
{
yield ['esendex://host.test?accountreference=testAccountReference&from=testFrom', $this->createTransport()];
yield ['esendex://host.test?accountreference=testAccountReference&from=testFrom', self::createTransport()];
}

public function supportedMessagesProvider(): iterable
public static function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
}

public function unsupportedMessagesProvider(): iterable
public static function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
yield [new DummyMessage()];
}

public function testSendWithErrorResponseThrowsTransportException()
Expand All @@ -60,7 +61,7 @@ public function testSendWithErrorResponseThrowsTransportException()
return $response;
});

$transport = $this->createTransport($client);
$transport = self::createTransport($client);

$this->expectException(TransportException::class);
$this->expectExceptionMessage('Unable to send the SMS: error 500.');
Expand All @@ -82,7 +83,7 @@ public function testSendWithErrorResponseContainingDetailsThrowsTransportExcepti
return $response;
});

$transport = $this->createTransport($client);
$transport = self::createTransport($client);

$this->expectException(TransportException::class);
$this->expectExceptionMessage('Unable to send the SMS: error 500. Details from Esendex: accountreference_invalid: "Invalid Account Reference EX0000000".');
Expand All @@ -105,7 +106,7 @@ public function testSendWithSuccessfulResponseDispatchesMessageEvent()
return $response;
});

$transport = $this->createTransport($client);
$transport = self::createTransport($client);

$sentMessage = $transport->send(new SmsMessage('phone', 'testMessage'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.4|^5.0|^6.0",
"symfony/notifier": "^5.3|^6.0"
"symfony/notifier": "^5.4.21|^6.2.7"
},
"require-dev": {
"symfony/uid": "^5.4|^6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
namespace Symfony\Component\Notifier\Bridge\Expo\Tests;

use Symfony\Component\Notifier\Bridge\Expo\ExpoTransport;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\PushMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

Expand All @@ -27,24 +28,24 @@ final class ExpoTransportTest extends TransportTestCase
/**
* @return ExpoTransport
*/
public function createTransport(HttpClientInterface $client = null): TransportInterface
public static function createTransport(HttpClientInterface $client = null): TransportInterface
{
return new ExpoTransport('token', $client ?? $this->createMock(HttpClientInterface::class));
return new ExpoTransport('token', $client ?? new DummyHttpClient());
}

public function toStringProvider(): iterable
public static function toStringProvider(): iterable
{
yield ['expo://exp.host/--/api/v2/push/send', $this->createTransport()];
yield ['expo://exp.host/--/api/v2/push/send', self::createTransport()];
}

public function supportedMessagesProvider(): iterable
public static function supportedMessagesProvider(): iterable
{
yield [new PushMessage('Hello!', 'Symfony Notifier')];
}

public function unsupportedMessagesProvider(): iterable
public static function unsupportedMessagesProvider(): iterable
{
yield [new SmsMessage('0670802161', 'Hello!')];
yield [$this->createMock(MessageInterface::class)];
yield [new DummyMessage()];
}
}
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Notifier/Bridge/Expo/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0|^6.0",
"symfony/notifier": "^5.4|^6.0"
"symfony/notifier": "^5.4.21|^6.2.7"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Expo\\": "" },
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.