-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Fix Arr::array default to use empty array #57008
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -664,6 +664,13 @@ public function testItGetsAnArray() | |
| Arr::array($test_array, 'string'); | ||
| } | ||
|
|
||
| public function testItReturnsEmptyArrayForMissingKeyByDefault() | ||
| { | ||
| $data = ['name' => 'Taylor']; | ||
|
|
||
| $this->assertSame([], Arr::array($data, 'missing_key')); | ||
| } | ||
|
|
||
| public function testHas() | ||
| { | ||
| $array = ['products.desk' => ['price' => 100]]; | ||
|
|
@@ -1588,7 +1595,8 @@ public function testFrom() | |
| $this->assertSame($subject, Arr::from($items)); | ||
|
|
||
| $items = new WeakMap; | ||
| $items[$temp = new class {}] = 'bar'; | ||
| $items[$temp = new class { | ||
| }] = 'bar'; | ||
|
Comment on lines
+1598
to
+1599
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These chages are not related for this PR.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes came from running Laravel Pint for code style consistency, not from any functional change.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Laravel uses StyleCI—adhering to StyleCI's config should suffice. |
||
| $this->assertSame(['bar'], Arr::from($items)); | ||
|
|
||
| $this->expectException(InvalidArgumentException::class); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change would be a breaking change in many projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method enforces a strict : array return type, so using [] as the default keeps the contract consistent. I’ve run the full test suite for this method, and everything passes fine.