Skip to content

[Notifier] [BC BREAK] Change constructor signature for Mattermost and Esendex transport #39592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CHANGELOG
-----

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

5.2.0
-----
Expand Down
18 changes: 11 additions & 7 deletions src/Symfony/Component/Notifier/Bridge/Esendex/EsendexTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ final class EsendexTransport extends AbstractTransport
{
protected const HOST = 'api.esendex.com';

private $token;
private $email;
private $password;
private $accountReference;
private $from;

public function __construct(string $token, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
public function __construct(string $email, string $password, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
{
$this->token = $token;
$this->email = $email;
$this->password = $password;
$this->accountReference = $accountReference;
$this->from = $from;

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

public function __toString(): string
{
return sprintf('esendex://%s', $this->getEndpoint());
return sprintf('esendex://%s?accountreference=%s&from=%s', $this->getEndpoint(), $this->accountReference, $this->from);
Copy link
Contributor Author

@OskarStark OskarStark Dec 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also updated the __toString() method to display accountreference and from, like in the other bridges

}

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

$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v1.0/messagedispatcher', [
'auth_basic' => $this->token,
'auth_basic' => sprintf('%s:%s', $this->email, $this->password),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, this was assembled in the factory

'json' => [
'accountreference' => $this->accountReference,
'messages' => [$messageData],
],
]);

if (200 === $response->getStatusCode()) {
$statusCode = $response->getStatusCode();

if (200 === $statusCode) {
return new SentMessage($message, (string) $this);
}

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

try {
$result = $response->toArray(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function create(Dsn $dsn): TransportInterface
throw new UnsupportedSchemeException($dsn, 'esendex', $this->getSupportedSchemes());
}

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

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

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

protected function getSupportedSchemes(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,25 @@ public function testCreateWithDsn()

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

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

public function testCreateWithMissingEmailThrowsIncompleteDsnException()
{
$factory = $this->createFactory();

$this->expectException(IncompleteDsnException::class);

$factory->create(Dsn::fromString('esendex://:password@host?accountreference=testAccountreference&from=FROM'));
}

public function testCreateWithMissingPasswordThrowsIncompleteDsnException()
{
$factory = $this->createFactory();

$this->expectException(IncompleteDsnException::class);

$factory->create(Dsn::fromString('esendex://email:@host?accountreference=testAccountreference&from=FROM'));
}

public function testCreateWithMissingOptionAccountreferenceThrowsIncompleteDsnException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testToString()
{
$transport = $this->createTransport();

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

public function testSupportsSmsMessage()
Expand Down Expand Up @@ -90,6 +90,6 @@ public function testSendWithErrorResponseContainingDetailsThrows()

private function createTransport(?HttpClientInterface $client = null): EsendexTransport
{
return (new EsendexTransport('testToken', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
return (new EsendexTransport('testEmail', 'testPassword', 'testAccountReference', 'testFrom', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
}
4 changes: 4 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/Mattermost/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CHANGELOG
-----

* The bridge is not marked as `@experimental` anymore
* [BC BREAK] Changed signature of `MattermostTransport::__construct()` method from:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

`public function __construct(string $token, string $channel, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, string $path = null)`
to:
`public function __construct(string $token, string $channel, ?string $path = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`

5.1.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class MattermostTransport extends AbstractTransport
private $channel;
private $path;

public function __construct(string $token, string $channel, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, string $path = null)
public function __construct(string $token, string $channel, ?string $path = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
{
$this->token = $token;
$this->channel = $channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function create(Dsn $dsn): TransportInterface
$host = $dsn->getHost();
$port = $dsn->getPort();

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

protected function getSupportedSchemes(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class MattermostTransportTest extends TransportTestCase
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
{
return (new MattermostTransport('testAccessToken', 'testChannel', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
return (new MattermostTransport('testAccessToken', 'testChannel', null, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}

public function toStringProvider(): iterable
Expand Down