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

[11.x] Add Illuminate\Support\enum_value to resolve BackedEnum or UnitEnum to scalar #53096

Merged
merged 27 commits into from
Oct 11, 2024

Conversation

crynobone
Copy link
Member

No description provided.

`UnitEnum` to scalar.

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@crynobone crynobone changed the title [11.x] Add Illuminate\Support\mutate to resolve BackedEnum or UnitEnum to scalar. [11.x] Add Illuminate\Support\mutate to resolve Arrayable, BackedEnum or UnitEnum to scalar Oct 10, 2024
crynobone and others added 17 commits October 10, 2024 09:51
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@crynobone crynobone changed the title [11.x] Add Illuminate\Support\mutate to resolve Arrayable, BackedEnum or UnitEnum to scalar [11.x] Add Illuminate\Support\mutate to resolve JsonSerializable, Stringable, BackedEnum or UnitEnum to scalar Oct 10, 2024
@rodrigopedra
Copy link
Contributor

Not a fan of the name, maybe unbox()?

Suggestion comes from my old Java days:

https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html

@taylorotwell
Copy link
Member

Even something super explicit like "enum_value" would be fine with me since this will mainly be used internally and not really be user facing.

@shaedrich
Copy link
Contributor

What about toScalar()?

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@crynobone crynobone changed the title [11.x] Add Illuminate\Support\mutate to resolve JsonSerializable, Stringable, BackedEnum or UnitEnum to scalar [11.x] Add Illuminate\Support\enum_value to resolve BackedEnum or UnitEnum to scalar Oct 10, 2024
@crynobone crynobone marked this pull request as ready for review October 10, 2024 23:31
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
crynobone and others added 5 commits October 11, 2024 10:42
@taylorotwell taylorotwell merged commit a236107 into 11.x Oct 11, 2024
32 checks passed
@taylorotwell taylorotwell deleted the mutate-value branch October 11, 2024 15:12
timacdonald pushed a commit to timacdonald/framework that referenced this pull request Oct 15, 2024
… `UnitEnum` to scalar (laravel#53096)

* [11.x] Add `Illuminate\Support\mutate` to resolve `BackedEnum` or
`UnitEnum` to scalar.

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

* wip

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

* Apply fixes from StyleCI

* wip

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

* Apply fixes from StyleCI

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

* Apply fixes from StyleCI

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

* wip

* Apply fixes from StyleCI

* rename to scalar value

* rename again

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
Co-authored-by: Taylor Otwell <taylor@laravel.com>
@jayan-blutui
Copy link
Contributor

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.

@grantholle
Copy link

Even something super explicit like "enum_value" would be fine with me since this will mainly be used internally and not really be user facing.

Any reason why it won't be added as a general helper? I find this really clever and useful to implement similar functionality in projects (similar to toValue in Vue-land).

@crynobone
Copy link
Member Author

We want to limit it's usecase only to what's needed for the Framework.

@grantholle
Copy link

Couldn't the same could be said about any helper? Seems odd that this one is isolated as internal. It's a good function, let it have its moment 😆 .

Thanks anyway...

@crynobone
Copy link
Member Author

Not exactly, as internal function we can create breaking change at any time and it's fine as long as it met Framework requirements. We also wouldn't need to consider any additional use-case by community other than use-case required by the Framework.

@grantholle
Copy link

That's fair. Given its simplicity, hopefully one day you'll reconsider 👍

For now it's copy + paste for me! Thanks again @crynobone

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

Successfully merging this pull request may close these issues.

9 participants