diff --git a/src/Bundle/ChillMainBundle/Tests/Phonenumber/PhonenumberHelperTest.php b/src/Bundle/ChillMainBundle/Tests/Phonenumber/PhonenumberHelperTest.php new file mode 100644 index 000000000..606fe13e3 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Phonenumber/PhonenumberHelperTest.php @@ -0,0 +1,148 @@ + [ + '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', + ]; + } +} diff --git a/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php b/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php index f04b8cc52..9620f7cb9 100644 --- a/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php +++ b/src/Bundle/ChillMainBundle/Validation/Validator/ValidPhonenumber.php @@ -37,15 +37,13 @@ final class ValidPhonenumber extends ConstraintValidator */ public function validate($value, Constraint $constraint) { - dump($value); - if (false === $this->phonenumberHelper->isPhonenumberValidationConfigured()) { $this->logger->debug('[phonenumber] skipping validation due to not configured helper'); return; } - if (empty($value)) { + if ('' === $value) { return; } diff --git a/tests/app b/tests/app index 0fef0f216..8d4a020ba 160000 --- a/tests/app +++ b/tests/app @@ -1 +1 @@ -Subproject commit 0fef0f21602989ed3aa6b301080ae406d71dd632 +Subproject commit 8d4a020ba2b824ac94fee53cf9df3935d9f449bf