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

Skip to content

Commit 9db0f20

Browse files
committed
feature #37747 [Notifier] Make Freemobile config more flexible (fabpot)
This PR was merged into the 5.2-dev branch. Discussion ---------- [Notifier] Make Freemobile config more flexible | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a<!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a As Freemobile only supports French phone numbers, let's support French numbers without the international code. Commits ------- 4dfde6a [Notifier] Make Freemobile config more flexible
2 parents e43d6b3 + 4dfde6a commit 9db0f20

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/Symfony/Component/Notifier/Bridge/FreeMobile/FreeMobileTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(string $login, string $password, string $phone, Http
3737
{
3838
$this->login = $login;
3939
$this->password = $password;
40-
$this->phone = $phone;
40+
$this->phone = str_replace('+33', '0', $phone);
4141

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

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

5555
protected function doSend(MessageInterface $message): SentMessage

src/Symfony/Component/Notifier/Bridge/FreeMobile/Tests/FreeMobileTransportTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,37 @@ final class FreeMobileTransportTest extends TestCase
2222
{
2323
public function testToStringContainsProperties(): void
2424
{
25-
$transport = $this->initTransport();
25+
$transport = $this->getTransport('0611223344');
2626

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

3030
public function testSupportsMessageInterface(): void
3131
{
32-
$transport = $this->initTransport();
32+
$transport = $this->getTransport('0611223344');
3333

3434
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
35+
$this->assertTrue($transport->supports(new SmsMessage('+33611223344', 'Hello!')));
3536
$this->assertFalse($transport->supports(new SmsMessage('0699887766', 'Hello!')));
3637
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class), 'Hello!'));
38+
39+
$transport = $this->getTransport('+33611223344');
40+
41+
$this->assertTrue($transport->supports(new SmsMessage('0611223344', 'Hello!')));
42+
$this->assertTrue($transport->supports(new SmsMessage('+33611223344', 'Hello!')));
3743
}
3844

3945
public function testSendNonSmsMessageThrowsException(): void
4046
{
41-
$transport = $this->initTransport();
47+
$transport = $this->getTransport('0611223344');
4248

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

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

48-
private function initTransport(): FreeMobileTransport
54+
private function getTransport(string $phone): FreeMobileTransport
4955
{
50-
return (new FreeMobileTransport(
51-
'login', 'pass', '0611223344', $this->createMock(HttpClientInterface::class)
52-
))->setHost('host.test');
56+
return (new FreeMobileTransport('login', 'pass', $phone, $this->createMock(HttpClientInterface::class)))->setHost('host.test');
5357
}
5458
}

0 commit comments

Comments
 (0)