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

Skip to content

Commit ec9ed2f

Browse files
committed
feature #39592 [Notifier] [BC BREAK] Change constructor signature for Mattermost and Esendex transport (OskarStark)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [Notifier] [BC BREAK] Change constructor signature for Mattermost and Esendex transport | 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 Commits ------- c5b9acf [Notifier] [BC BREAK] Change constructor signature for Mattermost and Esendex transport
2 parents df5dcc3 + c5b9acf commit ec9ed2f

9 files changed

+46
-15
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:[email protected]?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
}

src/Symfony/Component/Notifier/Bridge/Mattermost/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 `MattermostTransport::__construct()` method from:
9+
`public function __construct(string $token, string $channel, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, string $path = null)`
10+
to:
11+
`public function __construct(string $token, string $channel, ?string $path = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
812

913
5.1.0
1014
-----

src/Symfony/Component/Notifier/Bridge/Mattermost/MattermostTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class MattermostTransport extends AbstractTransport
2929
private $channel;
3030
private $path;
3131

32-
public function __construct(string $token, string $channel, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, string $path = null)
32+
public function __construct(string $token, string $channel, ?string $path = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3333
{
3434
$this->token = $token;
3535
$this->channel = $channel;

src/Symfony/Component/Notifier/Bridge/Mattermost/MattermostTransportFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function create(Dsn $dsn): TransportInterface
4141
$host = $dsn->getHost();
4242
$port = $dsn->getPort();
4343

44-
return (new MattermostTransport($token, $channel, $this->client, $this->dispatcher, $path))->setHost($host)->setPort($port);
44+
return (new MattermostTransport($token, $channel, $path, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
4545
}
4646

4747
protected function getSupportedSchemes(): array

src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class MattermostTransportTest extends TransportTestCase
2929
*/
3030
public function createTransport(?HttpClientInterface $client = null): TransportInterface
3131
{
32-
return (new MattermostTransport('testAccessToken', 'testChannel', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
32+
return (new MattermostTransport('testAccessToken', 'testChannel', null, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
3333
}
3434

3535
public function toStringProvider(): iterable

0 commit comments

Comments
 (0)