Skip to content

Commit 2a4b6cb

Browse files
committed
Refactor ShapeFileTest's shapes provider
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent c5f0ad2 commit 2a4b6cb

2 files changed

Lines changed: 48 additions & 196 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,6 @@ parameters:
130130
count: 1
131131
path: src/ShapeRecord.php
132132

133-
-
134-
message: "#^Cannot access offset 0 on mixed\\.$#"
135-
count: 1
136-
path: tests/ShapeFileTest.php
137-
138-
-
139-
message: "#^Cannot access offset 1 on mixed\\.$#"
140-
count: 1
141-
path: tests/ShapeFileTest.php
142-
143133
-
144134
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
145135
count: 17
@@ -165,21 +155,11 @@ parameters:
165155
count: 3
166156
path: tests/ShapeFileTest.php
167157

168-
-
169-
message: "#^Parameter \\#1 \\$point of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:addPoint\\(\\) expects array, mixed given\\.$#"
170-
count: 1
171-
path: tests/ShapeFileTest.php
172-
173158
-
174159
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
175160
count: 1
176161
path: tests/ShapeFileTest.php
177162

178-
-
179-
message: "#^Parameter \\#2 \\$partIndex of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:addPoint\\(\\) expects int, mixed given\\.$#"
180-
count: 1
181-
path: tests/ShapeFileTest.php
182-
183163
-
184164
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
185165
count: 1

tests/ShapeFileTest.php

Lines changed: 48 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -307,33 +307,19 @@ public function testShapeName(): void
307307
}
308308

309309
/**
310-
* Test shapes save/load round robin.
310+
* Test shapes save/load round-robin.
311311
*
312-
* @param int $type Shape type
313-
* @param mixed[] $points Points
312+
* @psalm-param list<array{mixed[], int}> $points
314313
*
315-
* @dataProvider shapes
314+
* @dataProvider shapesProvider
316315
*/
317-
public function testShapeSaveLoad(int $type, array $points): void
316+
public function testShapeSaveLoad(int $shapeType, array $points): void
318317
{
319-
$filename = './data/test_shape-' . $type . '.*';
320-
$shp = new ShapeFile($type);
321-
$shp->setDBFHeader([
322-
[
323-
'ID',
324-
'N',
325-
19,
326-
0,
327-
],
328-
[
329-
'DESC',
330-
'C',
331-
14,
332-
0,
333-
],
334-
]);
318+
$filename = './data/test_shape-' . $shapeType . '.*';
319+
$shp = new ShapeFile($shapeType);
320+
$shp->setDBFHeader([['ID', 'N', 19, 0], ['DESC', 'C', 14, 0]]);
335321

336-
$record0 = new ShapeRecord($type);
322+
$record0 = new ShapeRecord($shapeType);
337323

338324
foreach ($points as $point) {
339325
$record0->addPoint($point[0], $point[1]);
@@ -343,21 +329,15 @@ public function testShapeSaveLoad(int $type, array $points): void
343329

344330
$shp->saveToFile($filename);
345331

346-
$shp2 = new ShapeFile($type);
332+
$shp2 = new ShapeFile($shapeType);
347333
$shp2->loadFromFile($filename);
348334

349-
$this->assertEquals(
350-
count($shp->records),
351-
count($shp2->records),
352-
);
335+
$this->assertEquals(count($shp->records), count($shp2->records));
353336

354337
$record = $shp->records[0];
355338
$record2 = $shp2->records[0];
356339

357-
$items = [
358-
'numparts',
359-
'numpoints',
360-
];
340+
$items = ['numparts', 'numpoints'];
361341
foreach ($items as $item) {
362342
if (! isset($record->shpData[$item])) {
363343
continue;
@@ -371,157 +351,49 @@ public function testShapeSaveLoad(int $type, array $points): void
371351
}
372352

373353
/**
374-
* Test shapes save/load round robin with z coordinate.
375-
*
376-
* @param int $type Shape type
377-
* @param mixed[] $points Points
354+
* Data provider for save/load testing.
378355
*
379-
* @dataProvider shapes
356+
* @psalm-return list<array{int, list<array{mixed[], int}>}>
380357
*/
381-
public function testZetShapeSaveLoad(int $type, array $points): void
358+
public static function shapesProvider(): array
382359
{
383-
$this->testShapeSaveLoad($type + 10, $points);
384-
}
360+
$pointsForPointType = [[['x' => 10, 'y' => 20], 0]];
385361

386-
/**
387-
* Test shapes save/load round robin with measure.
388-
*
389-
* @param int $type Shape type
390-
* @param mixed[] $points Points
391-
*
392-
* @dataProvider shapes
393-
*/
394-
public function testMeasureShapeSaveLoad(int $type, array $points): void
395-
{
396-
$this->testShapeSaveLoad($type + 20, $points);
397-
}
362+
$pointsForPolyLineType = [
363+
[['x' => 10, 'y' => 20], 0],
364+
[['x' => 20, 'y' => 20], 0],
365+
[['x' => 20, 'y' => 20], 1],
366+
[['x' => 20, 'y' => 10], 1],
367+
];
368+
369+
$pointsForPolygonType = [
370+
[['x' => 10, 'y' => 20], 0],
371+
[['x' => 20, 'y' => 20], 0],
372+
[['x' => 20, 'y' => 20], 1],
373+
[['x' => 20, 'y' => 10], 1],
374+
[['x' => 20, 'y' => 10], 2],
375+
[['x' => 10, 'y' => 20], 2],
376+
];
377+
378+
$pointsForMultiPointType = [
379+
[['x' => 10, 'y' => 20], 0],
380+
[['x' => 20, 'y' => 20], 0],
381+
[['x' => 20, 'y' => 10], 0],
382+
];
398383

399-
/**
400-
* Data provider for save/load testing.
401-
*
402-
* @psalm-return list<array{int, mixed[]}>
403-
*/
404-
public static function shapes(): array
405-
{
406384
return [
407-
[
408-
1,
409-
[
410-
[
411-
[
412-
'x' => 10,
413-
'y' => 20,
414-
],
415-
0,
416-
],
417-
],
418-
],
419-
[
420-
3,
421-
[
422-
[
423-
[
424-
'x' => 10,
425-
'y' => 20,
426-
],
427-
0,
428-
],
429-
[
430-
[
431-
'x' => 20,
432-
'y' => 20,
433-
],
434-
0,
435-
],
436-
[
437-
[
438-
'x' => 20,
439-
'y' => 20,
440-
],
441-
1,
442-
],
443-
[
444-
[
445-
'x' => 20,
446-
'y' => 10,
447-
],
448-
1,
449-
],
450-
],
451-
],
452-
[
453-
5,
454-
[
455-
[
456-
[
457-
'x' => 10,
458-
'y' => 20,
459-
],
460-
0,
461-
],
462-
[
463-
[
464-
'x' => 20,
465-
'y' => 20,
466-
],
467-
0,
468-
],
469-
[
470-
[
471-
'x' => 20,
472-
'y' => 20,
473-
],
474-
1,
475-
],
476-
[
477-
[
478-
'x' => 20,
479-
'y' => 10,
480-
],
481-
1,
482-
],
483-
[
484-
[
485-
'x' => 20,
486-
'y' => 10,
487-
],
488-
2,
489-
],
490-
[
491-
[
492-
'x' => 10,
493-
'y' => 20,
494-
],
495-
2,
496-
],
497-
],
498-
],
499-
[
500-
8,
501-
[
502-
[
503-
[
504-
'x' => 10,
505-
'y' => 20,
506-
],
507-
0,
508-
],
509-
[
510-
[
511-
'x' => 20,
512-
'y' => 20,
513-
],
514-
0,
515-
],
516-
[
517-
[
518-
'x' => 20,
519-
'y' => 10,
520-
],
521-
0,
522-
],
523-
],
524-
],
385+
[1, $pointsForPointType],
386+
[3, $pointsForPolyLineType],
387+
[5, $pointsForPolygonType],
388+
[8, $pointsForMultiPointType],
389+
[11, $pointsForPointType],
390+
[13, $pointsForPolyLineType],
391+
[15, $pointsForPolygonType],
392+
[18, $pointsForMultiPointType],
393+
[21, $pointsForPointType],
394+
[23, $pointsForPolyLineType],
395+
[25, $pointsForPolygonType],
396+
[28, $pointsForMultiPointType],
525397
];
526398
}
527399

0 commit comments

Comments
 (0)