|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MichaelRubel\LoopFunctions\Tests; |
| 4 | + |
| 5 | +use Illuminate\Support\Collection; |
| 6 | +use MichaelRubel\LoopFunctions\Traits\LoopFunctions; |
| 7 | + |
| 8 | +class RecursiveArrayMappingTest extends TestCase |
| 9 | +{ |
| 10 | + use LoopFunctions; |
| 11 | + |
| 12 | + public bool $test = false; |
| 13 | + public ?string $nice = 'no'; |
| 14 | + public ?string $first_name = null; |
| 15 | + public ?string $last_name = null; |
| 16 | + public ?string $full_name = null; |
| 17 | + public ?array $array = null; |
| 18 | + public ?Collection $collection = null; |
| 19 | + |
| 20 | + /** @test */ |
| 21 | + public function testCanMapRecursively() |
| 22 | + { |
| 23 | + $data = [ |
| 24 | + 'collection' => collect([ |
| 25 | + 'first_name' => 'Michael', |
| 26 | + 'last_name' => 'Rubel', |
| 27 | + ]), |
| 28 | + 'last_name' => 'Rubel', |
| 29 | + 'array' => [ |
| 30 | + 'test' => true, |
| 31 | + 'full_name' => 'Michael Rubel', |
| 32 | + 'first_name' => 'Tester', |
| 33 | + 'last_name' => 'Field', |
| 34 | + 'nice' => 'yes', |
| 35 | + ], |
| 36 | + 'nice' => 'yes', |
| 37 | + ]; |
| 38 | + |
| 39 | + $this->propertiesFrom($data); |
| 40 | + |
| 41 | + $this->assertTrue($this->test); |
| 42 | + $this->assertArrayHasKey('test', $this->array); |
| 43 | + $this->assertArrayHasKey('first_name', $this->collection); |
| 44 | + $this->assertStringContainsString('Michael', $this->first_name); |
| 45 | + $this->assertStringContainsString('Rubel', $this->last_name); |
| 46 | + $this->assertStringContainsString('Michael Rubel', $this->full_name); |
| 47 | + $this->assertStringContainsString('yes', $this->nice); |
| 48 | + } |
| 49 | +} |
0 commit comments