Skip to content

Commit 270e64d

Browse files
committed
[Notifier] [Esendex] [BC BREAK] Change constructor signature
| Q | A | ------------- | --- | Branch? | 5.x, but BC BREAK for experimental bridge | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | --- | License | MIT | Doc PR | --- Based on #39428 (comment) cc @odolbeau as you provided the bridge
1 parent 4a053e5 commit 270e64d

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ CHANGELOG
55
-----
66

77
* The bridge is not marked as `@experimental` anymore
8+
* [BC BREAK] Changed signature of `EsendexTransport::__construct()` method from:
9+
`public function __construct(string $token, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
10+
to:
11+
`public function __construct(string $email, string $password, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
812

913
5.2.0
1014
-----

src/Symfony/Component/Notifier/Bridge/Esendex/EsendexTransport.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ final class EsendexTransport extends AbstractTransport
2626
{
2727
protected const HOST = 'api.esendex.com';
2828

29-
private $token;
29+
private $email;
30+
private $password;
3031
private $accountReference;
3132
private $from;
3233

33-
public function __construct(string $token, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
34+
public function __construct(string $email, string $password, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3435
{
35-
$this->token = $token;
36+
$this->email = $email;
37+
$this->password = $password;
3638
$this->accountReference = $accountReference;
3739
$this->from = $from;
3840

@@ -41,7 +43,7 @@ public function __construct(string $token, string $accountReference, string $fro
4143

4244
public function __toString(): string
4345
{
44-
return sprintf('esendex://%s', $this->getEndpoint());
46+
return sprintf('esendex://%s?accountreference=%s&from=%s', $this->getEndpoint(), $this->accountReference, $this->from);
4547
}
4648

4749
public function supports(MessageInterface $message): bool
@@ -65,18 +67,20 @@ protected function doSend(MessageInterface $message): SentMessage
6567
}
6668

6769
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v1.0/messagedispatcher', [
68-
'auth_basic' => $this->token,
70+
'auth_basic' => sprintf('%s:%s', $this->email, $this->password),
6971
'json' => [
7072
'accountreference' => $this->accountReference,
7173
'messages' => [$messageData],
7274
],
7375
]);
7476

75-
if (200 === $response->getStatusCode()) {
77+
$statusCode = $response->getStatusCode();
78+
79+
if (200 === $statusCode) {
7680
return new SentMessage($message, (string) $this);
7781
}
7882

79-
$message = sprintf('Unable to send the SMS: error %d.', $response->getStatusCode());
83+
$message = sprintf('Unable to send the SMS: error %d.', $statusCode);
8084

8185
try {
8286
$result = $response->toArray(false);

src/Symfony/Component/Notifier/Bridge/Esendex/EsendexTransportFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public function create(Dsn $dsn): TransportInterface
3030
throw new UnsupportedSchemeException($dsn, 'esendex', $this->getSupportedSchemes());
3131
}
3232

33-
$token = $this->getUser($dsn).':'.$this->getPassword($dsn);
33+
$email = $this->getUser($dsn);
34+
$password = $this->getPassword($dsn);
3435
$accountReference = $dsn->getOption('accountreference');
3536

3637
if (!$accountReference) {
@@ -46,7 +47,7 @@ public function create(Dsn $dsn): TransportInterface
4647
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
4748
$port = $dsn->getPort();
4849

49-
return (new EsendexTransport($token, $accountReference, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
50+
return (new EsendexTransport($email, $password, $accountReference, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
5051
}
5152

5253
protected function getSupportedSchemes(): array

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,25 @@ public function testCreateWithDsn()
2525

2626
$transport = $factory->create(Dsn::fromString('esendex://email:password@host.test?accountreference=testAccountreference&from=testFrom'));
2727

28-
$this->assertSame('esendex://host.test', (string) $transport);
28+
$this->assertSame('esendex://host.test?accountreference=testAccountreference&from=testFrom', (string) $transport);
29+
}
30+
31+
public function testCreateWithMissingEmailThrowsIncompleteDsnException()
32+
{
33+
$factory = $this->createFactory();
34+
35+
$this->expectException(IncompleteDsnException::class);
36+
37+
$factory->create(Dsn::fromString('esendex://:password@host?accountreference=testAccountreference&from=FROM'));
38+
}
39+
40+
public function testCreateWithMissingPasswordThrowsIncompleteDsnException()
41+
{
42+
$factory = $this->createFactory();
43+
44+
$this->expectException(IncompleteDsnException::class);
45+
46+
$factory->create(Dsn::fromString('esendex://email:@host?accountreference=testAccountreference&from=FROM'));
2947
}
3048

3149
public function testCreateWithMissingOptionAccountreferenceThrowsIncompleteDsnException()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testToString()
2727
{
2828
$transport = $this->createTransport();
2929

30-
$this->assertSame('esendex://host.test', (string) $transport);
30+
$this->assertSame('esendex://host.test?accountreference=testAccountReference&from=testFrom', (string) $transport);
3131
}
3232

3333
public function testSupportsSmsMessage()
@@ -90,6 +90,6 @@ public function testSendWithErrorResponseContainingDetailsThrows()
9090

9191
private function createTransport(?HttpClientInterface $client = null): EsendexTransport
9292
{
93-
return (new EsendexTransport('testToken', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
93+
return (new EsendexTransport('testEmail', 'testPassword', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
9494
}
9595
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy