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
190190 throw new PhpSpreadsheetException ('Table must be set on a range of cells. ' );
191191 }
192192
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+
193198 $ this ->range = $ range ;
194199 // Discard any column ruless that are no longer valid within this range
195200 [$ rangeStart , $ rangeEnd ] = Coordinate::rangeBoundaries ($ this ->range );
Original file line number Diff line number Diff line change @@ -173,14 +173,26 @@ public function testClearRange(): void
173173 self ::assertEquals ($ expectedResult , $ result );
174174 }
175175
176- public function testSetRangeInvalidRange (): void
176+ /**
177+ * @dataProvider invalidTableRangeProvider
178+ */
179+ public function testSetRangeInvalidRange (string $ range ): void
177180 {
178181 $ this ->expectException (PhpSpreadsheetException::class);
179182
180- $ expectedResult = 'A1 ' ;
181-
182183 $ 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+ ];
184196 }
185197
186198 public function testGetColumnsEmpty (): void
You can’t perform that action at this time.
0 commit comments