Skip to content

Validator throw a ValidationFailed exception when validateObject is used even if object is valid #2131

@tux-eithel

Description

@tux-eithel

Tempest version

3.10

PHP version

8.5

Operating system

Linux

Description

Hi!
The method validateObject defined here
https://github.com/tempestphp/tempest-framework/blob/3.x/packages/validation/src/Validator.php#L39-L58, will always throw an exception because this condition https://github.com/tempestphp/tempest-framework/blob/3.x/packages/validation/src/Validator.php#L55 is always true.

This test simple test fails:

    public function test_validate_passes_with_valid_object(): void
    {
        $this->validator->validateObject(new ObjectToBeValidated(name: 'ab'));

        $this->expectNotToPerformAssertions();
    }

In addition, when an exception is thrown, the property ValidationFailed->$targetClass is not set and for each rule which validation failed ($failingRules), FaillingRule->$field is null.

I know it's a not document method validateObject, but I was trying to use anyway, and I found the bug. If it's something internal, please ignore this Bug Report.

I'll try to open also a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions