File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
src/PhpSpreadsheet/Worksheet
tests/PhpSpreadsheetTests/Worksheet/Table Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,11 @@ public function setRange(string $range): self
190
190
throw new PhpSpreadsheetException ('Table must be set on a range of cells. ' );
191
191
}
192
192
193
+ [$ width , $ height ] = Coordinate::rangeDimension ($ range );
194
+ if ($ width < 1 || $ height < 2 ) {
195
+ throw new PhpSpreadsheetException ('The table range must be at least 1 column and 2 rows ' );
196
+ }
197
+
193
198
$ this ->range = $ range ;
194
199
// Discard any column ruless that are no longer valid within this range
195
200
[$ rangeStart , $ rangeEnd ] = Coordinate::rangeBoundaries ($ this ->range );
Original file line number Diff line number Diff line change @@ -173,14 +173,26 @@ public function testClearRange(): void
173
173
self ::assertEquals ($ expectedResult , $ result );
174
174
}
175
175
176
- public function testSetRangeInvalidRange (): void
176
+ /**
177
+ * @dataProvider invalidTableRangeProvider
178
+ */
179
+ public function testSetRangeInvalidRange (string $ range ): void
177
180
{
178
181
$ this ->expectException (PhpSpreadsheetException::class);
179
182
180
- $ expectedResult = 'A1 ' ;
181
-
182
183
$ sheet = $ this ->getSheet ();
183
- $ table = new Table ($ expectedResult , $ sheet );
184
+ new Table ($ range , $ sheet );
185
+ }
186
+
187
+ public function invalidTableRangeProvider (): array
188
+ {
189
+ return [
190
+ ['A1 ' ],
191
+ ['A1:A1 ' ],
192
+ ['B1:A4 ' ],
193
+ ['A1:D1 ' ],
194
+ ['D1:A1 ' ],
195
+ ];
184
196
}
185
197
186
198
public function testGetColumnsEmpty (): void
You can’t perform that action at this time.
0 commit comments