Skip to content

[Notifier] Make Freemobile config more flexible #37747

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
Aug 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(string $login, string $password, string $phone, Http
{
$this->login = $login;
$this->password = $password;
$this->phone = $phone;
$this->phone = str_replace('+33', '0', $phone);

parent::__construct($client, $dispatcher);
}
Expand All @@ -49,7 +49,7 @@ public function __toString(): string

public function supports(MessageInterface $message): bool
{
return $message instanceof SmsMessage && $this->phone === $message->getPhone();
return $message instanceof SmsMessage && $this->phone === str_replace('+33', '0', $message->getPhone());
}

protected function doSend(MessageInterface $message): SentMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,37 @@ final class FreeMobileTransportTest extends TestCase
{
public function testToStringContainsProperties(): void
{
$transport = $this->initTransport();
$transport = $this->getTransport('0611223344');

$this->assertSame('freemobile://host.test?phone=0611223344', (string) $transport);
}

public function testSupportsMessageInterface(): void
{
$transport = $this->initTransport();
$transport = $this->getTransport('0611223344');

$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
$this->assertTrue($transport->supports(new SmsMessage('+33611223344', 'Hello!')));
$this->assertFalse($transport->supports(new SmsMessage('0699887766', 'Hello!')));
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class), 'Hello!'));

$transport = $this->getTransport('+33611223344');

$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
$this->assertTrue($transport->supports(new SmsMessage('+33611223344', 'Hello!')));
}

public function testSendNonSmsMessageThrowsException(): void
{
$transport = $this->initTransport();
$transport = $this->getTransport('0611223344');

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

$transport->send(new SmsMessage('0699887766', 'Hello!'));
}

private function initTransport(): FreeMobileTransport
private function getTransport(string $phone): FreeMobileTransport
{
return (new FreeMobileTransport(
'login', 'pass', '0611223344', $this->createMock(HttpClientInterface::class)
))->setHost('host.test');
return (new FreeMobileTransport('login', 'pass', $phone, $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
}