[Notifier] [Free Mobile] Could not use custom host in DSN

This commit is contained in:
Oskar Stark 2020-12-15 11:26:26 +01:00
parent 3a3b2498fd
commit 63350cc19b
3 changed files with 9 additions and 6 deletions

View File

@ -26,7 +26,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
*/ */
final class FreeMobileTransport extends AbstractTransport final class FreeMobileTransport extends AbstractTransport
{ {
protected const HOST = 'https://smsapi.free-mobile.fr/sendmsg'; protected const HOST = 'smsapi.free-mobile.fr/sendmsg';
private $login; private $login;
private $password; private $password;
@ -57,7 +57,9 @@ final class FreeMobileTransport extends AbstractTransport
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given) and configured with your phone number.', __CLASS__, SmsMessage::class, \get_class($message))); throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given) and configured with your phone number.', __CLASS__, SmsMessage::class, \get_class($message)));
} }
$response = $this->client->request('POST', $this->getEndpoint(), [ $endpoint = sprintf('https://%s', $this->getEndpoint());
$response = $this->client->request('POST', $endpoint, [
'json' => [ 'json' => [
'user' => $this->login, 'user' => $this->login,
'pass' => $this->password, 'pass' => $this->password,

View File

@ -43,7 +43,10 @@ final class FreeMobileTransportFactory extends AbstractTransportFactory
throw new IncompleteDsnException('Missing phone.', $dsn->getOriginalDsn()); throw new IncompleteDsnException('Missing phone.', $dsn->getOriginalDsn());
} }
return new FreeMobileTransport($login, $password, $phone, $this->client, $this->dispatcher); $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();
return (new FreeMobileTransport($login, $password, $phone, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
} }
protected function getSupportedSchemes(): array protected function getSupportedSchemes(): array

View File

@ -23,9 +23,7 @@ final class FreeMobileTransportFactoryTest extends TestCase
{ {
$factory = $this->createFactory(); $factory = $this->createFactory();
$dsn = 'freemobile://login:pass@default?phone=0611223344'; $transport = $factory->create(Dsn::fromString('freemobile://login:pass@host.test?phone=0611223344'));
$transport = $factory->create(Dsn::fromString($dsn));
$transport->setHost('host.test');
$this->assertSame('freemobile://host.test?phone=0611223344', (string) $transport); $this->assertSame('freemobile://host.test?phone=0611223344', (string) $transport);
} }