@@ -86,9 +86,9 @@ protected function getDataArray(): array
8686 {
8787 $ id = 0 ;
8888 return [
89- ['id ' => $ id ++ , 'integer ' => 4573 , 'date ' => '1900-02-14 ' , 'name ' => 'James Bond ' ],
90- ['id ' => $ id ++ , 'integer ' => 982630 , 'date ' => '2179-08-12 ' , 'name ' => 'Ellen Louise Ripley ' ],
91- ['id ' => $ id ++ , 'integer ' => 7239 , 'date ' => '1753-01-31 ' , 'name ' => 'Captain Jack Sparrow ' ],
89+ ['id ' => ++ $ id , 'integer ' => 4573 , 'date ' => '1900-02-14 ' , 'name ' => 'James Bond ' ],
90+ ['id ' => ++ $ id , 'integer ' => 982630 , 'date ' => '2179-08-12 ' , 'name ' => 'Ellen Louise Ripley ' ],
91+ ['id ' => ++ $ id , 'integer ' => 7239 , 'date ' => '1753-01-31 ' , 'name ' => 'Captain Jack Sparrow ' ],
9292 ];
9393 }
9494
@@ -112,7 +112,7 @@ protected function read($testFileName)
112112 }
113113
114114
115- protected function startTest ($ testFileName , $ sheets = []): ExcelWriter
115+ protected function startExportTest ($ testFileName , $ sheets = []): ExcelWriter
116116 {
117117 if (file_exists ($ testFileName )) {
118118 unlink ($ testFileName );
@@ -124,7 +124,7 @@ protected function startTest($testFileName, $sheets = []): ExcelWriter
124124 return Excel::create ($ sheets );
125125 }
126126
127- protected function endTest ($ testFileName )
127+ protected function endExportTest ($ testFileName )
128128 {
129129 $ this ->excelReader = null ;
130130 $ this ->cells = [];
@@ -137,10 +137,10 @@ protected function endTest($testFileName)
137137 }
138138 }
139139
140- public function testArray ()
140+ public function testExportArray ()
141141 {
142142 $ testFileName = __DIR__ . '/test1.xlsx ' ;
143- $ excel = $ this ->startTest ($ testFileName );
143+ $ excel = $ this ->startExportTest ($ testFileName );
144144
145145 /** @var SheetWriter $sheet */
146146 $ sheet = $ excel ->getSheet ();
@@ -153,19 +153,19 @@ public function testArray()
153153
154154 $ this ->assertEquals (array_values ($ data [0 ]), $ this ->getValues ('A1 ' , 'B1 ' , 'C1 ' , 'D1 ' ));
155155
156- $ this ->endTest ($ testFileName );
156+ $ this ->endExportTest ($ testFileName );
157157 }
158158
159- public function testArrayWithHeaders ()
159+ public function testExportArrayWithHeaders ()
160160 {
161161 $ testFileName = __DIR__ . '/test2.xlsx ' ;
162- $ excel = $ this ->startTest ($ testFileName );
162+ $ excel = $ this ->startExportTest ($ testFileName );
163163
164164 /** @var SheetWriter $sheet */
165165 $ sheet = $ excel ->getSheet ();
166166
167167 $ data = $ this ->getDataArray ();
168- $ sheet ->withHeaders ()->writeData ($ data );
168+ $ sheet ->withHeadings ()->writeData ($ data );
169169 $ excel ->save ($ testFileName );
170170
171171 $ this ->read ($ testFileName );
@@ -174,13 +174,13 @@ public function testArrayWithHeaders()
174174 $ this ->assertEquals (array_keys ($ row ), $ this ->getValues ('A1 ' , 'B1 ' , 'C1 ' , 'D1 ' ));
175175 $ this ->assertEquals (array_values ($ row ), $ this ->getValues ('A3 ' , 'B3 ' , 'C3 ' , 'D3 ' ));
176176
177- $ this ->endTest ($ testFileName );
177+ $ this ->endExportTest ($ testFileName );
178178 }
179179
180- public function testCollection ()
180+ public function testExportCollection ()
181181 {
182182 $ testFileName = __DIR__ . '/test3.xlsx ' ;
183- $ excel = $ this ->startTest ($ testFileName );
183+ $ excel = $ this ->startExportTest ($ testFileName );
184184
185185 /** @var SheetWriter $sheet */
186186 $ sheet = $ excel ->getSheet ();
@@ -193,18 +193,18 @@ public function testCollection()
193193
194194 $ this ->assertEquals (array_values ($ data [0 ]), $ this ->getValues ('A1 ' , 'B1 ' , 'C1 ' , 'D1 ' ));
195195
196- $ this ->endTest ($ testFileName );
196+ $ this ->endExportTest ($ testFileName );
197197 }
198198
199- public function testCollectionWithHeaders ()
199+ public function testExportCollectionWithHeaders ()
200200 {
201201 $ testFileName = 'test4.xlsx ' ;
202- $ excel = $ this ->startTest ($ testFileName );
202+ $ excel = $ this ->startExportTest ($ testFileName );
203203
204204 /** @var SheetWriter $sheet */
205205 $ sheet = $ excel ->getSheet ();
206206
207- $ sheet ->withHeaders (['date ' , 'name ' ])
207+ $ sheet ->withHeadings (['date ' , 'name ' ])
208208 ->applyFontStyleBold ()
209209 ->applyBorder ('thin ' )
210210 ->writeData (collect ($ this ->getDataCollectionStd ()));
@@ -214,13 +214,13 @@ public function testCollectionWithHeaders()
214214
215215 $ this ->assertEquals (['1753-01-31 ' , 'Captain Jack Sparrow ' , null , null ], $ this ->getValues ('A4 ' , 'B4 ' , 'C4 ' , 'D4 ' ));
216216
217- $ this ->endTest ($ testFileName );
217+ $ this ->endExportTest ($ testFileName );
218218 }
219219
220- public function testMultipleSheets ()
220+ public function testExportMultipleSheets ()
221221 {
222222 $ testFileName = 'test5.xlsx ' ;
223- $ excel = $ this ->startTest ($ testFileName );
223+ $ excel = $ this ->startExportTest ($ testFileName );
224224
225225 $ sheet = $ excel ->makeSheet ('Collection ' );
226226 $ collection = collect ([
@@ -261,13 +261,13 @@ public function testMultipleSheets()
261261 $ this ->cells = $ this ->excelReader ->readRows (false , null , true );
262262 $ this ->assertEquals (9 , $ this ->getValue ('C3 ' ));
263263
264- $ this ->endTest ($ testFileName );
264+ $ this ->endExportTest ($ testFileName );
265265 }
266266
267- public function testAdvanced ()
267+ public function testExportAdvanced ()
268268 {
269269 $ testFileName = 'test6.xlsx ' ;
270- $ excel = $ this ->startTest ($ testFileName );
270+ $ excel = $ this ->startExportTest ($ testFileName );
271271
272272 /** @var SheetWriter $sheet */
273273 $ sheet = $ excel ->getSheet ();
@@ -305,10 +305,10 @@ public function testAdvanced()
305305
306306 $ this ->assertEquals ([982630 , '2179-08-12 ' , 'Ellen Louise Ripley ' , null ], $ this ->getValues ('B7 ' , 'C7 ' , 'D7 ' , 'e7 ' ));
307307
308- $ this ->endTest ($ testFileName );
308+ $ this ->endExportTest ($ testFileName );
309309 }
310310
311- public function testLoadModel ()
311+ public function testImportModel ()
312312 {
313313 $ testFileName = 'test_model.xlsx ' ;
314314 $ excel = Excel::open (storage_path ($ testFileName ));
@@ -357,4 +357,23 @@ public function testLoadModel()
357357 $ this ->assertEquals ('Ellen Louise Ripley ' , $ result [6 ]['B ' ]);
358358 $ this ->assertEquals ('Captain Jack Sparrow ' , $ result [7 ]['B ' ]);
359359 }
360+
361+
362+ public function testExportArray0 ()
363+ {
364+ $ testFileName = __DIR__ . '/test0.xlsx ' ;
365+ $ excel = $ this ->startExportTest ($ testFileName );
366+
367+ /** @var SheetWriter $sheet */
368+ $ sheet = $ excel ->getSheet ();
369+
370+ $ data = $ this ->getDataArray ();
371+ $ sheet ->withHeadings ()->setFieldFormats (['date ' => '@date ' ])->writeData ($ data );
372+ $ excel ->save ($ testFileName );
373+
374+ $ this ->assertTrue (file_exists ($ testFileName ));
375+
376+ //$this->endExportTest($testFileName);
377+ }
378+
360379}
0 commit comments