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 wrapping additional properties #893

Open
ennorehling opened this issue Oct 22, 2024 · 0 comments
Open

Not wrapping additional properties #893

ennorehling opened this issue Oct 22, 2024 · 0 comments

Comments

@ennorehling
Copy link

ennorehling commented Oct 22, 2024

✏️ Describe the bug
When adding additional properties to a Data Object, they do not get wrapped by wrap().

↪️ To Reproduce
Provide us a pest test like this one which shows the problem:

it('cannot wrap additional properties', function () {
    class UserData extends Data
    {
        public function __construct(
            public string $name,
        ) {
        }
    }

    dd(UserData::from(['name' => 'Ruben'])->additional(['role' => 'admin'])->wrap('data'));
});

Assertions aren't required, a simple dump or dd statement of what's going wrong is good enough 😄

✅ Expected behavior
I'm expecting this to produce

[
    "data" => [
      "name" => "Ruben",
      "rank" => "admin",
    ],
  ]

but instead, I get
[
"data" => [
"name" => "Ruben",
],
"rank" => "admin",
]

A similar thing happens when I add a with() method to the object.

🖥️ Versions

Laravel: v10.48.22
Laravel Data: 4.11.0
PHP: 8.2.20

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

No branches or pull requests

1 participant