10
10
class CellMatcherTest extends TestCase
11
11
{
12
12
/**
13
- * @var Spreadsheet
13
+ * @var ? Spreadsheet
14
14
*/
15
15
protected $ spreadsheet ;
16
16
17
- protected function setUp (): void
17
+ protected function loadSpreadsheet (): Spreadsheet
18
18
{
19
19
$ filename = 'tests/data/Style/ConditionalFormatting/CellMatcher.xlsx ' ;
20
20
$ reader = IOFactory::createReader ('Xlsx ' );
21
- $ this ->spreadsheet = $ reader ->load ($ filename );
21
+
22
+ return $ reader ->load ($ filename );
23
+ }
24
+
25
+ protected function tearDown (): void
26
+ {
27
+ if ($ this ->spreadsheet !== null ) {
28
+ $ this ->spreadsheet ->disconnectWorksheets ();
29
+ $ this ->spreadsheet = null ;
30
+ }
22
31
}
23
32
24
33
/**
25
34
* @dataProvider basicCellIsComparisonDataProvider
26
35
*/
27
36
public function testBasicCellIsComparison (string $ sheetname , string $ cellAddress , array $ expectedMatches ): void
28
37
{
38
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
29
39
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
30
- if ($ worksheet === null ) {
31
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
32
- }
40
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
33
41
$ cell = $ worksheet ->getCell ($ cellAddress );
34
42
35
43
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
36
- if ($ cfRange === null ) {
37
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
38
- }
44
+ self ::assertNotNull ($ cfRange , "{$ cellAddress } is not in a Conditional Format range " );
39
45
$ cfStyles = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
40
46
41
47
$ matcher = new CellMatcher ($ cell , $ cfRange );
@@ -82,16 +88,13 @@ public function basicCellIsComparisonDataProvider(): array
82
88
*/
83
89
public function testRangeCellIsComparison (string $ sheetname , string $ cellAddress , bool $ expectedMatch ): void
84
90
{
91
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
85
92
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
86
- if ($ worksheet === null ) {
87
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
88
- }
93
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
89
94
$ cell = $ worksheet ->getCell ($ cellAddress );
90
95
91
96
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
92
- if ($ cfRange === null ) {
93
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
94
- }
97
+ self ::assertNotNull ($ cfRange , "$ cellAddress is not in a Conditional Format range " );
95
98
$ cfStyle = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
96
99
97
100
$ matcher = new CellMatcher ($ cell , $ cfRange );
@@ -128,16 +131,13 @@ public function rangeCellIsComparisonDataProvider(): array
128
131
*/
129
132
public function testCellIsMultipleExpression (string $ sheetname , string $ cellAddress , array $ expectedMatches ): void
130
133
{
134
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
131
135
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
132
- if ($ worksheet === null ) {
133
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
134
- }
136
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
135
137
$ cell = $ worksheet ->getCell ($ cellAddress );
136
138
137
139
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
138
- if ($ cfRange === null ) {
139
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
140
- }
140
+ self ::assertNotNull ($ cfRange , "$ cellAddress is not in a Conditional Format range " );
141
141
$ cfStyles = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
142
142
143
143
$ matcher = new CellMatcher ($ cell , $ cfRange );
@@ -167,16 +167,13 @@ public function cellIsExpressionMultipleDataProvider(): array
167
167
*/
168
168
public function testCellIsExpression (string $ sheetname , string $ cellAddress , bool $ expectedMatch ): void
169
169
{
170
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
170
171
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
171
- if ($ worksheet === null ) {
172
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
173
- }
172
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
174
173
$ cell = $ worksheet ->getCell ($ cellAddress );
175
174
176
175
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
177
- if ($ cfRange === null ) {
178
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
179
- }
176
+ self ::assertNotNull ($ cfRange , "$ cellAddress is not in a Conditional Format range " );
180
177
$ cfStyle = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
181
178
182
179
$ matcher = new CellMatcher ($ cell , $ cfRange );
@@ -216,16 +213,13 @@ public function cellIsExpressionDataProvider(): array
216
213
*/
217
214
public function testTextExpressions (string $ sheetname , string $ cellAddress , bool $ expectedMatch ): void
218
215
{
216
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
219
217
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
220
- if ($ worksheet === null ) {
221
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
222
- }
218
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
223
219
$ cell = $ worksheet ->getCell ($ cellAddress );
224
220
225
221
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
226
- if ($ cfRange === null ) {
227
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
228
- }
222
+ self ::assertNotNull ($ cfRange , "$ cellAddress is not in a Conditional Format range " );
229
223
$ cfStyle = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
230
224
231
225
$ matcher = new CellMatcher ($ cell , $ cfRange );
@@ -329,16 +323,13 @@ public function textExpressionsDataProvider(): array
329
323
*/
330
324
public function testBlankExpressions (string $ sheetname , string $ cellAddress , array $ expectedMatches ): void
331
325
{
326
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
332
327
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
333
- if ($ worksheet === null ) {
334
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
335
- }
328
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
336
329
$ cell = $ worksheet ->getCell ($ cellAddress );
337
330
338
331
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
339
- if ($ cfRange === null ) {
340
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
341
- }
332
+ self ::assertNotNull ($ cfRange , "$ cellAddress is not in a Conditional Format range " );
342
333
$ cfStyles = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
343
334
344
335
$ matcher = new CellMatcher ($ cell , $ cfRange );
@@ -365,16 +356,13 @@ public function blanksDataProvider(): array
365
356
*/
366
357
public function testErrorExpressions (string $ sheetname , string $ cellAddress , array $ expectedMatches ): void
367
358
{
359
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
368
360
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
369
- if ($ worksheet === null ) {
370
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
371
- }
361
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
372
362
$ cell = $ worksheet ->getCell ($ cellAddress );
373
363
374
364
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
375
- if ($ cfRange === null ) {
376
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
377
- }
365
+ self ::assertNotNull ($ cfRange , "$ cellAddress is not in a Conditional Format range " );
378
366
$ cfStyles = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
379
367
380
368
$ matcher = new CellMatcher ($ cell , $ cfRange );
@@ -400,16 +388,13 @@ public function errorDataProvider(): array
400
388
*/
401
389
public function testDateOccurringExpressions (string $ sheetname , string $ cellAddress , bool $ expectedMatch ): void
402
390
{
391
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
403
392
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
404
- if ($ worksheet === null ) {
405
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
406
- }
393
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
407
394
$ cell = $ worksheet ->getCell ($ cellAddress );
408
395
409
396
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
410
- if ($ cfRange === null ) {
411
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
412
- }
397
+ self ::assertNotNull ($ cfRange , "$ cellAddress is not in a Conditional Format range " );
413
398
$ cfStyle = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
414
399
415
400
$ matcher = new CellMatcher ($ cell , $ cfRange );
@@ -447,16 +432,13 @@ public function dateOccurringDataProvider(): array
447
432
*/
448
433
public function testDuplicatesExpressions (string $ sheetname , string $ cellAddress , array $ expectedMatches ): void
449
434
{
435
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
450
436
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
451
- if ($ worksheet === null ) {
452
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
453
- }
437
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
454
438
$ cell = $ worksheet ->getCell ($ cellAddress );
455
439
456
440
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
457
- if ($ cfRange === null ) {
458
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
459
- }
441
+ self ::AssertNotNull ($ cfRange , "$ cellAddress is not in a Conditional Format range " );
460
442
$ cfStyles = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
461
443
462
444
$ matcher = new CellMatcher ($ cell , $ cfRange );
@@ -486,16 +468,13 @@ public function duplicatesDataProvider(): array
486
468
*/
487
469
public function testCrossWorksheetExpressions (string $ sheetname , string $ cellAddress , bool $ expectedMatch ): void
488
470
{
471
+ $ this ->spreadsheet = $ this ->loadSpreadsheet ();
489
472
$ worksheet = $ this ->spreadsheet ->getSheetByName ($ sheetname );
490
- if ($ worksheet === null ) {
491
- self ::markTestSkipped ("{$ sheetname } not found in test workbook " );
492
- }
473
+ self ::assertNotNull ($ worksheet , "$ sheetname not found in test workbook " );
493
474
$ cell = $ worksheet ->getCell ($ cellAddress );
494
475
495
476
$ cfRange = $ worksheet ->getConditionalRange ($ cell ->getCoordinate ());
496
- if ($ cfRange === null ) {
497
- self ::markTestSkipped ("{$ cellAddress } is not in a Conditional Format range " );
498
- }
477
+ self ::assertNotNull ($ cfRange , "$ cellAddress is not in a Conditional Format range " );
499
478
$ cfStyle = $ worksheet ->getConditionalStyles ($ cell ->getCoordinate ());
500
479
501
480
$ matcher = new CellMatcher ($ cell , $ cfRange );
0 commit comments