Skip to content

Commit 8da8f82

Browse files
committed
[Mailer] Renamed getName() to toString()
1 parent 8b21225 commit 8da8f82

18 files changed

+42
-42
lines changed

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`.

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

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
}

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

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

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()

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
}

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()

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
}

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
}

0 commit comments

Comments
 (0)