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

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

Closed
crynobone opened this issue Oct 16, 2024 · 2 comments · Fixed by #53181
Labels

Comments

@crynobone
Copy link
Member

          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)

@crynobone crynobone added the bug label Oct 16, 2024
crynobone added a commit that referenced this issue Oct 16, 2024
only empty string

fixes #53180

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@twarkie
Copy link

twarkie commented Oct 16, 2024

Same problem here!

11.27
Illuminate\Support\Js::from([]) => []

11.28
Illuminate\Support\Js::from([]) => null

@ThomasEnssner
Copy link

Same problem with @js([]) as it uses Illuminate\Support\Js::from([])

taylorotwell pushed a commit that referenced this issue Oct 16, 2024
…stead of only empty string (#53181)

* [11.x] Handle empty values passed to `enum_value()` function instead of
only empty string

fixes #53180

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants