Closed SLourenco closed 4 years ago
Thank you very very much!
You ended up exposing a problem in our Validation algorithm tests. Our assertions were:
public function test_validation_behaviour(): void
{
foreach ($this->validIds as $id) {
$this->assertTrue(
Socrates::validateId($id, 'PT')
);
}
// Here be dragons...
$this->expectException(InvalidLengthException::class);
Socrates::validateId('11084129 8 ZX', 'PT');
// Everything here passes...
$this->assertFalse(
Socrates::validateId('14897475 4 ZY5', 'PT')
);
}
Not only some countries test for a single invalid ID - which isn't ideal - but even those that test with multiple of those have that same problem.
I went ahead and changed the order of assertions and also made it test against an array of Invalid IDs:
public function test_validation_behaviour(): void
{
foreach ($this->validIds as $id) {
$this->assertTrue(
Socrates::validateId($id, 'PT')
);
}
foreach ($this->invalidIds as $invalidId) {
$this->assertFalse(
Socrates::validateId($invalidId, 'PT')
);
}
$this->expectException(InvalidLengthException::class);
Socrates::validateId('11084129 8 ZX', 'PT');
}
Also, I opened an issue #59 for us to go ahead and fix our test suite. Sounds like a new release is in order @JoaoFSCruz
The Portugal validation algorithm has a bug in an if code block that is never run. In
the
$toggleDigit
is initialized to false and is not modified outside of the if statement, which depends on it being true to run.