Skip to content

Commit

Permalink
Refactor ShapeFileTest's shapes provider
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Sep 14, 2023
1 parent c5f0ad2 commit 2a4b6cb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 196 deletions.
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ parameters:
count: 1
path: src/ShapeRecord.php

-
message: "#^Cannot access offset 0 on mixed\\.$#"
count: 1
path: tests/ShapeFileTest.php

-
message: "#^Cannot access offset 1 on mixed\\.$#"
count: 1
path: tests/ShapeFileTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 17
Expand All @@ -165,21 +155,11 @@ parameters:
count: 3
path: tests/ShapeFileTest.php

-
message: "#^Parameter \\#1 \\$point of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:addPoint\\(\\) expects array, mixed given\\.$#"
count: 1
path: tests/ShapeFileTest.php

-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
count: 1
path: tests/ShapeFileTest.php

-
message: "#^Parameter \\#2 \\$partIndex of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:addPoint\\(\\) expects int, mixed given\\.$#"
count: 1
path: tests/ShapeFileTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 1
Expand Down
224 changes: 48 additions & 176 deletions tests/ShapeFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,33 +307,19 @@ public function testShapeName(): void
}

/**
* Test shapes save/load round robin.
* Test shapes save/load round-robin.
*
* @param int $type Shape type
* @param mixed[] $points Points
* @psalm-param list<array{mixed[], int}> $points
*
* @dataProvider shapes
* @dataProvider shapesProvider
*/
public function testShapeSaveLoad(int $type, array $points): void
public function testShapeSaveLoad(int $shapeType, array $points): void
{
$filename = './data/test_shape-' . $type . '.*';
$shp = new ShapeFile($type);
$shp->setDBFHeader([
[
'ID',
'N',
19,
0,
],
[
'DESC',
'C',
14,
0,
],
]);
$filename = './data/test_shape-' . $shapeType . '.*';
$shp = new ShapeFile($shapeType);
$shp->setDBFHeader([['ID', 'N', 19, 0], ['DESC', 'C', 14, 0]]);

$record0 = new ShapeRecord($type);
$record0 = new ShapeRecord($shapeType);

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

$shp->saveToFile($filename);

$shp2 = new ShapeFile($type);
$shp2 = new ShapeFile($shapeType);
$shp2->loadFromFile($filename);

$this->assertEquals(
count($shp->records),
count($shp2->records),
);
$this->assertEquals(count($shp->records), count($shp2->records));

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

$items = [
'numparts',
'numpoints',
];
$items = ['numparts', 'numpoints'];
foreach ($items as $item) {
if (! isset($record->shpData[$item])) {
continue;
Expand All @@ -371,157 +351,49 @@ public function testShapeSaveLoad(int $type, array $points): void
}

/**
* Test shapes save/load round robin with z coordinate.
*
* @param int $type Shape type
* @param mixed[] $points Points
* Data provider for save/load testing.
*
* @dataProvider shapes
* @psalm-return list<array{int, list<array{mixed[], int}>}>
*/
public function testZetShapeSaveLoad(int $type, array $points): void
public static function shapesProvider(): array
{
$this->testShapeSaveLoad($type + 10, $points);
}
$pointsForPointType = [[['x' => 10, 'y' => 20], 0]];

/**
* Test shapes save/load round robin with measure.
*
* @param int $type Shape type
* @param mixed[] $points Points
*
* @dataProvider shapes
*/
public function testMeasureShapeSaveLoad(int $type, array $points): void
{
$this->testShapeSaveLoad($type + 20, $points);
}
$pointsForPolyLineType = [
[['x' => 10, 'y' => 20], 0],
[['x' => 20, 'y' => 20], 0],
[['x' => 20, 'y' => 20], 1],
[['x' => 20, 'y' => 10], 1],
];

$pointsForPolygonType = [
[['x' => 10, 'y' => 20], 0],
[['x' => 20, 'y' => 20], 0],
[['x' => 20, 'y' => 20], 1],
[['x' => 20, 'y' => 10], 1],
[['x' => 20, 'y' => 10], 2],
[['x' => 10, 'y' => 20], 2],
];

$pointsForMultiPointType = [
[['x' => 10, 'y' => 20], 0],
[['x' => 20, 'y' => 20], 0],
[['x' => 20, 'y' => 10], 0],
];

/**
* Data provider for save/load testing.
*
* @psalm-return list<array{int, mixed[]}>
*/
public static function shapes(): array
{
return [
[
1,
[
[
[
'x' => 10,
'y' => 20,
],
0,
],
],
],
[
3,
[
[
[
'x' => 10,
'y' => 20,
],
0,
],
[
[
'x' => 20,
'y' => 20,
],
0,
],
[
[
'x' => 20,
'y' => 20,
],
1,
],
[
[
'x' => 20,
'y' => 10,
],
1,
],
],
],
[
5,
[
[
[
'x' => 10,
'y' => 20,
],
0,
],
[
[
'x' => 20,
'y' => 20,
],
0,
],
[
[
'x' => 20,
'y' => 20,
],
1,
],
[
[
'x' => 20,
'y' => 10,
],
1,
],
[
[
'x' => 20,
'y' => 10,
],
2,
],
[
[
'x' => 10,
'y' => 20,
],
2,
],
],
],
[
8,
[
[
[
'x' => 10,
'y' => 20,
],
0,
],
[
[
'x' => 20,
'y' => 20,
],
0,
],
[
[
'x' => 20,
'y' => 10,
],
0,
],
],
],
[1, $pointsForPointType],
[3, $pointsForPolyLineType],
[5, $pointsForPolygonType],
[8, $pointsForMultiPointType],
[11, $pointsForPointType],
[13, $pointsForPolyLineType],
[15, $pointsForPolygonType],
[18, $pointsForMultiPointType],
[21, $pointsForPointType],
[23, $pointsForPolyLineType],
[25, $pointsForPolygonType],
[28, $pointsForMultiPointType],
];
}

Expand Down

0 comments on commit 2a4b6cb

Please sign in to comment.