Skip to content

Bug where empty arrays [] are treated as null when running the following assertion in PEST. It seems like the enum_value function is internally calling a transform function which then converts the [] value to null. #53180

@crynobone

Description

@crynobone
          Just updated to Laravel 11.28. After running some tests in my application I noticed that this PR introduces an issue where empty arrays `[]` are treated as `null` when running the following assertion in PEST. It seems like the `enum_value` function is internally calling a `transform` function which then converts the `[]` value to `null`.
use Illuminate\Testing\Fluent\AssertableJson;

->assertJson(fn (AssertableJson $json) => $json->whereType('id', 'string')
    ->where('object', 'menu')
    ->where('name', 'Primary')
    ->where('handle', 'primary')
    ->has('items', 2)
    ->has('items.0', fn (AssertableJson $json) => $json->whereType('id', 'string')
        ->where('object', 'menu_item')
        ->where('label', 'Home')
        ->where('url', '/')
        ->where('active', true)
        ->where('opens_new_tab', false)
        ->where('items', []) // Issue occurs here
        ->where('order', 0)
        ->etc()
    )
    ->has('items.1.items.0', fn (AssertableJson $json) => $json->whereType('id', 'string')
        ->where('object', 'menu_item')
        ->where('label', 'Payments')
        ->where('url', '/payments')
        ->where('active', true)
        ->where('opens_new_tab', false)
        ->where('items', []) // Issue occurs here
        ->where('order', 0)
        ->etc()
    )
    ->etc()
);

This check will return the following error:

Property [items.0.items] does not match the expected value.
Failed asserting that Array &0 [] is identical to null.

Originally posted by @jayan-blutui in #53096 (comment)

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