Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 471c943

Browse files
[Notifier] Make TransportTestCase data providers static
1 parent 7f3e387 commit 471c943

File tree

98 files changed

+744
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+744
-468
lines changed

UPGRADE-5.4.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ Messenger
6969
* Deprecate not setting the `delete_after_ack` config option (or DSN parameter) using the Redis transport,
7070
its default value will change to `true` in 6.0
7171

72+
73+
Notifier
74+
--------
75+
76+
* The following data providers for `TransportTestCase` are now static: `toStringProvider()`, `supportedMessagesProvider()` and `unsupportedMessagesProvider()`
77+
* The `TransportTestCase::createTransport()` method is now static
78+
7279
Monolog
7380
-------
7481

src/Symfony/Component/Notifier/Bridge/AllMySms/Tests/AllMySmsTransportTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313

1414
use Symfony\Component\Notifier\Bridge\AllMySms\AllMySmsTransport;
1515
use Symfony\Component\Notifier\Message\ChatMessage;
16-
use Symfony\Component\Notifier\Message\MessageInterface;
1716
use Symfony\Component\Notifier\Message\SmsMessage;
1817
use Symfony\Component\Notifier\Test\TransportTestCase;
18+
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
19+
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
1920
use Symfony\Component\Notifier\Transport\TransportInterface;
2021
use Symfony\Contracts\HttpClient\HttpClientInterface;
2122

@@ -24,25 +25,25 @@ final class AllMySmsTransportTest extends TransportTestCase
2425
/**
2526
* @return AllMySmsTransport
2627
*/
27-
public function createTransport(HttpClientInterface $client = null, string $from = null): TransportInterface
28+
public static function createTransport(HttpClientInterface $client = null, string $from = null): TransportInterface
2829
{
29-
return new AllMySmsTransport('login', 'apiKey', $from, $client ?? $this->createMock(HttpClientInterface::class));
30+
return new AllMySmsTransport('login', 'apiKey', $from, $client ?? new DummyHttpClient());
3031
}
3132

32-
public function toStringProvider(): iterable
33+
public static function toStringProvider(): iterable
3334
{
34-
yield ['allmysms://api.allmysms.com', $this->createTransport()];
35-
yield ['allmysms://api.allmysms.com?from=TEST', $this->createTransport(null, 'TEST')];
35+
yield ['allmysms://api.allmysms.com', self::createTransport()];
36+
yield ['allmysms://api.allmysms.com?from=TEST', self::createTransport(null, 'TEST')];
3637
}
3738

38-
public function supportedMessagesProvider(): iterable
39+
public static function supportedMessagesProvider(): iterable
3940
{
4041
yield [new SmsMessage('0611223344', 'Hello!')];
4142
}
4243

43-
public function unsupportedMessagesProvider(): iterable
44+
public static function unsupportedMessagesProvider(): iterable
4445
{
4546
yield [new ChatMessage('Hello!')];
46-
yield [$this->createMock(MessageInterface::class)];
47+
yield [new DummyMessage()];
4748
}
4849
}

src/Symfony/Component/Notifier/Bridge/AllMySms/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=7.2.5",
2020
"symfony/http-client": "^4.3|^5.0|^6.0",
21-
"symfony/notifier": "^5.3|^6.0"
21+
"symfony/notifier": "^5.4.21|^6.2.7"
2222
},
2323
"autoload": {
2424
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\AllMySms\\": "" },

src/Symfony/Component/Notifier/Bridge/AmazonSns/Tests/AmazonSnsTransportTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,36 @@
1616
use Symfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsOptions;
1717
use Symfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsTransport;
1818
use Symfony\Component\Notifier\Message\ChatMessage;
19-
use Symfony\Component\Notifier\Message\MessageInterface;
20-
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
2119
use Symfony\Component\Notifier\Message\SmsMessage;
2220
use Symfony\Component\Notifier\Test\TransportTestCase;
21+
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
22+
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
23+
use Symfony\Component\Notifier\Tests\Fixtures\TestOptions;
2324
use Symfony\Component\Notifier\Transport\TransportInterface;
2425
use Symfony\Contracts\HttpClient\HttpClientInterface;
2526

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

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

38-
public function supportedMessagesProvider(): iterable
39+
public static function supportedMessagesProvider(): iterable
3940
{
4041
yield [new SmsMessage('0601020304', 'Hello!')];
4142
yield [new ChatMessage('Hello', new AmazonSnsOptions('my-topic'))];
4243
}
4344

44-
public function unsupportedMessagesProvider(): iterable
45+
public static function unsupportedMessagesProvider(): iterable
4546
{
46-
yield [$this->createMock(MessageInterface::class)];
47-
yield [new ChatMessage('hello', $this->createMock(MessageOptionsInterface::class))];
47+
yield [new DummyMessage()];
48+
yield [new ChatMessage('hello', new TestOptions())];
4849
}
4950

5051
public function testSmsMessageOptions()

src/Symfony/Component/Notifier/Bridge/AmazonSns/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=7.2.5",
2020
"symfony/http-client": "^4.4|^5.2|^6.0",
21-
"symfony/notifier": "^5.4|^6.0",
21+
"symfony/notifier": "^5.4.21|^6.2.7",
2222
"async-aws/sns": "^1.0"
2323
},
2424
"autoload": {

src/Symfony/Component/Notifier/Bridge/Clickatell/Tests/ClickatellTransportTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Symfony\Component\Notifier\Message\MessageInterface;
2020
use Symfony\Component\Notifier\Message\SmsMessage;
2121
use Symfony\Component\Notifier\Test\TransportTestCase;
22+
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
23+
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
2224
use Symfony\Component\Notifier\Transport\TransportInterface;
2325
use Symfony\Contracts\HttpClient\HttpClientInterface;
2426
use Symfony\Contracts\HttpClient\ResponseInterface;
@@ -28,31 +30,31 @@ final class ClickatellTransportTest extends TransportTestCase
2830
/**
2931
* @return ClickatellTransport
3032
*/
31-
public function createTransport(HttpClientInterface $client = null, string $from = null): TransportInterface
33+
public static function createTransport(HttpClientInterface $client = null, string $from = null): TransportInterface
3234
{
33-
return new ClickatellTransport('authToken', $from, $client ?? $this->createMock(HttpClientInterface::class));
35+
return new ClickatellTransport('authToken', $from, $client ?? new DummyHttpClient());
3436
}
3537

36-
public function toStringProvider(): iterable
38+
public static function toStringProvider(): iterable
3739
{
38-
yield ['clickatell://api.clickatell.com', $this->createTransport()];
39-
yield ['clickatell://api.clickatell.com?from=TEST', $this->createTransport(null, 'TEST')];
40+
yield ['clickatell://api.clickatell.com', self::createTransport()];
41+
yield ['clickatell://api.clickatell.com?from=TEST', self::createTransport(null, 'TEST')];
4042
}
4143

42-
public function supportedMessagesProvider(): iterable
44+
public static function supportedMessagesProvider(): iterable
4345
{
4446
yield [new SmsMessage('+33612345678', 'Hello!')];
4547
}
4648

47-
public function unsupportedMessagesProvider(): iterable
49+
public static function unsupportedMessagesProvider(): iterable
4850
{
4951
yield [new ChatMessage('Hello!')];
50-
yield [$this->createMock(MessageInterface::class)];
52+
yield [new DummyMessage()];
5153
}
5254

5355
public function testExceptionIsThrownWhenNonMessageIsSend()
5456
{
55-
$transport = $this->createTransport();
57+
$transport = self::createTransport();
5658

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

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

7880
$client = new MockHttpClient($response);
7981

80-
$transport = $this->createTransport($client);
82+
$transport = self::createTransport($client);
8183

8284
$this->expectException(TransportException::class);
8385
$this->expectExceptionMessage('Unable to send SMS with Clickatell: Error code 105 with message "Invalid Account Reference EX0000000" (https://documentation-page).');

src/Symfony/Component/Notifier/Bridge/Clickatell/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require": {
2323
"php": ">=7.2.5",
2424
"symfony/http-client": "^4.3|^5.0|^6.0",
25-
"symfony/notifier": "^5.3|^6.0"
25+
"symfony/notifier": "^5.4.21|^6.2.7"
2626
},
2727
"autoload": {
2828
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Clickatell\\": "" },

src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
use Symfony\Component\Notifier\Exception\LengthException;
1717
use Symfony\Component\Notifier\Exception\TransportException;
1818
use Symfony\Component\Notifier\Message\ChatMessage;
19-
use Symfony\Component\Notifier\Message\MessageInterface;
2019
use Symfony\Component\Notifier\Message\SmsMessage;
2120
use Symfony\Component\Notifier\Test\TransportTestCase;
21+
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
22+
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
2223
use Symfony\Component\Notifier\Transport\TransportInterface;
2324
use Symfony\Contracts\HttpClient\HttpClientInterface;
2425
use Symfony\Contracts\HttpClient\ResponseInterface;
@@ -28,30 +29,30 @@ final class DiscordTransportTest extends TransportTestCase
2829
/**
2930
* @return DiscordTransport
3031
*/
31-
public function createTransport(HttpClientInterface $client = null): TransportInterface
32+
public static function createTransport(HttpClientInterface $client = null): TransportInterface
3233
{
33-
return (new DiscordTransport('testToken', 'testWebhookId', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('host.test');
34+
return (new DiscordTransport('testToken', 'testWebhookId', $client ?? new DummyHttpClient()))->setHost('host.test');
3435
}
3536

36-
public function toStringProvider(): iterable
37+
public static function toStringProvider(): iterable
3738
{
38-
yield ['discord://host.test?webhook_id=testWebhookId', $this->createTransport()];
39+
yield ['discord://host.test?webhook_id=testWebhookId', self::createTransport()];
3940
}
4041

41-
public function supportedMessagesProvider(): iterable
42+
public static function supportedMessagesProvider(): iterable
4243
{
4344
yield [new ChatMessage('Hello!')];
4445
}
4546

46-
public function unsupportedMessagesProvider(): iterable
47+
public static function unsupportedMessagesProvider(): iterable
4748
{
4849
yield [new SmsMessage('0611223344', 'Hello!')];
49-
yield [$this->createMock(MessageInterface::class)];
50+
yield [new DummyMessage()];
5051
}
5152

5253
public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException()
5354
{
54-
$transport = $this->createTransport();
55+
$transport = self::createTransport();
5556

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

76-
$transport = $this->createTransport($client);
77+
$transport = self::createTransport($client);
7778

7879
$this->expectException(TransportException::class);
7980
$this->expectExceptionMessageMatches('/testDescription.+testErrorCode/');

src/Symfony/Component/Notifier/Bridge/Discord/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=7.2.5",
2020
"symfony/http-client": "^4.3|^5.0|^6.0",
21-
"symfony/notifier": "^5.3|^6.0",
21+
"symfony/notifier": "^5.4.21|^6.2.7",
2222
"symfony/polyfill-mbstring": "^1.0"
2323
},
2424
"autoload": {

src/Symfony/Component/Notifier/Bridge/Esendex/Tests/EsendexTransportTest.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransport;
1616
use Symfony\Component\Notifier\Exception\TransportException;
1717
use Symfony\Component\Notifier\Message\ChatMessage;
18-
use Symfony\Component\Notifier\Message\MessageInterface;
1918
use Symfony\Component\Notifier\Message\SmsMessage;
2019
use Symfony\Component\Notifier\Test\TransportTestCase;
20+
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
21+
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
2122
use Symfony\Component\Notifier\Transport\TransportInterface;
2223
use Symfony\Component\Uid\Uuid;
2324
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -28,25 +29,25 @@ final class EsendexTransportTest extends TransportTestCase
2829
/**
2930
* @return EsendexTransport
3031
*/
31-
public function createTransport(HttpClientInterface $client = null): TransportInterface
32+
public static function createTransport(HttpClientInterface $client = null): TransportInterface
3233
{
33-
return (new EsendexTransport('email', 'password', 'testAccountReference', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('host.test');
34+
return (new EsendexTransport('email', 'password', 'testAccountReference', 'testFrom', $client ?? new DummyHttpClient()))->setHost('host.test');
3435
}
3536

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

41-
public function supportedMessagesProvider(): iterable
42+
public static function supportedMessagesProvider(): iterable
4243
{
4344
yield [new SmsMessage('0611223344', 'Hello!')];
4445
}
4546

46-
public function unsupportedMessagesProvider(): iterable
47+
public static function unsupportedMessagesProvider(): iterable
4748
{
4849
yield [new ChatMessage('Hello!')];
49-
yield [$this->createMock(MessageInterface::class)];
50+
yield [new DummyMessage()];
5051
}
5152

5253
public function testSendWithErrorResponseThrowsTransportException()
@@ -60,7 +61,7 @@ public function testSendWithErrorResponseThrowsTransportException()
6061
return $response;
6162
});
6263

63-
$transport = $this->createTransport($client);
64+
$transport = self::createTransport($client);
6465

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

85-
$transport = $this->createTransport($client);
86+
$transport = self::createTransport($client);
8687

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

108-
$transport = $this->createTransport($client);
109+
$transport = self::createTransport($client);
109110

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

src/Symfony/Component/Notifier/Bridge/Esendex/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=7.2.5",
2020
"symfony/http-client": "^4.4|^5.0|^6.0",
21-
"symfony/notifier": "^5.3|^6.0"
21+
"symfony/notifier": "^5.4.21|^6.2.7"
2222
},
2323
"require-dev": {
2424
"symfony/uid": "^5.4|^6.0"

src/Symfony/Component/Notifier/Bridge/Expo/Tests/ExpoTransportTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
namespace Symfony\Component\Notifier\Bridge\Expo\Tests;
1313

1414
use Symfony\Component\Notifier\Bridge\Expo\ExpoTransport;
15-
use Symfony\Component\Notifier\Message\MessageInterface;
1615
use Symfony\Component\Notifier\Message\PushMessage;
1716
use Symfony\Component\Notifier\Message\SmsMessage;
1817
use Symfony\Component\Notifier\Test\TransportTestCase;
18+
use Symfony\Component\Notifier\Tests\Fixtures\DummyHttpClient;
19+
use Symfony\Component\Notifier\Tests\Fixtures\DummyMessage;
1920
use Symfony\Component\Notifier\Transport\TransportInterface;
2021
use Symfony\Contracts\HttpClient\HttpClientInterface;
2122

@@ -27,24 +28,24 @@ final class ExpoTransportTest extends TransportTestCase
2728
/**
2829
* @return ExpoTransport
2930
*/
30-
public function createTransport(HttpClientInterface $client = null): TransportInterface
31+
public static function createTransport(HttpClientInterface $client = null): TransportInterface
3132
{
32-
return new ExpoTransport('token', $client ?? $this->createMock(HttpClientInterface::class));
33+
return new ExpoTransport('token', $client ?? new DummyHttpClient());
3334
}
3435

35-
public function toStringProvider(): iterable
36+
public static function toStringProvider(): iterable
3637
{
37-
yield ['expo://exp.host/--/api/v2/push/send', $this->createTransport()];
38+
yield ['expo://exp.host/--/api/v2/push/send', self::createTransport()];
3839
}
3940

40-
public function supportedMessagesProvider(): iterable
41+
public static function supportedMessagesProvider(): iterable
4142
{
4243
yield [new PushMessage('Hello!', 'Symfony Notifier')];
4344
}
4445

45-
public function unsupportedMessagesProvider(): iterable
46+
public static function unsupportedMessagesProvider(): iterable
4647
{
4748
yield [new SmsMessage('0670802161', 'Hello!')];
48-
yield [$this->createMock(MessageInterface::class)];
49+
yield [new DummyMessage()];
4950
}
5051
}

src/Symfony/Component/Notifier/Bridge/Expo/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=7.2.5",
2020
"symfony/http-client": "^4.3|^5.0|^6.0",
21-
"symfony/notifier": "^5.4|^6.0"
21+
"symfony/notifier": "^5.4.21|^6.2.7"
2222
},
2323
"autoload": {
2424
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Expo\\": "" },

0 commit comments

Comments
 (0)