Respect / Validation

The most awesome validation engine ever created for PHP
https://respect-validation.readthedocs.io
MIT License
5.75k stars 774 forks source link

Increase code coverage #1456

Closed dcorrea777 closed 2 months ago

dcorrea777 commented 2 months ago

Hey everyone,

I'm looking to get back into contributing to the project and I've been checking out the roadmap for version 3.0. I want to start by increasing the code coverage, but I ran into a few questions.

I've been adding some exception tests using phpt, but I got stuck on the Base rule test. This rule throws an exception called InvalidRuleConstructorException. However, it seems like this exception isn't being caught by the exceptionMessage and exceptionFullMessage functions. Am I doing something wrong?

dcorrea777 commented 2 months ago

I think I've found the right way to do exception testing, I can follow phpunit itself, correct?

Example:

#[Test]
public function itShouldThrowsExceptionWhenBaseIsNotValid(): void
{
    $this->expectException(InvalidRuleConstructorException::class);
    $this->expectExceptionMessage('a base between 1 and 62 is required');

    (new Base(63))->evaluate('011010001');
}
henriquemoody commented 2 months ago

Hey hey! 👋

I've commented on #1457 that it's best not to include the call to the evaluate() method because it gives the impression that the exception is thrown from that method and not from the Rule's constructor.

dcorrea777 commented 2 months ago

Thanks for the reply @henriquemoody