[Notifier] [BC BREAK] Change constructor signature for Mattermost and Esendex transport
This commit is contained in:
parent
4a053e5fed
commit
c5b9acf5d5
@ -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
|
||||
-----
|
||||
|
@ -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;
|
||||
|
||||
@ -41,7 +43,7 @@ final class EsendexTransport extends AbstractTransport
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf('esendex://%s', $this->getEndpoint());
|
||||
return sprintf('esendex://%s?accountreference=%s&from=%s', $this->getEndpoint(), $this->accountReference, $this->from);
|
||||
}
|
||||
|
||||
public function supports(MessageInterface $message): bool
|
||||
@ -65,18 +67,20 @@ final class EsendexTransport extends AbstractTransport
|
||||
}
|
||||
|
||||
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v1.0/messagedispatcher', [
|
||||
'auth_basic' => $this->token,
|
||||
'auth_basic' => sprintf('%s:%s', $this->email, $this->password),
|
||||
'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);
|
||||
|
@ -30,7 +30,8 @@ final class EsendexTransportFactory extends AbstractTransportFactory
|
||||
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) {
|
||||
@ -46,7 +47,7 @@ final class EsendexTransportFactory extends AbstractTransportFactory
|
||||
$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
|
||||
|
@ -25,7 +25,25 @@ final class EsendexTransportFactoryTest extends TestCase
|
||||
|
||||
$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()
|
||||
|
@ -27,7 +27,7 @@ final class EsendexTransportTest extends TestCase
|
||||
{
|
||||
$transport = $this->createTransport();
|
||||
|
||||
$this->assertSame('esendex://host.test', (string) $transport);
|
||||
$this->assertSame('esendex://host.test?accountreference=testAccountReference&from=testFrom', (string) $transport);
|
||||
}
|
||||
|
||||
public function testSupportsSmsMessage()
|
||||
@ -90,6 +90,6 @@ final class EsendexTransportTest extends TestCase
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,10 @@ CHANGELOG
|
||||
-----
|
||||
|
||||
* The bridge is not marked as `@experimental` anymore
|
||||
* [BC BREAK] Changed signature of `MattermostTransport::__construct()` method from:
|
||||
`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
|
||||
-----
|
||||
|
@ -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;
|
||||
|
@ -41,7 +41,7 @@ final class MattermostTransportFactory extends AbstractTransportFactory
|
||||
$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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user