|
6 | 6 | use Maatwebsite\Excel\Concerns\Importable; |
7 | 7 | use Maatwebsite\Excel\Concerns\ToArray; |
8 | 8 | use Maatwebsite\Excel\Concerns\ToModel; |
| 9 | +use Maatwebsite\Excel\Concerns\WithHeadingRow; |
9 | 10 | use Maatwebsite\Excel\Concerns\WithLimit; |
10 | 11 | use Maatwebsite\Excel\Concerns\WithStartRow; |
11 | 12 | use Maatwebsite\Excel\Tests\Data\Stubs\Database\User; |
@@ -104,6 +105,72 @@ public function limit(): int |
104 | 105 | $import->import('import-users.xlsx'); |
105 | 106 | } |
106 | 107 |
|
| 108 | + public function test_can_import_single_with_heading_row() |
| 109 | + { |
| 110 | + $import = new class implements ToArray, WithLimit, WithHeadingRow |
| 111 | + { |
| 112 | + use Importable; |
| 113 | + |
| 114 | + /** |
| 115 | + * @param array $array |
| 116 | + */ |
| 117 | + public function array(array $array) |
| 118 | + { |
| 119 | + Assert::assertEquals([ |
| 120 | + [ |
| 121 | + 'Patrick Brouwers', |
| 122 | + 'patrick@maatwebsite.nl', |
| 123 | + ], |
| 124 | + ], $array); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * @return int |
| 129 | + */ |
| 130 | + public function limit(): int |
| 131 | + { |
| 132 | + return 1; |
| 133 | + } |
| 134 | + }; |
| 135 | + |
| 136 | + $import->import('import-users-with-headings.xlsx'); |
| 137 | + } |
| 138 | + |
| 139 | + public function test_can_import_multiple_with_heading_row() |
| 140 | + { |
| 141 | + $import = new class implements ToArray, WithLimit, WithHeadingRow |
| 142 | + { |
| 143 | + use Importable; |
| 144 | + |
| 145 | + /** |
| 146 | + * @param array $array |
| 147 | + */ |
| 148 | + public function array(array $array) |
| 149 | + { |
| 150 | + Assert::assertEquals([ |
| 151 | + [ |
| 152 | + 'Patrick Brouwers', |
| 153 | + 'patrick@maatwebsite.nl', |
| 154 | + ], |
| 155 | + [ |
| 156 | + 'Taylor Otwell', |
| 157 | + 'taylor@laravel.com', |
| 158 | + ], |
| 159 | + ], $array); |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * @return int |
| 164 | + */ |
| 165 | + public function limit(): int |
| 166 | + { |
| 167 | + return 2; |
| 168 | + } |
| 169 | + }; |
| 170 | + |
| 171 | + $import->import('import-users-with-headings.xlsx'); |
| 172 | + } |
| 173 | + |
107 | 174 | public function test_can_set_limit_bigger_than_row_size() |
108 | 175 | { |
109 | 176 | $import = new class implements ToArray, WithLimit |
|
0 commit comments