|
3 | 3 | namespace Illuminate\Tests\Support; |
4 | 4 |
|
5 | 5 | use ArrayAccess; |
| 6 | +use ArrayIterator; |
6 | 7 | use Illuminate\Contracts\Support\Htmlable; |
7 | 8 | use Illuminate\Support\Env; |
8 | 9 | use Illuminate\Support\Optional; |
| 10 | +use IteratorAggregate; |
9 | 11 | use LogicException; |
10 | 12 | use Mockery as m; |
11 | 13 | use PHPUnit\Framework\TestCase; |
@@ -87,10 +89,18 @@ public function testDataGetWithNestedArrays() |
87 | 89 | ['name' => 'abigail'], |
88 | 90 | ['name' => 'dayle'], |
89 | 91 | ]; |
| 92 | + $arrayIterable = new SupportTestArrayIterable([ |
| 93 | + [ 'name' => 'taylor', 'email' => '[email protected]'], |
| 94 | + ['name' => 'abigail'], |
| 95 | + ['name' => 'dayle'], |
| 96 | + ]); |
90 | 97 |
|
91 | 98 | $this->assertEquals(['taylor', 'abigail', 'dayle'], data_get($array, '*.name')); |
92 | 99 | $this-> assertEquals([ '[email protected]', null, null], data_get( $array, '*.email', 'irrelevant')); |
93 | 100 |
|
| 101 | + $this->assertEquals(['taylor', 'abigail', 'dayle'], data_get($arrayIterable, '*.name')); |
| 102 | + $this-> assertEquals([ '[email protected]', null, null], data_get( $arrayIterable, '*.email', 'irrelevant')); |
| 103 | + |
94 | 104 | $array = [ |
95 | 105 | 'users' => [ |
96 | 106 | [ 'first' => 'taylor', 'last' => 'otwell', 'email' => '[email protected]'], |
@@ -792,3 +802,18 @@ public function offsetUnset($offset) |
792 | 802 | unset($this->attributes[$offset]); |
793 | 803 | } |
794 | 804 | } |
| 805 | + |
| 806 | +class SupportTestArrayIterable implements IteratorAggregate |
| 807 | +{ |
| 808 | + protected $items = []; |
| 809 | + |
| 810 | + public function __construct($items = []) |
| 811 | + { |
| 812 | + $this->items = $items; |
| 813 | + } |
| 814 | + |
| 815 | + public function getIterator() |
| 816 | + { |
| 817 | + return new ArrayIterator($this->items); |
| 818 | + } |
| 819 | +} |
0 commit comments