Skip to content

in2it/tdd-phone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phone number normalization using TDD

This repository is to show how one can normalize phone numbers using core PHP functionality.

1. The problem to solve

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.

2. Test-driven development

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.

  1. We write a base test to validate our hypothesis
  2. We write the code according to the hypothesis and make it pass
  3. We refactor the code and optionally the test to meet all our requirements

3. Done

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.

Tools used

  1. PHP 8.4
  2. 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.

About

Normalizing phone numbers with TDD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages