@@ -14,8 +14,7 @@ class TableTest extends SetupTeardown
14
14
public function testToString (): void
15
15
{
16
16
$ expectedResult = self ::INITIAL_RANGE ;
17
- $ sheet = $ this ->getSheet ();
18
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
17
+ $ table = new Table (self ::INITIAL_RANGE );
19
18
20
19
// magic __toString should return the active table range
21
20
$ result = (string ) $ table ;
@@ -27,8 +26,7 @@ public function testToString(): void
27
26
*/
28
27
public function testValidTableNames (string $ name , string $ expected ): void
29
28
{
30
- $ sheet = $ this ->getSheet ();
31
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
29
+ $ table = new Table (self ::INITIAL_RANGE );
32
30
33
31
$ result = $ table ->setName ($ name );
34
32
self ::assertInstanceOf (Table::class, $ result );
@@ -38,6 +36,7 @@ public function testValidTableNames(string $name, string $expected): void
38
36
public function validTableNamesProvider (): array
39
37
{
40
38
return [
39
+ ['' , '' ],
41
40
['Table_1 ' , 'Table_1 ' ],
42
41
['_table_2 ' , '_table_2 ' ],
43
42
['\table_3 ' , '\table_3 ' ],
@@ -52,8 +51,7 @@ public function validTableNamesProvider(): array
52
51
*/
53
52
public function testInvalidTableNames (string $ name ): void
54
53
{
55
- $ sheet = $ this ->getSheet ();
56
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
54
+ $ table = new Table (self ::INITIAL_RANGE );
57
55
58
56
$ this ->expectException (PhpSpreadsheetException::class);
59
57
@@ -95,8 +93,7 @@ public function testUniqueTableName(): void
95
93
96
94
public function testVariousSets (): void
97
95
{
98
- $ sheet = $ this ->getSheet ();
99
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
96
+ $ table = new Table (self ::INITIAL_RANGE );
100
97
101
98
$ result = $ table ->setShowHeaderRow (false );
102
99
self ::assertInstanceOf (Table::class, $ result );
@@ -110,15 +107,15 @@ public function testVariousSets(): void
110
107
public function testGetWorksheet (): void
111
108
{
112
109
$ sheet = $ this ->getSheet ();
113
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
110
+ $ table = new Table (self ::INITIAL_RANGE );
111
+ $ sheet ->addTable ($ table );
114
112
$ result = $ table ->getWorksheet ();
115
113
self ::assertSame ($ sheet , $ result );
116
114
}
117
115
118
116
public function testSetWorksheet (): void
119
117
{
120
- $ sheet = $ this ->getSheet ();
121
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
118
+ $ table = new Table (self ::INITIAL_RANGE );
122
119
$ spreadsheet = $ this ->getSpreadsheet ();
123
120
$ sheet2 = $ spreadsheet ->createSheet ();
124
121
// Setters return the instance to implement the fluent interface
@@ -129,8 +126,7 @@ public function testSetWorksheet(): void
129
126
public function testGetRange (): void
130
127
{
131
128
$ expectedResult = self ::INITIAL_RANGE ;
132
- $ sheet = $ this ->getSheet ();
133
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
129
+ $ table = new Table (self ::INITIAL_RANGE );
134
130
135
131
// Result should be the active table range
136
132
$ result = $ table ->getRange ();
@@ -141,7 +137,7 @@ public function testSetRange(): void
141
137
{
142
138
$ sheet = $ this ->getSheet ();
143
139
$ title = $ sheet ->getTitle ();
144
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
140
+ $ table = new Table (self ::INITIAL_RANGE );
145
141
$ ranges = [
146
142
'G1:J512 ' => "$ title!G1:J512 " ,
147
143
'K1:N20 ' => 'K1:N20 ' ,
@@ -161,8 +157,7 @@ public function testSetRange(): void
161
157
public function testClearRange (): void
162
158
{
163
159
$ expectedResult = '' ;
164
- $ sheet = $ this ->getSheet ();
165
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
160
+ $ table = new Table (self ::INITIAL_RANGE );
166
161
167
162
// Setters return the instance to implement the fluent interface
168
163
$ result = $ table ->setRange ('' );
@@ -180,8 +175,7 @@ public function testSetRangeInvalidRange(string $range): void
180
175
{
181
176
$ this ->expectException (PhpSpreadsheetException::class);
182
177
183
- $ sheet = $ this ->getSheet ();
184
- new Table ($ range , $ sheet );
178
+ new Table ($ range );
185
179
}
186
180
187
181
public function invalidTableRangeProvider (): array
@@ -198,8 +192,7 @@ public function invalidTableRangeProvider(): array
198
192
public function testGetColumnsEmpty (): void
199
193
{
200
194
// There should be no columns yet defined
201
- $ sheet = $ this ->getSheet ();
202
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
195
+ $ table = new Table (self ::INITIAL_RANGE );
203
196
$ result = $ table ->getColumns ();
204
197
self ::assertIsArray ($ result );
205
198
self ::assertCount (0 , $ result );
@@ -212,8 +205,7 @@ public function testGetColumnOffset(): void
212
205
'K ' => 3 ,
213
206
'M ' => 5 ,
214
207
];
215
- $ sheet = $ this ->getSheet ();
216
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
208
+ $ table = new Table (self ::INITIAL_RANGE );
217
209
218
210
// If we request a specific column by its column ID, we should get an
219
211
// integer returned representing the column offset within the range
@@ -296,8 +288,7 @@ public function testGetInvalidColumnOffset(): void
296
288
public function testSetColumnWithString (): void
297
289
{
298
290
$ expectedResult = 'L ' ;
299
- $ sheet = $ this ->getSheet ();
300
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
291
+ $ table = new Table (self ::INITIAL_RANGE );
301
292
302
293
// Setters return the instance to implement the fluent interface
303
294
$ result = $ table ->setColumn ($ expectedResult );
@@ -315,8 +306,7 @@ public function testSetColumnWithString(): void
315
306
public function testSetInvalidColumnWithString (): void
316
307
{
317
308
$ this ->expectException (PhpSpreadsheetException::class);
318
- $ sheet = $ this ->getSheet ();
319
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
309
+ $ table = new Table (self ::INITIAL_RANGE );
320
310
321
311
$ invalidColumn = 'A ' ;
322
312
$ table ->setColumn ($ invalidColumn );
@@ -326,8 +316,7 @@ public function testSetColumnWithColumnObject(): void
326
316
{
327
317
$ expectedResult = 'M ' ;
328
318
$ columnObject = new Column ($ expectedResult );
329
- $ sheet = $ this ->getSheet ();
330
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
319
+ $ table = new Table (self ::INITIAL_RANGE );
331
320
332
321
// Setters return the instance to implement the fluent interface
333
322
$ result = $ table ->setColumn ($ columnObject );
@@ -347,26 +336,23 @@ public function testSetInvalidColumnWithObject(): void
347
336
$ this ->expectException (PhpSpreadsheetException::class);
348
337
349
338
$ invalidColumn = 'E ' ;
350
- $ sheet = $ this ->getSheet ();
351
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
339
+ $ table = new Table (self ::INITIAL_RANGE );
352
340
$ table ->setColumn ($ invalidColumn );
353
341
}
354
342
355
343
public function testSetColumnWithInvalidDataType (): void
356
344
{
357
345
$ this ->expectException (PhpSpreadsheetException::class);
358
346
359
- $ sheet = $ this ->getSheet ();
360
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
347
+ $ table = new Table (self ::INITIAL_RANGE );
361
348
$ invalidColumn = 123.456 ;
362
349
// @phpstan-ignore-next-line
363
350
$ table ->setColumn ($ invalidColumn );
364
351
}
365
352
366
353
public function testGetColumns (): void
367
354
{
368
- $ sheet = $ this ->getSheet ();
369
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
355
+ $ table = new Table (self ::INITIAL_RANGE );
370
356
371
357
$ columnIndexes = ['L ' , 'M ' ];
372
358
@@ -391,8 +377,7 @@ public function testGetColumns(): void
391
377
392
378
public function testGetColumn (): void
393
379
{
394
- $ sheet = $ this ->getSheet ();
395
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
380
+ $ table = new Table (self ::INITIAL_RANGE );
396
381
397
382
$ columnIndexes = ['L ' , 'M ' ];
398
383
@@ -410,8 +395,7 @@ public function testGetColumn(): void
410
395
411
396
public function testGetColumnByOffset (): void
412
397
{
413
- $ sheet = $ this ->getSheet ();
414
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
398
+ $ table = new Table (self ::INITIAL_RANGE );
415
399
416
400
$ columnIndexes = [
417
401
0 => 'H ' ,
@@ -430,8 +414,7 @@ public function testGetColumnByOffset(): void
430
414
431
415
public function testGetColumnIfNotSet (): void
432
416
{
433
- $ sheet = $ this ->getSheet ();
434
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
417
+ $ table = new Table (self ::INITIAL_RANGE );
435
418
// If we request a specific column by its column ID, we should
436
419
// get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\Table\Column object returned
437
420
$ result = $ table ->getColumn ('K ' );
@@ -441,8 +424,7 @@ public function testGetColumnIfNotSet(): void
441
424
public function testGetColumnWithoutRangeSet (): void
442
425
{
443
426
$ this ->expectException (\PhpOffice \PhpSpreadsheet \Exception::class);
444
- $ sheet = $ this ->getSheet ();
445
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
427
+ $ table = new Table (self ::INITIAL_RANGE );
446
428
447
429
// Clear the range
448
430
$ table ->setRange ('' );
@@ -451,8 +433,7 @@ public function testGetColumnWithoutRangeSet(): void
451
433
452
434
public function testClearRangeWithExistingColumns (): void
453
435
{
454
- $ sheet = $ this ->getSheet ();
455
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
436
+ $ table = new Table (self ::INITIAL_RANGE );
456
437
$ expectedResult = '' ;
457
438
458
439
$ columnIndexes = ['L ' , 'M ' , 'N ' ];
@@ -476,8 +457,7 @@ public function testClearRangeWithExistingColumns(): void
476
457
477
458
public function testSetRangeWithExistingColumns (): void
478
459
{
479
- $ sheet = $ this ->getSheet ();
480
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
460
+ $ table = new Table (self ::INITIAL_RANGE );
481
461
$ expectedResult = 'G1:J512 ' ;
482
462
483
463
// These columns should be retained
@@ -509,7 +489,8 @@ public function testSetRangeWithExistingColumns(): void
509
489
public function testClone (): void
510
490
{
511
491
$ sheet = $ this ->getSheet ();
512
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
492
+ $ table = new Table (self ::INITIAL_RANGE );
493
+ $ sheet ->addTable ($ table );
513
494
$ columnIndexes = ['L ' , 'M ' ];
514
495
515
496
foreach ($ columnIndexes as $ columnIndex ) {
@@ -546,8 +527,7 @@ public function testNoWorksheet(): void
546
527
547
528
public function testClearColumn (): void
548
529
{
549
- $ sheet = $ this ->getSheet ();
550
- $ table = new Table (self ::INITIAL_RANGE , $ sheet );
530
+ $ table = new Table (self ::INITIAL_RANGE );
551
531
$ columnIndexes = ['J ' , 'K ' , 'L ' , 'M ' ];
552
532
553
533
foreach ($ columnIndexes as $ columnIndex ) {
0 commit comments