Skip to content

Commit

Permalink
Merge pull request #37 from JoolsMcFly/chore/remove-dynamic-calls-to-…
Browse files Browse the repository at this point in the history
…static-methods

PhpUnit: remove dynamic calls to static methods
  • Loading branch information
MauricioFauth authored Oct 12, 2024
2 parents d8550ba + 645823c commit 8248afe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 55 deletions.
30 changes: 0 additions & 30 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,7 @@ parameters:
count: 1
path: src/ShapeRecord.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 18
path: tests/ShapeFileTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileDoesNotExist\\(\\)\\.$#"
count: 1
path: tests/ShapeFileTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotEquals\\(\\)\\.$#"
count: 1
path: tests/ShapeFileTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNull\\(\\)\\.$#"
count: 1
path: tests/ShapeFileTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#"
count: 3
path: tests/ShapeFileTest.php

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

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 1
path: tests/UtilTest.php
48 changes: 24 additions & 24 deletions tests/ShapeFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public function testLoad(string $filename, int $records, int|null $parts): void
{
$shp = new ShapeFile(ShapeType::Point);
$shp->loadFromFile($filename);
$this->assertEquals('', $shp->lastError);
$this->assertEquals($records, count($shp->records));
self::assertEquals('', $shp->lastError);
self::assertEquals($records, count($shp->records));
if ($parts === null) {
return;
}

$this->assertEquals($parts, count($shp->records[0]->shpData['parts']));
self::assertEquals($parts, count($shp->records[0]->shpData['parts']));
}

/**
Expand Down Expand Up @@ -108,7 +108,7 @@ public function testLoadError(string $filename): void
{
$shp = new ShapeFile(ShapeType::Point);
$shp->loadFromFile($filename);
$this->assertNotEquals('', $shp->lastError);
self::assertNotEquals('', $shp->lastError);
}

/**
Expand All @@ -119,12 +119,12 @@ public function testLoadEmptyFilename(): void
$shp = new ShapeFile(ShapeType::Point);
$shp->loadFromFile('');
if (ShapeFile::supportsDbase()) {
$this->assertEquals('It wasn\'t possible to find the DBase file ""', $shp->lastError);
self::assertEquals('It wasn\'t possible to find the DBase file ""', $shp->lastError);

return;
}

$this->assertEquals('Not a SHP file (file code mismatch)', $shp->lastError);
self::assertEquals('Not a SHP file (file code mismatch)', $shp->lastError);
}

/**
Expand All @@ -133,7 +133,7 @@ public function testLoadEmptyFilename(): void
public function testGetDBFHeader(): void
{
$shp = new ShapeFile(ShapeType::Point);
$this->assertNull($shp->getDBFHeader());
self::assertNull($shp->getDBFHeader());
}

/**
Expand Down Expand Up @@ -222,14 +222,14 @@ private function createTestData(): void
public function testCreate(): void
{
if (! ShapeFile::supportsDbase()) {
$this->markTestSkipped('dbase extension missing');
self::markTestSkipped('dbase extension missing');
}

$this->createTestData();

$shp = new ShapeFile(ShapeType::Point);
$shp->loadFromFile('./data/test_shape.*');
$this->assertEquals(4, count($shp->records));
self::assertEquals(4, count($shp->records));
}

/**
Expand All @@ -238,7 +238,7 @@ public function testCreate(): void
public function testDelete(): void
{
if (! ShapeFile::supportsDbase()) {
$this->markTestSkipped('dbase extension missing');
self::markTestSkipped('dbase extension missing');
}

$this->createTestData();
Expand All @@ -247,11 +247,11 @@ public function testDelete(): void
$shp->loadFromFile('./data/test_shape.*');
$shp->deleteRecord(1);
$shp->saveToFile();
$this->assertEquals(3, count($shp->records));
self::assertEquals(3, count($shp->records));

$shp = new ShapeFile(ShapeType::Point);
$shp->loadFromFile('./data/test_shape.*');
$this->assertEquals(3, count($shp->records));
self::assertEquals(3, count($shp->records));
}

/**
Expand All @@ -260,7 +260,7 @@ public function testDelete(): void
public function testAdd(): void
{
if (! ShapeFile::supportsDbase()) {
$this->markTestSkipped('dbase extension missing');
self::markTestSkipped('dbase extension missing');
}

$this->createTestData();
Expand All @@ -276,11 +276,11 @@ public function testAdd(): void
$shp->records[4]->dbfData['DESC'] = 'CCCCCCCCCCC';

$shp->saveToFile();
$this->assertEquals(5, count($shp->records));
self::assertEquals(5, count($shp->records));

$shp = new ShapeFile(ShapeType::Point);
$shp->loadFromFile('./data/test_shape.*');
$this->assertEquals(5, count($shp->records));
self::assertEquals(5, count($shp->records));
}

/**
Expand All @@ -291,7 +291,7 @@ public function testSaveNoDBF(): void
$shp = new ShapeFile(ShapeType::Point);
$shp->saveToFile('./data/test_nodbf.*');

$this->assertFileDoesNotExist('./data/test_nodbf.dbf');
self::assertFileDoesNotExist('./data/test_nodbf.dbf');
}

/**
Expand All @@ -300,13 +300,13 @@ public function testSaveNoDBF(): void
public function testShapeName(): void
{
$obj = new ShapeRecord(ShapeType::Point);
$this->assertEquals('Point', $obj->getShapeName());
self::assertEquals('Point', $obj->getShapeName());
$obj = new ShapeFile(ShapeType::Point);
$this->assertEquals('Point', $obj->getShapeName());
self::assertEquals('Point', $obj->getShapeName());
$obj = new ShapeRecord(ShapeType::Null);
$this->assertEquals('Null Shape', $obj->getShapeName());
self::assertEquals('Null Shape', $obj->getShapeName());
$obj = new ShapeRecord(ShapeType::Unknown);
$this->assertEquals('Unknown Shape', $obj->getShapeName());
self::assertEquals('Unknown Shape', $obj->getShapeName());
}

/**
Expand Down Expand Up @@ -335,7 +335,7 @@ public function testShapeSaveLoad(ShapeType $shapeType, array $points): void
$shp2 = new ShapeFile($shapeType);
$shp2->loadFromFile($filename);

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

$record = $shp->records[0];
$record2 = $shp2->records[0];
Expand All @@ -346,7 +346,7 @@ public function testShapeSaveLoad(ShapeType $shapeType, array $points): void
continue;
}

$this->assertEquals($record->shpData[$item], $record2->shpData[$item]);
self::assertEquals($record->shpData[$item], $record2->shpData[$item]);
}

/* Test deletion works */
Expand Down Expand Up @@ -405,15 +405,15 @@ public function testSearch(): void
$shp = new ShapeFile(ShapeType::Null);
$shp->loadFromFile('data/capitals.*');
/* Nonexisting entry or no dbase support */
$this->assertEquals(
self::assertEquals(
-1,
$shp->getIndexFromDBFData('CNTRY_NAME', 'nonexisting'),
);
if (! ShapeFile::supportsDbase()) {
return;
}

$this->assertEquals(
self::assertEquals(
218,
$shp->getIndexFromDBFData('CNTRY_NAME', 'Czech Republic'),
);
Expand Down
2 changes: 1 addition & 1 deletion tests/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UtilTest extends TestCase
*/
public function testLoadData(string $type, string|false $data, mixed $expected): void
{
$this->assertEquals(
self::assertEquals(
$expected,
Util::loadData($type, $data),
);
Expand Down

0 comments on commit 8248afe

Please sign in to comment.