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

Not able to match @null@||@array@ (again) #471

Closed
Aerendir opened this issue Nov 27, 2023 · 4 comments · Fixed by #493
Closed

Not able to match @null@||@array@ (again) #471

Aerendir opened this issue Nov 27, 2023 · 4 comments · Fixed by #493
Labels

Comments

@Aerendir
Copy link

Aerendir commented Nov 27, 2023

There is already a closed issue that reports my same exact problem:

My array structure is almost this:

{
    "@context": "\/api\/contexts\/MyClass",
    "@id": "\/api\/myclasses\/2",
    "hydra:member": [
        {
            "id": 1,
            "my_key": {
                "key1": "EUR",
                "key2": 0.22
            }
        }
    ]
}

my_key can also be null:

{
    "@context": "\/api\/contexts\/MyClass",
    "@id": "\/api\/myclasses\/2",
    "hydra:member": [
        {
            "id": 1,
            "my_key": null
        }
    ]
}

So, to validate this structure, I use this pattern:

[
                '@context'         => '/{app_api_entrypoint}/contexts/' . StringHelper::getClassBaseName(Item::class),
                '@id'              => '/{app_api_entrypoint}{api_endpoint}',
                '@type'            => 'hydra:Collection',
                'hydra:totalItems' => AbstractItemsFixture::COUNT_TOTAL_IN_ACCOUNT,
                'hydra:member'     => [
                    [
                        '@id' => '@string@',
                        'my_key' => '@array@ || @null@',
...

This validation does not pass:

Failed asserting that Value "Array(2)" does not match pattern "[hydra:member][0]" at path: "[hydra:member][0][my_key]".

Am I doing it wrong or is it actually a bug?

@Aerendir Aerendir changed the title Not able to match @null@||@array@ (again) Not able to match @null@||@array@ (again) Nov 27, 2023
@norberttech
Copy link
Member

Hey @Aerendir it looks like a bug. It seems that or condition is not handled properly and it's failing whenever the first check fails.

@Aerendir
Copy link
Author

Aerendir commented Dec 1, 2023

I don't know... I tried to debug, but I'm not so used to the library, so I didn't had a good result...

Anyway, the live sandbox is very useful!

You should put it in a template for GitHub when opening a bug issue, asking to reproduce the problem...

@norberttech
Copy link
Member

You should put it in a template for GitHub when opening a bug issue, asking to reproduce the problem...

Done!

@GeLoLabs
Copy link
Contributor

GeLoLabs commented Oct 3, 2024

The issue comes from the "MatcherFactory", it builds an "ArrayMatcher" which uses an "OrMatcher" which don't use any "ArrayMatcher" in its chain and so this "OrMatcher" (which is different from the one used by the main matcher) is not able to match "@array@" (see https://github.com/coduo/php-matcher/blob/6.x/src/Factory/MatcherFactory.php#L52)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants