Skip to content

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

Closed
@Aerendir

Description

@Aerendir

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions