This commit is contained in:
Pol Dellaiera
2022-02-22 11:10:54 +01:00
parent 68a64aa67f
commit e1b3719746
3 changed files with 150 additions and 4 deletions

View File

@@ -0,0 +1,148 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Tests\Routing\Loader;
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
use Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
final class PhonenumberHelperTest extends KernelTestCase
{
/**
* @dataProvider normalizePhonenumbers
*/
public function testNormalizePhonenumbers(string $defaultCarrierCode, string $phoneNumber, string $expected)
{
$subject = new PhonenumberHelper(
new ArrayAdapter(),
new ParameterBag([
'chill_main.phone_helper' => [
'default_carrier_code' => $defaultCarrierCode,
],
]),
new NullLogger()
);
$this->assertEquals($expected, $subject->normalize($phoneNumber));
}
/**
* @dataProvider denormalizePhonenumbers
*/
public function testDenormalizePhonenumbers(string $defaultCarrierCode, string $phoneNumber, string $expected)
{
$subject = new PhonenumberHelper(
new ArrayAdapter(),
new ParameterBag([
'chill_main.phone_helper' => [
'default_carrier_code' => $defaultCarrierCode,
],
]),
new NullLogger()
);
$this->assertEquals($expected, $subject->denormalize($phoneNumber));
}
/**
* @dataProvider formatPhonenumbers
*/
public function testFormatPhonenumbers(string $defaultCarrierCode, string $phoneNumber, string $expected)
{
$subject = new PhonenumberHelper(
new ArrayAdapter(),
new ParameterBag([
'chill_main.phone_helper' => [
'default_carrier_code' => $defaultCarrierCode,
],
]),
new NullLogger()
);
$this->assertEquals($expected, $subject->format($phoneNumber));
}
public function formatPhonenumbers() {
yield [
'BE',
'+3281136917',
'081 13 69 17',
];
yield [
'FR',
'+33 6 23 12 45 54',
'06 23 12 45 54',
];
yield [
'FR',
'+32 81 13 69 17',
'081 13 69 17',
];
yield [
'BE',
'+33 6 23 12 45 54',
'06 23 12 45 54',
];
}
public function normalizePhonenumbers() {
yield [
'BE',
'081136917',
'+3281136917',
];
yield [
'BE',
'003281136917',
'+3281136917',
];
yield [
'BE',
'0032478123456',
'+32478123456',
];
yield [
'BE',
'0478123456',
'+32478123456',
];
yield [
'FR',
'0623124554',
'+33623124554',
];
}
public function denormalizePhonenumbers() {
yield [
'BE',
'+3281136917',
'+3281136917',
];
yield [
'BE',
'+33 6 23 12 45 54',
'+33623124554',
];
}
}