|
17 | 17 | use Test\TinyBlocks\Mapper\Models\Description; |
18 | 18 | use Test\TinyBlocks\Mapper\Models\Employee; |
19 | 19 | use Test\TinyBlocks\Mapper\Models\Employees; |
| 20 | +use Test\TinyBlocks\Mapper\Models\Invoice; |
| 21 | +use Test\TinyBlocks\Mapper\Models\Invoices; |
| 22 | +use Test\TinyBlocks\Mapper\Models\InvoiceSummaries; |
20 | 23 | use Test\TinyBlocks\Mapper\Models\Member; |
21 | 24 | use Test\TinyBlocks\Mapper\Models\MemberId; |
22 | 25 | use Test\TinyBlocks\Mapper\Models\Members; |
@@ -89,6 +92,30 @@ public function testCollectionOfScalars(): void |
89 | 92 | self::assertSame('mixed', $attributes->getType()); |
90 | 93 | } |
91 | 94 |
|
| 95 | + public function testCollectionOfTraversable(): void |
| 96 | + { |
| 97 | + /** @Given an InvoiceSummaries collection with traversable invoices */ |
| 98 | + $invoiceSummaries = InvoiceSummaries::createFrom( |
| 99 | + invoices: Invoices::createFrom(elements: [ |
| 100 | + new Invoice(id: 'INV001', amount: 100.0, customer: 'Customer A'), |
| 101 | + new Invoice(id: 'INV002', amount: 150.5, customer: 'Customer B'), |
| 102 | + new Invoice(id: 'INV003', amount: 200.75, customer: 'Customer C') |
| 103 | + ]) |
| 104 | + ); |
| 105 | + |
| 106 | + /** @When mapping the InvoiceSummaries collection to an array */ |
| 107 | + $actual = $invoiceSummaries->toArray(); |
| 108 | + |
| 109 | + /** @Then the mapped array should have expected values */ |
| 110 | + $expected = [ |
| 111 | + 'INV001' => ['id' => 'INV001', 'amount' => 100.0, 'customer' => 'Customer A'], |
| 112 | + 'INV002' => ['id' => 'INV002', 'amount' => 150.5, 'customer' => 'Customer B'], |
| 113 | + 'INV003' => ['id' => 'INV003', 'amount' => 200.75, 'customer' => 'Customer C'] |
| 114 | + ]; |
| 115 | + |
| 116 | + self::assertSame($expected, $actual); |
| 117 | + } |
| 118 | + |
92 | 119 | #[DataProvider('collectionDiscardKeysProvider')] |
93 | 120 | public function testCollectionDiscardKeys(IterableMapper $collection, array $expected): void |
94 | 121 | { |
|
0 commit comments