From 6344bfa779bb7b18158c5fbae6a73a6f799ba8cb Mon Sep 17 00:00:00 2001 From: Jonas Renggli Date: Sun, 11 May 2025 16:22:34 +0200 Subject: [PATCH] [php-flight] fix: use static PHPUnit assertions (#21253) Static analysis tools such as PHPStan report errors when dynamic calls are used for static methods. ``` ERROR Dynamic call to static method PHPUnit\Framework\Assert::assertEquals(). ``` According to the source code of PHPUnit (https://github.com/sebastianbergmann/phpunit/blob/9.5.0/src/Framework/Assert.php) the function is indeed static. ```php public static function assertTrue($condition, string $message = ''): void ``` This change updates to PHP Flight test template `register_routes_test.mustache` to use static calls for PHPUnit assertions. --- .../php-flight/register_routes_test.mustache | 4 ++-- .../petstore/php-flight/Test/RegisterRoutesTest.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-flight/register_routes_test.mustache b/modules/openapi-generator/src/main/resources/php-flight/register_routes_test.mustache index ad45d9fcca6..cdb3e8cc265 100644 --- a/modules/openapi-generator/src/main/resources/php-flight/register_routes_test.mustache +++ b/modules/openapi-generator/src/main/resources/php-flight/register_routes_test.mustache @@ -26,7 +26,7 @@ class RegisterRoutesTest extends \PHPUnit\Framework\TestCase { {{/operations}} }; \{{invokerPackage}}\RegisterRoutes::registerRoutes($handler); - $this->assertTrue(true); + self::assertTrue(true); } {{/apis}} {{#models}} @@ -41,7 +41,7 @@ class RegisterRoutesTest extends \PHPUnit\Framework\TestCase { {{/-first}} {{/enumVars}} {{/allowableValues}} - $this->assertEquals( + self::assertEquals( parseParam($value, '\\{{escapedModelPackage}}\\{{classname}}'), \{{modelPackage}}\{{classname}}::{{#allowableValues}}{{#enumVars}}{{#-first}}{{{name}}}{{/-first}}{{/enumVars}}{{/allowableValues}} ); diff --git a/samples/server/petstore/php-flight/Test/RegisterRoutesTest.php b/samples/server/petstore/php-flight/Test/RegisterRoutesTest.php index 737debbe455..e95aed2e9f8 100644 --- a/samples/server/petstore/php-flight/Test/RegisterRoutesTest.php +++ b/samples/server/petstore/php-flight/Test/RegisterRoutesTest.php @@ -29,7 +29,7 @@ class RegisterRoutesTest extends \PHPUnit\Framework\TestCase { } }; \OpenAPIServer\RegisterRoutes::registerRoutes($handler); - $this->assertTrue(true); + self::assertTrue(true); } public function testRegisterRoutesAbstractStoreApi(): void { @@ -39,7 +39,7 @@ class RegisterRoutesTest extends \PHPUnit\Framework\TestCase { } }; \OpenAPIServer\RegisterRoutes::registerRoutes($handler); - $this->assertTrue(true); + self::assertTrue(true); } public function testRegisterRoutesAbstractUserApi(): void { @@ -49,12 +49,12 @@ class RegisterRoutesTest extends \PHPUnit\Framework\TestCase { } }; \OpenAPIServer\RegisterRoutes::registerRoutes($handler); - $this->assertTrue(true); + self::assertTrue(true); } public function testParseParamsEnumFindPetsByStatusStatusParameterInner(): void { $value = 'available'; - $this->assertEquals( + self::assertEquals( parseParam($value, '\\OpenAPIServer\\Model\\FindPetsByStatusStatusParameterInner'), \OpenAPIServer\Model\FindPetsByStatusStatusParameterInner::AVAILABLE ); @@ -62,7 +62,7 @@ class RegisterRoutesTest extends \PHPUnit\Framework\TestCase { public function testParseParamsEnumOrderStatus(): void { $value = 'placed'; - $this->assertEquals( + self::assertEquals( parseParam($value, '\\OpenAPIServer\\Model\\OrderStatus'), \OpenAPIServer\Model\OrderStatus::PLACED ); @@ -70,7 +70,7 @@ class RegisterRoutesTest extends \PHPUnit\Framework\TestCase { public function testParseParamsEnumPetStatus(): void { $value = 'available'; - $this->assertEquals( + self::assertEquals( parseParam($value, '\\OpenAPIServer\\Model\\PetStatus'), \OpenAPIServer\Model\PetStatus::AVAILABLE );