Skip to content

Commit 82f4321

Browse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[Translation][Mailer] Convert $this calls to static ones in data providers
1 parent 44ec77a commit 82f4321

File tree

6 files changed

+30
-24
lines changed

6 files changed

+30
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ CHANGELOG
44
5.4.21
55
------
66

7-
* [BC BREAK] The following data providers for `TransportFactoryTestCase` are now static:
7+
* [BC BREAK] The following data providers for `TransportFactoryTestCase` are now static:
88
`supportsProvider()`, `createProvider()`, `unsupportedSchemeProvider()`and `incompleteDsnProvider()`
9-
* [BC BREAK] The following data providers for `TransportTestCase` are now static:
9+
* [BC BREAK] The following data providers for `TransportTestCase` are now static:
1010
`toStringProvider()`, `supportedMessagesProvider()` and `unsupportedMessagesProvider()`
1111

1212
5.4

Test/TransportFactoryTestCase.php

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

1414
use PHPUnit\Framework\TestCase;
1515
use Psr\Log\LoggerInterface;
16+
use Psr\Log\NullLogger;
17+
use Symfony\Component\HttpClient\MockHttpClient;
1618
use Symfony\Component\Mailer\Exception\IncompleteDsnException;
1719
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;
1820
use Symfony\Component\Mailer\Transport\Dsn;
@@ -31,11 +33,11 @@ abstract class TransportFactoryTestCase extends TestCase
3133
protected const USER = 'u$er';
3234
protected const PASSWORD = 'pa$s';
3335

34-
protected $dispatcher;
35-
protected $client;
36-
protected $logger;
36+
protected static $dispatcher;
37+
protected static $client;
38+
protected static $logger;
3739

38-
abstract public function getFactory(): TransportFactoryInterface;
40+
abstract public static function getFactory(): TransportFactoryInterface;
3941

4042
abstract public static function supportsProvider(): iterable;
4143

@@ -100,18 +102,22 @@ public function testIncompleteDsnException(Dsn $dsn)
100102
$factory->create($dsn);
101103
}
102104

103-
protected function getDispatcher(): EventDispatcherInterface
105+
protected static function getDispatcher(): EventDispatcherInterface
104106
{
105-
return $this->dispatcher ?? $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
107+
return self::$dispatcher ?? self::$dispatcher = new class() implements EventDispatcherInterface {
108+
public function dispatch($event, string $eventName = null): object
109+
{
110+
}
111+
};
106112
}
107113

108-
protected function getClient(): HttpClientInterface
114+
protected static function getClient(): HttpClientInterface
109115
{
110-
return $this->client ?? $this->client = $this->createMock(HttpClientInterface::class);
116+
return self::$client ?? self::$client = new MockHttpClient();
111117
}
112118

113-
protected function getLogger(): LoggerInterface
119+
protected static function getLogger(): LoggerInterface
114120
{
115-
return $this->logger ?? $this->logger = $this->createMock(LoggerInterface::class);
121+
return self::$logger ?? self::$logger = new NullLogger();
116122
}
117123
}

Tests/Transport/NullTransportFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
class NullTransportFactoryTest extends TransportFactoryTestCase
2121
{
22-
public function getFactory(): TransportFactoryInterface
22+
public static function getFactory(): TransportFactoryInterface
2323
{
24-
return new NullTransportFactory($this->getDispatcher(), $this->getClient(), $this->getLogger());
24+
return new NullTransportFactory(self::getDispatcher(), self::getClient(), self::getLogger());
2525
}
2626

2727
public static function supportsProvider(): iterable
@@ -36,7 +36,7 @@ public static function createProvider(): iterable
3636
{
3737
yield [
3838
new Dsn('null', 'null'),
39-
new NullTransport($this->getDispatcher(), $this->getLogger()),
39+
new NullTransport(self::getDispatcher(), self::getLogger()),
4040
];
4141
}
4242
}

Tests/Transport/SendmailTransportFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
class SendmailTransportFactoryTest extends TransportFactoryTestCase
2121
{
22-
public function getFactory(): TransportFactoryInterface
22+
public static function getFactory(): TransportFactoryInterface
2323
{
24-
return new SendmailTransportFactory($this->getDispatcher(), $this->getClient(), $this->getLogger());
24+
return new SendmailTransportFactory(self::getDispatcher(), self::getClient(), self::getLogger());
2525
}
2626

2727
public static function supportsProvider(): iterable
@@ -36,12 +36,12 @@ public static function createProvider(): iterable
3636
{
3737
yield [
3838
new Dsn('sendmail+smtp', 'default'),
39-
new SendmailTransport(null, $this->getDispatcher(), $this->getLogger()),
39+
new SendmailTransport(null, self::getDispatcher(), self::getLogger()),
4040
];
4141

4242
yield [
4343
new Dsn('sendmail+smtp', 'default', null, null, null, ['command' => '/usr/sbin/sendmail -oi -t']),
44-
new SendmailTransport('/usr/sbin/sendmail -oi -t', $this->getDispatcher(), $this->getLogger()),
44+
new SendmailTransport('/usr/sbin/sendmail -oi -t', self::getDispatcher(), self::getLogger()),
4545
];
4646
}
4747

Tests/Transport/Smtp/EsmtpTransportFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
class EsmtpTransportFactoryTest extends TransportFactoryTestCase
2222
{
23-
public function getFactory(): TransportFactoryInterface
23+
public static function getFactory(): TransportFactoryInterface
2424
{
25-
return new EsmtpTransportFactory($this->getDispatcher(), $this->getClient(), $this->getLogger());
25+
return new EsmtpTransportFactory(self::getDispatcher(), self::getClient(), self::getLogger());
2626
}
2727

2828
public static function supportsProvider(): iterable
@@ -45,8 +45,8 @@ public static function supportsProvider(): iterable
4545

4646
public static function createProvider(): iterable
4747
{
48-
$eventDispatcher = $this->getDispatcher();
49-
$logger = $this->getLogger();
48+
$eventDispatcher = self::getDispatcher();
49+
$logger = self::getLogger();
5050

5151
$transport = new EsmtpTransport('localhost', 25, false, $eventDispatcher, $logger);
5252

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"symfony/service-contracts": "^1.1|^2|^3"
2828
},
2929
"require-dev": {
30-
"symfony/http-client-contracts": "^1.1|^2|^3",
30+
"symfony/http-client": "^4.4|^5.0|^6.0",
3131
"symfony/messenger": "^4.4|^5.0|^6.0"
3232
},
3333
"conflict": {

0 commit comments

Comments
 (0)