Skip to content

Validator object appears to keep its validation status #385

Closed
@CMCDragonkai

Description

@CMCDragonkai

I'm using 5.1 version.

<?php

use JsonSchema\Validator;

$validator = new Validator;

$data = (object)['key' => true];

$validator->validate(
    $data,
    (object)[
        'type' => 'object',
        'properties' => (object)[
            'key' => (object)[
                'type' => 'boolean'
            ]
        ]
    ]
);

var_dump($validator->isValid()); // true

$data = ['key' => true];

$validator->validate(
    $data,
    (object)[
        'type' => 'object',
        'properties' => (object)[
            'key' => (object)[
                'type' => 'boolean'
            ]
        ]
    ]
);

var_dump($validator->isValid()); // false


$data = (object)['key' => true];

$validator->validate(
    $data,
    (object)[
        'type' => 'object',
        'properties' => (object)[
            'key' => (object)[
                'type' => 'boolean'
            ]
        ]
    ]
);

var_dump($validator->isValid()); // false but should be true

There should be a way to clear the Validator status? Or that subsequent invocations of validate should not keep the original validation status.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions