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

Skip to content

Commit ef2b65a

Browse files
committed
minor #33419 [Mailer] Renamed getName() to toString() (fabpot)
This PR was merged into the 4.4 branch. Discussion ---------- [Mailer] Renamed getName() to toString() | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | n/a | License | MIT | Doc PR | n/a The `getName()` method on a Transport was introduced in 4.4. We rename it here as this method is mainly used by the profiler to display useful information about which mailer is used. This is more a string representation than a name (which is going to be introduced in the PR about multiple mailer support). Commits ------- 5b7bba9 [Mailer] Renamed getName() to toString()
2 parents bcb91ea + 5b7bba9 commit ef2b65a

28 files changed

+56
-51
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/MailerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher, LoggerInt
4343
$this->onDoSend = $onDoSend;
4444
}
4545

46-
public function getName(): string
46+
public function __toString(): string
4747
{
4848
return 'dummy://local';
4949
}

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(string $accessKey, string $secretKey, string $region
4343
parent::__construct($client, $dispatcher, $logger);
4444
}
4545

46-
public function getName(): string
46+
public function __toString(): string
4747
{
4848
return sprintf('api://%s@ses?region=%s', $this->accessKey, $this->region);
4949
}

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesHttpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(string $accessKey, string $secretKey, string $region
4242
parent::__construct($client, $dispatcher, $logger);
4343
}
4444

45-
public function getName(): string
45+
public function __toString(): string
4646
{
4747
return sprintf('http://%s@ses?region=%s', $this->accessKey, $this->region);
4848
}

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillApiTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3636
parent::__construct($client, $dispatcher, $logger);
3737
}
3838

39-
public function getName(): string
39+
public function __toString(): string
4040
{
4141
return sprintf('api://mandrill');
4242
}

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillHttpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3434
parent::__construct($client, $dispatcher, $logger);
3535
}
3636

37-
public function getName(): string
37+
public function __toString(): string
3838
{
3939
return sprintf('http://mandrill');
4040
}

src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunApiTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(string $key, string $domain, string $region = null,
4141
parent::__construct($client, $dispatcher, $logger);
4242
}
4343

44-
public function getName(): string
44+
public function __toString(): string
4545
{
4646
return sprintf('api://%s@mailgun?region=%s', $this->domain, $this->region);
4747
}

src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunHttpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(string $key, string $domain, string $region = null,
4040
parent::__construct($client, $dispatcher, $logger);
4141
}
4242

43-
public function getName(): string
43+
public function __toString(): string
4444
{
4545
return sprintf('http://%s@mailgun?region=%s', $this->domain, $this->region);
4646
}

src/Symfony/Component/Mailer/Bridge/Postmark/Transport/PostmarkApiTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3636
parent::__construct($client, $dispatcher, $logger);
3737
}
3838

39-
public function getName(): string
39+
public function __toString(): string
4040
{
4141
return sprintf('api://postmark');
4242
}

src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridTransportFactoryTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,9 @@ public function unsupportedSchemeProvider(): iterable
7676
'The "foo" scheme is not supported for mailer "sendgrid". Supported schemes are: "api", "smtp", "smtps".',
7777
];
7878
}
79+
80+
public function incompleteDsnProvider(): iterable
81+
{
82+
yield [new Dsn('api', 'sendgrid')];
83+
}
7984
}

src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
3737
parent::__construct($client, $dispatcher, $logger);
3838
}
3939

40-
public function getName(): string
40+
public function __toString(): string
4141
{
4242
return sprintf('api://sendgrid');
4343
}

src/Symfony/Component/Mailer/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CHANGELOG
1111
* Added PHPUnit constraints
1212
* Added `MessageDataCollector`
1313
* Added `MessageEvents` and `MessageLoggerListener` to allow collecting sent emails
14-
* [BC BREAK] `TransportInterface` has a new `getName()` method
14+
* [BC BREAK] `TransportInterface` has a new `__toString()` method
1515
* [BC BREAK] Classes `AbstractApiTransport` and `AbstractHttpTransport` moved under `Transport` sub-namespace.
1616
* [BC BREAK] Transports depend on `Symfony\Contracts\EventDispatcher\EventDispatcherInterface`
1717
instead of `Symfony\Component\EventDispatcher\EventDispatcherInterface`.

src/Symfony/Component/Mailer/Event/MessageEvent.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ final class MessageEvent extends Event
2424
{
2525
private $message;
2626
private $envelope;
27-
private $transportName;
27+
private $transport;
2828
private $queued;
2929

30-
public function __construct(RawMessage $message, SmtpEnvelope $envelope, string $transportName, bool $queued = false)
30+
public function __construct(RawMessage $message, SmtpEnvelope $envelope, string $transport, bool $queued = false)
3131
{
3232
$this->message = $message;
3333
$this->envelope = $envelope;
34-
$this->transportName = $transportName;
34+
$this->transport = $transport;
3535
$this->queued = $queued;
3636
}
3737

@@ -55,9 +55,9 @@ public function setEnvelope(SmtpEnvelope $envelope): void
5555
$this->envelope = $envelope;
5656
}
5757

58-
public function getTransportName(): string
58+
public function getTransport(): string
5959
{
60-
return $this->transportName;
60+
return $this->transport;
6161
}
6262

6363
public function isQueued(): bool

src/Symfony/Component/Mailer/Event/MessageEvents.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MessageEvents
2424
public function add(MessageEvent $event): void
2525
{
2626
$this->events[] = $event;
27-
$this->transports[$event->getTransportName()] = true;
27+
$this->transports[$event->getTransport()] = true;
2828
}
2929

3030
public function getTransports(): array
@@ -43,7 +43,7 @@ public function getEvents(string $name = null): array
4343

4444
$events = [];
4545
foreach ($this->events as $event) {
46-
if ($name === $event->getTransportName()) {
46+
if ($name === $event->getTransport()) {
4747
$events[] = $event;
4848
}
4949
}

src/Symfony/Component/Mailer/Mailer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): void
5454
throw new TransportException('Cannot send message without a valid envelope.', 0, $e);
5555
}
5656
}
57-
$event = new MessageEvent($message, $envelope, $this->transport->getName(), true);
57+
$event = new MessageEvent($message, $envelope, (string) $this->transport, true);
5858
$this->dispatcher->dispatch($event);
5959
}
6060

src/Symfony/Component/Mailer/Test/TransportFactoryTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testCreate(Dsn $dsn, TransportInterface $transport): void
7070

7171
$this->assertEquals($transport, $factory->create($dsn));
7272
if ('smtp' !== $dsn->getScheme() && 'smtps' !== $dsn->getScheme()) {
73-
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', $transport->getName());
73+
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', (string) $transport);
7474
}
7575
}
7676

src/Symfony/Component/Mailer/Tests/Transport/FailoverTransportTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public function testSendNoTransports()
2929
new FailoverTransport([]);
3030
}
3131

32-
public function testGetName()
32+
public function testToString()
3333
{
3434
$t1 = $this->createMock(TransportInterface::class);
35-
$t1->expects($this->once())->method('getName')->willReturn('t1://local');
35+
$t1->expects($this->once())->method('__toString')->willReturn('t1://local');
3636
$t2 = $this->createMock(TransportInterface::class);
37-
$t2->expects($this->once())->method('getName')->willReturn('t2://local');
37+
$t2->expects($this->once())->method('__toString')->willReturn('t2://local');
3838
$t = new FailoverTransport([$t1, $t2]);
39-
$this->assertEquals('t1://local || t2://local', $t->getName());
39+
$this->assertEquals('t1://local || t2://local', (string) $t);
4040
}
4141

4242
public function testSendFirstWork()

src/Symfony/Component/Mailer/Tests/Transport/NullTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
class NullTransportTest extends TestCase
1818
{
19-
public function testName()
19+
public function testToString()
2020
{
2121
$t = new NullTransport();
22-
$this->assertEquals('smtp://null', $t->getName());
22+
$this->assertEquals('smtp://null', (string) $t);
2323
}
2424
}

src/Symfony/Component/Mailer/Tests/Transport/RoundRobinTransportTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public function testSendNoTransports()
2828
new RoundRobinTransport([]);
2929
}
3030

31-
public function testGetName()
31+
public function testToString()
3232
{
3333
$t1 = $this->createMock(TransportInterface::class);
34-
$t1->expects($this->once())->method('getName')->willReturn('t1://local');
34+
$t1->expects($this->once())->method('__toString')->willReturn('t1://local');
3535
$t2 = $this->createMock(TransportInterface::class);
36-
$t2->expects($this->once())->method('getName')->willReturn('t2://local');
36+
$t2->expects($this->once())->method('__toString')->willReturn('t2://local');
3737
$t = new RoundRobinTransport([$t1, $t2]);
38-
$this->assertEquals('t1://local && t2://local', $t->getName());
38+
$this->assertEquals('t1://local && t2://local', (string) $t);
3939
}
4040

4141
public function testSendAlternate()

src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
class SendmailTransportTest extends TestCase
1818
{
19-
public function testName()
19+
public function testToString()
2020
{
2121
$t = new SendmailTransport();
22-
$this->assertEquals('smtp://sendmail', $t->getName());
22+
$this->assertEquals('smtp://sendmail', (string) $t);
2323
}
2424
}

src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@
1616

1717
class EsmtpTransportTest extends TestCase
1818
{
19-
public function testName()
19+
public function testToString()
2020
{
2121
$t = new EsmtpTransport();
22-
$this->assertEquals('smtp://localhost', $t->getName());
22+
$this->assertEquals('smtp://localhost', (string) $t);
2323

2424
$t = new EsmtpTransport('example.com');
2525
if (\defined('OPENSSL_VERSION_NUMBER')) {
26-
$this->assertEquals('smtps://example.com', $t->getName());
26+
$this->assertEquals('smtps://example.com', (string) $t);
2727
} else {
28-
$this->assertEquals('smtp://example.com', $t->getName());
28+
$this->assertEquals('smtp://example.com', (string) $t);
2929
}
3030

3131
$t = new EsmtpTransport('example.com', 2525);
32-
$this->assertEquals('smtp://example.com:2525', $t->getName());
32+
$this->assertEquals('smtp://example.com:2525', (string) $t);
3333

3434
$t = new EsmtpTransport('example.com', 0, true);
35-
$this->assertEquals('smtps://example.com', $t->getName());
35+
$this->assertEquals('smtps://example.com', (string) $t);
3636

3737
$t = new EsmtpTransport('example.com', 0, false);
38-
$this->assertEquals('smtp://example.com', $t->getName());
38+
$this->assertEquals('smtp://example.com', (string) $t);
3939

4040
$t = new EsmtpTransport('example.com', 466, true);
41-
$this->assertEquals('smtps://example.com:466', $t->getName());
41+
$this->assertEquals('smtps://example.com:466', (string) $t);
4242
}
4343
}

src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
class SmtpTransportTest extends TestCase
1919
{
20-
public function testName()
20+
public function testToString()
2121
{
2222
$t = new SmtpTransport();
23-
$this->assertEquals('smtps://localhost', $t->getName());
23+
$this->assertEquals('smtps://localhost', (string) $t);
2424

2525
$t = new SmtpTransport((new SocketStream())->setHost('127.0.0.1')->setPort(2525)->disableTls());
26-
$this->assertEquals('smtp://127.0.0.1:2525', $t->getName());
26+
$this->assertEquals('smtp://127.0.0.1:2525', (string) $t);
2727
}
2828
}

src/Symfony/Component/Mailer/Tests/TransportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
6969
throw new \BadMethodCallException('This method newer should be called.');
7070
}
7171

72-
public function getName(): string
72+
public function __toString(): string
7373
{
7474
return sprintf('dummy://local');
7575
}

src/Symfony/Component/Mailer/Transport/AbstractTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
6767
}
6868
}
6969

70-
$event = new MessageEvent($message, $envelope, $this->getName());
70+
$event = new MessageEvent($message, $envelope, (string) $this);
7171
$this->dispatcher->dispatch($event);
7272
$envelope = $event->getEnvelope();
7373
if (!$envelope->getRecipients()) {

src/Symfony/Component/Mailer/Transport/NullTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function doSend(SentMessage $message): void
2424
{
2525
}
2626

27-
public function getName(): string
27+
public function __toString(): string
2828
{
2929
return 'smtp://null';
3030
}

src/Symfony/Component/Mailer/Transport/RoundRobinTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
5656
throw new TransportException('All transports failed.');
5757
}
5858

59-
public function getName(): string
59+
public function __toString(): string
6060
{
6161
return implode(' '.$this->getNameSymbol().' ', array_map(function (TransportInterface $transport) {
62-
return $transport->getName();
62+
return (string) $transport;
6363
}, $this->transports));
6464
}
6565

src/Symfony/Component/Mailer/Transport/SendmailTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
7373
return parent::send($message, $envelope);
7474
}
7575

76-
public function getName(): string
76+
public function __toString(): string
7777
{
7878
if ($this->transport) {
79-
return $this->transport->getName();
79+
return (string) $this->transport;
8080
}
8181

8282
return 'smtp://sendmail';

src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
126126
return $message;
127127
}
128128

129-
public function getName(): string
129+
public function __toString(): string
130130
{
131131
if ($this->stream instanceof SocketStream) {
132132
$name = sprintf('smtp%s://%s', ($tls = $this->stream->isTLS()) ? 's' : '', $this->stream->getHost());

src/Symfony/Component/Mailer/Transport/TransportInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ interface TransportInterface
3131
*/
3232
public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentMessage;
3333

34-
public function getName(): string;
34+
public function __toString(): string;
3535
}

0 commit comments

Comments
 (0)