This repository is to show how one can normalize phone numbers using core PHP functionality.
Taken a phone number 012 34 56 78, where 012 is the zone number and 34 56 78 is the subscription number, there are multiple ways this information is provided:
- 012 34 56 78
- 012/34.56.78
- (012) 345-678
- 00 32 12 34 56 78
- +3212345678
Without normalization, each varient might end up in the data persistency layer (database, CRM, files) and creates issues when searching for it, or displaying this information in different locales you might use.
The purpose of test-driven development is to focus on solving the problem at hand without the distractions of might haves or could be's.
- We write a base test to validate our hypothesis
- We write the code according to the hypothesis and make it pass
- We refactor the code and optionally the test to meet all our requirements
When all tests pass, it is safe to say the job is done.
If, for some reason we have missed an edge case where other notations are being used, we can add this edge case to tests and modify the code so it covers this edge case as well. And since we also cover the other cases, our tests will notify us if and when we break logic that was already solving a case.
- PHP 8.4
- PHPUnit 12.1
For PHPUnit I used the Phar package, which you can find at https://phar.phpunit.de, but it will also work with a Composer installation.