Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix & standardize Validation tests across all countries #59

Closed
AlexOlival opened this issue Jun 11, 2020 · 1 comment · Fixed by #64
Closed

Fix & standardize Validation tests across all countries #59

AlexOlival opened this issue Jun 11, 2020 · 1 comment · Fixed by #64
Labels
bug Something isn't working good first issue Good for newcomers
Milestone

Comments

@AlexOlival
Copy link
Collaborator

AlexOlival commented Jun 11, 2020

This problem was found thanks to #57:

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.

The correct order of assertions should be:

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');
}

So we need to ahead and fix these tests for all countries.

@AlexOlival AlexOlival added bug Something isn't working good first issue Good for newcomers labels Jun 11, 2020
@AlexOlival
Copy link
Collaborator Author

As an addendum, it is slightly odd that we didn't find this problem before....

Validators were mostly implemented following the TDD logic, and with invalid IDs being tested against the algorithm as it was being developed.
I guess that as we try to tackle this, we will find out if there was something wrong with the test itself, or if it is a more insidious problem related to the environment...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant