Skip to content

Commit 767e498

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 symfony#39428 (comment) * [ ] Update recipe * [ ] Update documentation cc @odolbeau as you provided the bridge
1 parent 44e98db commit 767e498

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
CHANGELOG
22
=========
33

4+
5.3.0
5+
-----
6+
7+
* [BC BREAK] Changed signature of `EsendexTransport::__construct()` method from:
8+
`public function __construct(string $token, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
9+
to:
10+
`public function __construct(string $email, string $password, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
11+
412
5.2.0
513
-----
614

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

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

32-
private $token;
32+
private $email;
33+
private $password;
3334
private $accountReference;
3435
private $from;
3536

36-
public function __construct(string $token, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
37+
public function __construct(string $email, string $password, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3738
{
38-
$this->token = $token;
39+
$this->email = $email;
40+
$this->password = $password;
3941
$this->accountReference = $accountReference;
4042
$this->from = $from;
4143

@@ -44,7 +46,7 @@ public function __construct(string $token, string $accountReference, string $fro
4446

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

5052
public function supports(MessageInterface $message): bool
@@ -68,18 +70,20 @@ protected function doSend(MessageInterface $message): SentMessage
6870
}
6971

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

78-
if (200 === $response->getStatusCode()) {
80+
$statusCode = $response->getStatusCode();
81+
82+
if (200 === $statusCode) {
7983
return new SentMessage($message, (string) $this);
8084
}
8185

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

8488
try {
8589
$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
@@ -33,7 +33,8 @@ public function create(Dsn $dsn): TransportInterface
3333
throw new UnsupportedSchemeException($dsn, 'esendex', $this->getSupportedSchemes());
3434
}
3535

36-
$token = $this->getUser($dsn).':'.$this->getPassword($dsn);
36+
$email = $this->getUser($dsn);
37+
$password = $this->getPassword($dsn);
3738
$accountReference = $dsn->getOption('accountreference');
3839

3940
if (!$accountReference) {
@@ -49,7 +50,7 @@ public function create(Dsn $dsn): TransportInterface
4950
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
5051
$port = $dsn->getPort();
5152

52-
return (new EsendexTransport($token, $accountReference, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
53+
return (new EsendexTransport($email, $password, $accountReference, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
5354
}
5455

5556
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: 1 addition & 1 deletion
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()

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