Skip to content

Commit e2bd169

Browse files
committed
minor symfony#58318 [Notifier] Make data providers static (derrabus)
This PR was merged into the 6.4 branch. Discussion ---------- [Notifier] Make data providers static | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT Data provides must be static in PHPUnit 11. For the trivial cases, I've simply added the static keyword. In two more complicated cases, we created mocks inside a data provider which is bit of a problem. Given that those providers emitted only two test sets each anyway, I've resolved the data providers by creating two separate tests. Commits ------- 390cbbb [Notifier] Make data providers static
2 parents df36e5f + 390cbbb commit e2bd169

File tree

7 files changed

+64
-104
lines changed

7 files changed

+64
-104
lines changed

src/Symfony/Component/Notifier/Bridge/Bandwidth/Tests/BandwidthTransportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function createTransport(?HttpClientInterface $client = null, stri
2929
return new BandwidthTransport('username', 'password', $from, 'account_id', 'application_id', 'priority', $client ?? new MockHttpClient());
3030
}
3131

32-
public function invalidFromProvider(): iterable
32+
public static function invalidFromProvider(): iterable
3333
{
3434
yield 'no zero at start if phone number' => ['+0'];
3535
yield 'phone number too short' => ['+1'];

src/Symfony/Component/Notifier/Bridge/FakeChat/Tests/FakeChatTransportFactoryTest.php

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,38 @@
2020

2121
final class FakeChatTransportFactoryTest extends TransportFactoryTestCase
2222
{
23-
/**
24-
* @dataProvider missingRequiredDependencyProvider
25-
*/
26-
public function testMissingRequiredDependency(?MailerInterface $mailer, ?LoggerInterface $logger, string $dsn, string $message)
23+
public function testMissingRequiredMailerDependency()
2724
{
2825
$this->expectException(LogicException::class);
29-
$this->expectExceptionMessage($message);
26+
$this->expectExceptionMessage('Cannot create a transport for scheme "fakechat+email" without providing an implementation of "Symfony\Component\Mailer\MailerInterface".');
3027

31-
$factory = new FakeChatTransportFactory($mailer, $logger);
32-
$factory->create(new Dsn($dsn));
28+
$factory = new FakeChatTransportFactory(null, $this->createStub(LoggerInterface::class));
29+
$factory->create(new Dsn('fakechat+email://[email protected]&[email protected]'));
3330
}
3431

35-
/**
36-
* @dataProvider missingOptionalDependencyProvider
37-
*/
38-
public function testMissingOptionalDependency(?MailerInterface $mailer, ?LoggerInterface $logger, string $dsn)
32+
public function testMissingRequiredLoggerDependency()
3933
{
40-
$factory = new FakeChatTransportFactory($mailer, $logger);
41-
$transport = $factory->create(new Dsn($dsn));
34+
$this->expectException(LogicException::class);
35+
$this->expectExceptionMessage('Cannot create a transport for scheme "fakechat+logger" without providing an implementation of "Psr\Log\LoggerInterface".');
36+
37+
$factory = new FakeChatTransportFactory($this->createStub(MailerInterface::class));
38+
$factory->create(new Dsn('fakechat+logger://default'));
39+
}
40+
41+
public function testMissingOptionalLoggerDependency()
42+
{
43+
$factory = new FakeChatTransportFactory($this->createStub(MailerInterface::class));
44+
$transport = $factory->create(new Dsn('fakechat+email://[email protected]&[email protected]'));
45+
46+
$this->assertSame('fakechat+email://[email protected]&[email protected]', (string) $transport);
47+
}
48+
49+
public function testMissingOptionalMailerDependency()
50+
{
51+
$factory = new FakeChatTransportFactory(null, $this->createStub(LoggerInterface::class));
52+
$transport = $factory->create(new Dsn('fakechat+logger://default'));
4253

43-
$this->assertSame($dsn, (string) $transport);
54+
$this->assertSame('fakechat+logger://default', (string) $transport);
4455
}
4556

4657
public function createFactory(): FakeChatTransportFactory
@@ -88,35 +99,4 @@ public static function unsupportedSchemeProvider(): iterable
8899
{
89100
yield ['somethingElse://[email protected]&[email protected]'];
90101
}
91-
92-
public function missingRequiredDependencyProvider(): iterable
93-
{
94-
$exceptionMessage = 'Cannot create a transport for scheme "%s" without providing an implementation of "%s".';
95-
yield 'missing mailer' => [
96-
null,
97-
$this->createMock(LoggerInterface::class),
98-
99-
sprintf($exceptionMessage, 'fakechat+email', MailerInterface::class),
100-
];
101-
yield 'missing logger' => [
102-
$this->createMock(MailerInterface::class),
103-
null,
104-
'fakechat+logger://default',
105-
sprintf($exceptionMessage, 'fakechat+logger', LoggerInterface::class),
106-
];
107-
}
108-
109-
public function missingOptionalDependencyProvider(): iterable
110-
{
111-
yield 'missing logger' => [
112-
$this->createMock(MailerInterface::class),
113-
null,
114-
115-
];
116-
yield 'missing mailer' => [
117-
null,
118-
$this->createMock(LoggerInterface::class),
119-
'fakechat+logger://default',
120-
];
121-
}
122102
}

src/Symfony/Component/Notifier/Bridge/FakeSms/Tests/FakeSmsTransportFactoryTest.php

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,38 @@
2020

2121
final class FakeSmsTransportFactoryTest extends TransportFactoryTestCase
2222
{
23-
/**
24-
* @dataProvider missingRequiredDependencyProvider
25-
*/
26-
public function testMissingRequiredDependency(?MailerInterface $mailer, ?LoggerInterface $logger, string $dsn, string $message)
23+
public function testMissingRequiredMailerDependency()
2724
{
2825
$this->expectException(LogicException::class);
29-
$this->expectExceptionMessage($message);
26+
$this->expectExceptionMessage('Cannot create a transport for scheme "fakesms+email" without providing an implementation of "Symfony\Component\Mailer\MailerInterface".');
3027

31-
$factory = new FakeSmsTransportFactory($mailer, $logger);
32-
$factory->create(new Dsn($dsn));
28+
$factory = new FakeSmsTransportFactory(null, $this->createStub(LoggerInterface::class));
29+
$factory->create(new Dsn('fakesms+email://[email protected]&[email protected]'));
3330
}
3431

35-
/**
36-
* @dataProvider missingOptionalDependencyProvider
37-
*/
38-
public function testMissingOptionalDependency(?MailerInterface $mailer, ?LoggerInterface $logger, string $dsn)
32+
public function testMissingRequiredDependency()
3933
{
40-
$factory = new FakeSmsTransportFactory($mailer, $logger);
41-
$transport = $factory->create(new Dsn($dsn));
34+
$this->expectException(LogicException::class);
35+
$this->expectExceptionMessage('Cannot create a transport for scheme "fakesms+logger" without providing an implementation of "Psr\Log\LoggerInterface".');
36+
37+
$factory = new FakeSmsTransportFactory($this->createStub(MailerInterface::class));
38+
$factory->create(new Dsn('fakesms+logger://default'));
39+
}
40+
41+
public function testMissingOptionalLoggerDependency()
42+
{
43+
$factory = new FakeSmsTransportFactory($this->createStub(MailerInterface::class));
44+
$transport = $factory->create(new Dsn('fakesms+email://[email protected]&[email protected]'));
45+
46+
$this->assertSame('fakesms+email://[email protected]&[email protected]', (string) $transport);
47+
}
48+
49+
public function testMissingOptionalMailerDependency()
50+
{
51+
$factory = new FakeSmsTransportFactory(null, $this->createStub(LoggerInterface::class));
52+
$transport = $factory->create(new Dsn('fakesms+logger://default'));
4253

43-
$this->assertSame($dsn, (string) $transport);
54+
$this->assertSame('fakesms+logger://default', (string) $transport);
4455
}
4556

4657
public function createFactory(): FakeSmsTransportFactory
@@ -88,35 +99,4 @@ public static function unsupportedSchemeProvider(): iterable
8899
{
89100
yield ['somethingElse://[email protected]&[email protected]'];
90101
}
91-
92-
public function missingRequiredDependencyProvider(): iterable
93-
{
94-
$exceptionMessage = 'Cannot create a transport for scheme "%s" without providing an implementation of "%s".';
95-
yield 'missing mailer' => [
96-
null,
97-
$this->createMock(LoggerInterface::class),
98-
99-
sprintf($exceptionMessage, 'fakesms+email', MailerInterface::class),
100-
];
101-
yield 'missing logger' => [
102-
$this->createMock(MailerInterface::class),
103-
null,
104-
'fakesms+logger://default',
105-
sprintf($exceptionMessage, 'fakesms+logger', LoggerInterface::class),
106-
];
107-
}
108-
109-
public function missingOptionalDependencyProvider(): iterable
110-
{
111-
yield 'missing logger' => [
112-
$this->createMock(MailerInterface::class),
113-
null,
114-
115-
];
116-
yield 'missing mailer' => [
117-
null,
118-
$this->createMock(LoggerInterface::class),
119-
'fakesms+logger://default',
120-
];
121-
}
122102
}

src/Symfony/Component/Notifier/Bridge/GoIp/Tests/GoIpTransportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testSendMessageWithUnsuccessfulReplyFromGoipThrows(string $goipE
8282
self::createTransport($mockClient)->send(new SmsMessage('1', 'Test'));
8383
}
8484

85-
public function goipErrorsProvider(): iterable
85+
public static function goipErrorsProvider(): iterable
8686
{
8787
yield ['ERROR,L10 GSM logout'];
8888
}

src/Symfony/Component/Notifier/Bridge/Plivo/Tests/PlivoTransportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function createTransport(?HttpClientInterface $client = null, stri
2929
return new PlivoTransport('authId', 'authToken', $from, $client ?? new MockHttpClient());
3030
}
3131

32-
public function invalidFromProvider(): iterable
32+
public static function invalidFromProvider(): iterable
3333
{
3434
yield 'too short' => ['a'];
3535
yield 'too long' => ['abcdefghijkl'];

src/Symfony/Component/Notifier/Bridge/SimpleTextin/Tests/SimpleTextinTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function createTransport(?HttpClientInterface $client = null, stri
2828
return new SimpleTextinTransport('test_api_key', $from, $client ?? new MockHttpClient());
2929
}
3030

31-
public function invalidFromProvider(): iterable
31+
public static function invalidFromProvider(): iterable
3232
{
3333
yield 'no zero at start if phone number' => ['+0'];
3434
yield 'phone number too short' => ['+1'];
@@ -87,7 +87,7 @@ public static function unsupportedMessagesProvider(): iterable
8787
yield [new DummyMessage()];
8888
}
8989

90-
public function validFromProvider(): iterable
90+
public static function validFromProvider(): iterable
9191
{
9292
yield ['+11'];
9393
yield ['+112'];

src/Symfony/Component/Notifier/Bridge/SpotHit/Tests/SpotHitTransportTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,26 @@ function ($method, $url, $options) {
6767
$transport->send(new SmsMessage('0611223344', 'Hello!'));
6868
}
6969

70-
public function argumentsProvider(): \Generator
70+
public static function argumentsProvider(): \Generator
7171
{
7272
yield [
73-
function (SpotHitTransport $transport) { $transport->setSmsLong(true); },
74-
function (array $bodyArguments) { $this->assertSame('1', $bodyArguments['smslong']); },
73+
static function (SpotHitTransport $transport) { $transport->setSmsLong(true); },
74+
static function (array $bodyArguments) { self::assertSame('1', $bodyArguments['smslong']); },
7575
];
7676

7777
yield [
78-
function (SpotHitTransport $transport) { $transport->setLongNBr(3); },
79-
function (array $bodyArguments) { $this->assertSame('3', $bodyArguments['smslongnbr']); },
78+
static function (SpotHitTransport $transport) { $transport->setLongNBr(3); },
79+
static function (array $bodyArguments) { self::assertSame('3', $bodyArguments['smslongnbr']); },
8080
];
8181

8282
yield [
83-
function (SpotHitTransport $transport) {
83+
static function (SpotHitTransport $transport) {
8484
$transport->setSmsLong(true);
8585
$transport->setLongNBr(3);
8686
},
87-
function (array $bodyArguments) {
88-
$this->assertSame('1', $bodyArguments['smslong']);
89-
$this->assertSame('3', $bodyArguments['smslongnbr']);
87+
static function (array $bodyArguments) {
88+
self::assertSame('1', $bodyArguments['smslong']);
89+
self::assertSame('3', $bodyArguments['smslongnbr']);
9090
},
9191
];
9292
}

0 commit comments

Comments
 (0)