|
2 | 2 |
|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
| 5 | +use Illuminate\Support\Collection; |
5 | 6 | use function Pest\Faker\faker; |
6 | 7 | use WendellAdriel\ValidatedDTO\SimpleDTO; |
| 8 | +use WendellAdriel\ValidatedDTO\Tests\Datasets\SimpleNameDTO; |
7 | 9 | use WendellAdriel\ValidatedDTO\Tests\Datasets\WireableDTO; |
8 | 10 |
|
9 | 11 | beforeEach(function () { |
|
21 | 23 | ->toBe($wireableDTO->toArray()); |
22 | 24 | }); |
23 | 25 |
|
| 26 | +it('validates that a Wireable DTO with a nested DTO will return the correct data for the toLivewire method', function () { |
| 27 | + $data = [ |
| 28 | + 'name' => $this->name, |
| 29 | + 'age' => $this->age, |
| 30 | + 'simple_name_dto' => [ |
| 31 | + 'first_name' => $this->name, |
| 32 | + 'last_name' => $this->name, |
| 33 | + ], |
| 34 | + ]; |
| 35 | + |
| 36 | + $wireableDTO = new WireableDTO($data); |
| 37 | + |
| 38 | + expect($wireableDTO) |
| 39 | + ->toBeInstanceOf(SimpleDTO::class) |
| 40 | + ->and($wireableDTO->simple_name_dto) |
| 41 | + ->toBeInstanceOf(SimpleNameDTO::class) |
| 42 | + ->and($wireableDTO->toLivewire()) |
| 43 | + ->toBe($data); |
| 44 | +}); |
| 45 | + |
| 46 | +it('validates that a Wireable DTO with a DTO Collection will return the correct data for the toLivewire method', function () { |
| 47 | + $simple_name = [ |
| 48 | + 'first_name' => $this->name, |
| 49 | + 'last_name' => $this->name, |
| 50 | + ]; |
| 51 | + |
| 52 | + $simple_name_2 = [ |
| 53 | + 'first_name' => $this->name, |
| 54 | + 'last_name' => $this->name, |
| 55 | + ]; |
| 56 | + |
| 57 | + $data = [ |
| 58 | + 'name' => $this->name, |
| 59 | + 'age' => $this->age, |
| 60 | + 'simple_names_collection' => [$simple_name, $simple_name_2], |
| 61 | + ]; |
| 62 | + |
| 63 | + $wireableDTO = new WireableDTO($data); |
| 64 | + |
| 65 | + expect($wireableDTO) |
| 66 | + ->toBeInstanceOf(SimpleDTO::class) |
| 67 | + ->and($wireableDTO->simple_names_collection) |
| 68 | + ->toBeInstanceOf(Collection::class) |
| 69 | + ->and($wireableDTO->simple_names_collection->first()) |
| 70 | + ->toBeInstanceOf(SimpleNameDTO::class) |
| 71 | + ->and($wireableDTO->toLivewire()) |
| 72 | + ->toBe($data); |
| 73 | +}); |
| 74 | + |
24 | 75 | it('validates that a Wireable DTO can be instantiated with the fromLivewire method with array', function () { |
25 | 76 | $wireableDTO = WireableDTO::fromLivewire(['name' => $this->name, 'age' => $this->age]); |
26 | 77 |
|
|
0 commit comments