spoorsny / php-south-african-id

A self-validating value object encapsulating a South African government-issued personal identification number.
https://packagist.org/packages/spoorsny/south-african-id
GNU General Public License v3.0
0 stars 0 forks source link

Add explicit test for or explain in comment usage of null byte in nonnumeric strings test data provider #14

Closed geoffreyvanwyk closed 3 months ago

geoffreyvanwyk commented 3 months ago

I have added a test data point containing a null byte to the nonnumericStrings data provider method to cover the case of a null byte passed to DateTime::createFromFormat in \Spoorsny\ValueObjects\SouthAfricanId::assertStartsWithDate() method. DateTime::createFromFormat raises a ValueError in case a null byte is passed to it. Using a try-catch in assertStartsWithDate to cover that condition is never covered completely by tests, because the null byte is always detected by assertIsNumeric firstly. A comment needs to be added to the data provider method to explain that.

A separate explit test could use a null byte in the date segment, then assert that the exception message thrown by the test for nonnumeric strings is received.