From a585e502725d7e3cfcec25f7a3d59443842006da Mon Sep 17 00:00:00 2001 From: Djordy Koert Date: Sat, 6 Apr 2024 15:56:36 +0200 Subject: [PATCH] remove phpunit 8.5, add phpunit 10.5 (#2258) * remove phpunit 8.5, add phpunit 10.5 * add static to data providers * rename abstract test class * set error handler * remove expection code assertions * update phpunit config * fix test class renamed --- composer.json | 2 +- phpunit.xml.dist | 8 +- tests/Command/DumpCommandTest.php | 4 +- ...Test.php => AbstractDescriberTestCase.php} | 2 +- tests/Describer/ApiPlatformDescriberTest.php | 2 +- tests/Describer/RouteDescriberTest.php | 2 +- tests/Functional/FOSRestTest.php | 2 +- tests/Functional/FunctionalTest.php | 10 +- tests/Model/ModelRegistryTest.php | 6 +- .../Annotations/AnnotationReaderTest.php | 2 +- .../SymfonyConstraintAnnotationReaderTest.php | 20 +-- .../ModelDescriber/FormModelDescriberTest.php | 2 +- tests/Render/Html/GetNelmioAssetTest.php | 14 +- .../RouteMetadataDescriberTest.php | 4 +- .../FilteredRouteCollectionBuilderTest.php | 10 +- tests/SwaggerPhp/UtilTest.php | 145 +++++++++--------- 16 files changed, 123 insertions(+), 112 deletions(-) rename tests/Describer/{AbstractDescriberTest.php => AbstractDescriberTestCase.php} (91%) diff --git a/composer.json b/composer.json index f4f22efc1..3b7235d45 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ "doctrine/annotations": "^2.0", - "phpunit/phpunit": "^8.5|^9.6", + "phpunit/phpunit": "^9.6|^10.5", "friendsofphp/php-cs-fixer": "^3.52", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 92c783b2f..fd747cdbf 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,7 @@ tests + + + + src + + diff --git a/tests/Command/DumpCommandTest.php b/tests/Command/DumpCommandTest.php index e6a4f490e..62d5ced0b 100644 --- a/tests/Command/DumpCommandTest.php +++ b/tests/Command/DumpCommandTest.php @@ -30,7 +30,7 @@ public function testJson(array $jsonOptions, int $expectedJsonFlags) ); } - public function provideJsonMode() + public static function provideJsonMode(): iterable { return [ 'pretty print' => [[], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES], @@ -64,7 +64,7 @@ public function testHtml($htmlConfig, string $expectedHtml) self::assertStringContainsString($expectedHtml, $output); } - public function provideAssetsMode() + public static function provideAssetsMode(): iterable { return [ 'default mode is cdn' => [ diff --git a/tests/Describer/AbstractDescriberTest.php b/tests/Describer/AbstractDescriberTestCase.php similarity index 91% rename from tests/Describer/AbstractDescriberTest.php rename to tests/Describer/AbstractDescriberTestCase.php index 698547712..aceea6fc1 100644 --- a/tests/Describer/AbstractDescriberTest.php +++ b/tests/Describer/AbstractDescriberTestCase.php @@ -16,7 +16,7 @@ use OpenApi\Context; use PHPUnit\Framework\TestCase; -abstract class AbstractDescriberTest extends TestCase +abstract class AbstractDescriberTestCase extends TestCase { /** @var DescriberInterface */ protected $describer; diff --git a/tests/Describer/ApiPlatformDescriberTest.php b/tests/Describer/ApiPlatformDescriberTest.php index f18911e1e..1439874c7 100644 --- a/tests/Describer/ApiPlatformDescriberTest.php +++ b/tests/Describer/ApiPlatformDescriberTest.php @@ -18,7 +18,7 @@ use OpenApi\Context; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; -class ApiPlatformDescriberTest extends AbstractDescriberTest +class ApiPlatformDescriberTest extends AbstractDescriberTestCase { private $documentation; diff --git a/tests/Describer/RouteDescriberTest.php b/tests/Describer/RouteDescriberTest.php index 60e514fdc..005f67e86 100644 --- a/tests/Describer/RouteDescriberTest.php +++ b/tests/Describer/RouteDescriberTest.php @@ -20,7 +20,7 @@ use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; -class RouteDescriberTest extends AbstractDescriberTest +class RouteDescriberTest extends AbstractDescriberTestCase { private $routes; diff --git a/tests/Functional/FOSRestTest.php b/tests/Functional/FOSRestTest.php index d87eb8976..507896c5e 100644 --- a/tests/Functional/FOSRestTest.php +++ b/tests/Functional/FOSRestTest.php @@ -76,7 +76,7 @@ public function testFOSRestAction(string $route) self::assertNotHasParameter('_format', 'path', $operation); } - public function provideRoute(): iterable + public static function provideRoute(): iterable { yield 'Annotations' => ['/api/fosrest']; diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php index 5fcf62777..15145d506 100644 --- a/tests/Functional/FunctionalTest.php +++ b/tests/Functional/FunctionalTest.php @@ -63,7 +63,7 @@ public function testFetchArticleAction(string $articleRoute) $this->assertNotHasProperty('author', Util::getProperty($articleModel, 'author')); } - public function provideArticleRoute(): iterable + public static function provideArticleRoute(): iterable { if (interface_exists(Reader::class)) { yield 'Annotations' => ['/api/article/{id}']; @@ -95,7 +95,7 @@ public function testSwaggerAction(string $path) self::assertEquals('An example resource', $response->description); } - public function swaggerActionPathsProvider() + public static function swaggerActionPathsProvider(): iterable { return [['/api/swagger'], ['/api/swagger2']]; } @@ -133,7 +133,7 @@ public function testImplicitSwaggerAction(string $method) self::assertEquals('#/components/schemas/User', $requestBody->content['application/json']->schema->items->ref); } - public function implicitSwaggerActionMethodsProvider() + public static function implicitSwaggerActionMethodsProvider(): iterable { return [['get'], ['post']]; } @@ -384,7 +384,7 @@ public function testSecurityAction(string $route) self::assertEquals($expected, $operation->security); } - public function provideSecurityRoute(): iterable + public static function provideSecurityRoute(): iterable { yield 'Annotations' => ['/api/security']; @@ -402,7 +402,7 @@ public function testSecurityOverrideAction(string $route) self::assertEquals([], $operation->security); } - public function provideSecurityOverrideRoute(): iterable + public static function provideSecurityOverrideRoute(): iterable { yield 'Annotations' => ['/api/securityOverride']; diff --git a/tests/Model/ModelRegistryTest.php b/tests/Model/ModelRegistryTest.php index f43559f93..2c8a53c0b 100644 --- a/tests/Model/ModelRegistryTest.php +++ b/tests/Model/ModelRegistryTest.php @@ -72,7 +72,7 @@ public function testNameCollisionsAreLogged(Type $type, array $arrayType) $registry->register(new Model($type, ['group2'])); } - public function provideNameCollisionsTypes() + public static function provideNameCollisionsTypes(): iterable { yield [ new Type(Type::BUILTIN_TYPE_OBJECT, false, self::class), @@ -169,7 +169,7 @@ public function testNameAliasingForObjects(string $expected, $groups, array $alt self::assertEquals($expected, $registry->register(new Model($type, $groups))); } - public function getNameAlternatives() + public static function getNameAlternatives(): iterable { return [ [ @@ -238,7 +238,7 @@ public function testUnsupportedTypeException(Type $type, string $stringType) $registry->registerSchemas(); } - public function unsupportedTypesProvider() + public static function unsupportedTypesProvider(): iterable { return [ [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true), 'mixed[]'], diff --git a/tests/ModelDescriber/Annotations/AnnotationReaderTest.php b/tests/ModelDescriber/Annotations/AnnotationReaderTest.php index 19cadd414..4a14f6da9 100644 --- a/tests/ModelDescriber/Annotations/AnnotationReaderTest.php +++ b/tests/ModelDescriber/Annotations/AnnotationReaderTest.php @@ -54,7 +54,7 @@ class_exists(AnnotationReader::class) ? new AnnotationReader() : null, self::assertEquals($schema->properties[1]->description, 'some description'); } - public function provideProperty(): iterable + public static function provideProperty(): iterable { yield 'Annotations' => [new class() { /** diff --git a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php b/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php index 7f4a58204..b3359e1be 100644 --- a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php +++ b/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php @@ -102,7 +102,7 @@ public function testOptionalProperty($entity) self::assertEquals($schema->required, ['property2']); } - public function provideOptionalProperty(): iterable + public static function provideOptionalProperty(): iterable { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ @@ -152,7 +152,7 @@ public function testAssertChoiceResultsInNumericArray($entity) self::assertEquals($schema->properties[0]->enum, ['active', 'blocked']); } - public function provideAssertChoiceResultsInNumericArray(): iterable + public static function provideAssertChoiceResultsInNumericArray(): iterable { define('TEST_ASSERT_CHOICE_STATUSES', [ 1 => 'active', @@ -200,7 +200,7 @@ public function testMultipleChoiceConstraintsApplyEnumToItems($entity) self::assertEquals($schema->properties[0]->items->enum, ['one', 'two']); } - public function provideMultipleChoiceConstraintsApplyEnumToItems(): iterable + public static function provideMultipleChoiceConstraintsApplyEnumToItems(): iterable { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [new class() { @@ -240,7 +240,7 @@ public function testLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet($entity) self::assertSame(1, $schema->properties[0]->minLength); } - public function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet(): iterable + public static function provideLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet(): iterable { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ @@ -282,7 +282,7 @@ public function testLengthConstraintDoesNotSetMinLengthIfMinIsNotSet($entity) self::assertSame(100, $schema->properties[0]->maxLength); } - public function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet(): iterable + public static function provideLengthConstraintDoesNotSetMinLengthIfMinIsNotSet(): iterable { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ @@ -364,7 +364,7 @@ public function testCountConstraintDoesNotSetMinItemsIfMinIsNotSet($entity) self::assertSame(10, $schema->properties[0]->maxItems); } - public function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): iterable + public static function provideCountConstraintDoesNotSetMinItemsIfMinIsNotSet(): iterable { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ @@ -406,7 +406,7 @@ public function testCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet($entity) self::assertSame(10, $schema->properties[0]->minItems); } - public function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): iterable + public static function provideCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet(): iterable { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ @@ -448,7 +448,7 @@ public function testRangeConstraintDoesNotSetMaximumIfMaxIsNotSet($entity) self::assertSame(10, $schema->properties[0]->minimum); } - public function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): iterable + public static function provideRangeConstraintDoesNotSetMaximumIfMaxIsNotSet(): iterable { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ @@ -490,7 +490,7 @@ public function testRangeConstraintDoesNotSetMinimumIfMinIsNotSet($entity) self::assertSame(10, $schema->properties[0]->maximum); } - public function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): iterable + public static function provideRangeConstraintDoesNotSetMinimumIfMinIsNotSet(): iterable { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [ @@ -609,7 +609,7 @@ public function testReaderWithValidationGroupsEnabledCanReadFromMultipleValidati self::assertSame(1, $schema->properties[0]->minimum, 'should have read constraint in other group'); } - public function provideConstraintsWithGroups(): iterable + public static function provideConstraintsWithGroups(): iterable { if (interface_exists(Reader::class) && Kernel::MAJOR_VERSION < 7) { yield 'Annotations' => [new class() { diff --git a/tests/ModelDescriber/FormModelDescriberTest.php b/tests/ModelDescriber/FormModelDescriberTest.php index 928f225e3..4ce1cb818 100644 --- a/tests/ModelDescriber/FormModelDescriberTest.php +++ b/tests/ModelDescriber/FormModelDescriberTest.php @@ -80,7 +80,7 @@ public function testDescribeCreatesTokenPropertyDependingOnOptions(bool $csrfPro } } - public function provideCsrfProtectionOptions(): array + public static function provideCsrfProtectionOptions(): iterable { return [ [true, '_token', true], diff --git a/tests/Render/Html/GetNelmioAssetTest.php b/tests/Render/Html/GetNelmioAssetTest.php index 0c77116fb..1dcf54940 100644 --- a/tests/Render/Html/GetNelmioAssetTest.php +++ b/tests/Render/Html/GetNelmioAssetTest.php @@ -30,17 +30,17 @@ public function test($mode, $asset, $expectedContent) self::assertSame($expectedContent, $twigFunction->getCallable()->__invoke($mode, $asset)); } - public function provideAsset() + public static function provideAsset(): iterable { $cdnDir = 'https://cdn.jsdelivr.net/gh/nelmio/NelmioApiDocBundle/public'; $resourceDir = __DIR__.'/../../../public'; - return $this->provideCss($cdnDir, $resourceDir) - + $this->provideJs($cdnDir, $resourceDir) - + $this->provideImage($cdnDir); + return self::provideCss($cdnDir, $resourceDir) + + self::provideJs($cdnDir, $resourceDir) + + self::provideImage($cdnDir); } - private function provideCss($cdnDir, $resourceDir) + private static function provideCss($cdnDir, $resourceDir): array { return [ 'bundled css' => [ @@ -66,7 +66,7 @@ private function provideCss($cdnDir, $resourceDir) ]; } - private function provideJs($cdnDir, $resourceDir) + private static function provideJs($cdnDir, $resourceDir): array { return [ 'bundled js' => [ @@ -92,7 +92,7 @@ private function provideJs($cdnDir, $resourceDir) ]; } - private function provideImage($cdnDir) + private static function provideImage($cdnDir): array { return [ 'bundled image' => [ diff --git a/tests/RouteDescriber/RouteMetadataDescriberTest.php b/tests/RouteDescriber/RouteMetadataDescriberTest.php index 0940b93f6..81e09a4c9 100644 --- a/tests/RouteDescriber/RouteMetadataDescriberTest.php +++ b/tests/RouteDescriber/RouteMetadataDescriberTest.php @@ -90,7 +90,7 @@ public function testNonEnumPatterns($pattern) self::assertEquals(Generator::UNDEFINED, $getPathParameter->schema->enum); } - public function provideEnumPattern() + public static function provideEnumPattern(): iterable { yield ['1|2|3']; yield ['srf|rtr|rsi']; @@ -98,7 +98,7 @@ public function provideEnumPattern() yield ['srf-1|srf-2']; } - public function provideInvalidEnumPattern() + public static function provideInvalidEnumPattern(): iterable { yield ['|']; yield ['|a']; diff --git a/tests/Routing/FilteredRouteCollectionBuilderTest.php b/tests/Routing/FilteredRouteCollectionBuilderTest.php index 557f97dfa..9bc1d102b 100644 --- a/tests/Routing/FilteredRouteCollectionBuilderTest.php +++ b/tests/Routing/FilteredRouteCollectionBuilderTest.php @@ -112,7 +112,7 @@ public function testFilterWithInvalidOption(array $options) ); } - public function getInvalidOptions(): array + public static function getInvalidOptions(): iterable { return [ [['invalid_option' => null]], @@ -168,7 +168,7 @@ public function testMatchingRoutes(string $name, Route $route, array $options = self::assertCount(1, $filteredRoutes); } - public function getMatchingRoutes(): iterable + public static function getMatchingRoutes(): iterable { yield from [ ['r1', new Route('/api/bar/action1')], @@ -220,7 +220,7 @@ public function testMatchingRoutesWithAnnotation(string $name, Route $route, arr self::assertCount(1, $filteredRoutes); } - public function getMatchingRoutesWithAnnotation(): iterable + public static function getMatchingRoutesWithAnnotation(): iterable { yield from [ 'with annotation only' => [ @@ -270,7 +270,7 @@ public function testNonMatchingRoutes(string $name, Route $route, array $options self::assertCount(0, $filteredRoutes); } - public function getNonMatchingRoutes(): array + public static function getNonMatchingRoutes(): iterable { return [ ['r1', new Route('/api/bar/action1'), ['path_patterns' => ['^/apis']]], @@ -326,7 +326,7 @@ public function testRoutesWithDisabledDefaultRoutes( /** * @return array */ - public function getRoutesWithDisabledDefaultRoutes(): array + public static function getRoutesWithDisabledDefaultRoutes(): iterable { return [ 'non matching route without Annotation' => [ diff --git a/tests/SwaggerPhp/UtilTest.php b/tests/SwaggerPhp/UtilTest.php index 05e4f0659..ff550f7d7 100644 --- a/tests/SwaggerPhp/UtilTest.php +++ b/tests/SwaggerPhp/UtilTest.php @@ -51,7 +51,19 @@ public function setUp(): void parent::setUp(); $this->rootContext = new Context(['isTestingRoot' => true]); - $this->rootAnnotation = $this->createObj(OA\OpenApi::class, ['_context' => $this->rootContext]); + $this->rootAnnotation = self::createObj(OA\OpenApi::class, ['_context' => $this->rootContext]); + + set_error_handler( + static function ($errno, $errstr) { + throw new \Exception($errstr, $errno); + }, + E_ALL + ); + } + + public function tearDown(): void + { + restore_error_handler(); } public function testCreateContextSetsParentContext() @@ -164,18 +176,13 @@ public function testCreateCollectionItemDoesNotAddToUnknownProperty() $collection = 'foobars'; $class = OA\Info::class; - $expectedRegex = "/Property \"foobars\" doesn't exist .*/"; - try { - Util::createCollectionItem($this->rootAnnotation, $collection, $class); - } catch (\Exception $e) { - self::assertMatchesRegularExpression($expectedRegex, $e->getMessage()); - } + self::expectException(\Exception::class); + self::expectExceptionMessage("Property \"foobars\" doesn't exist"); + Util::createCollectionItem($this->rootAnnotation, $collection, $class); - try { - self::assertNull($this->rootAnnotation->{$collection}); /* @phpstan-ignore-line */ - } catch (\Exception $e) { - self::assertMatchesRegularExpression($expectedRegex, $e->getMessage()); - } + self::expectException(\Exception::class); + self::expectExceptionMessage("Property \"foobars\" doesn't exist"); + self::assertNull($this->rootAnnotation->{$collection}); /* @phpstan-ignore-line */ } public function testSearchCollectionItem() @@ -205,11 +212,9 @@ public function testSearchCollectionItem() $search = ['baz' => 'foobar']; - try { - Util::searchCollectionItem($collection, array_merge(\get_object_vars($item2), $search)); - } catch (\Exception $e) { - self::assertSame('Undefined property: stdClass::$baz', $e->getMessage()); - } + self::expectException(\Exception::class); + self::expectExceptionMessage('Undefined property: stdClass::$baz'); + Util::searchCollectionItem($collection, array_merge(\get_object_vars($item2), $search)); // no exception on empty collection self::assertNull(Util::searchCollectionItem([], \get_object_vars($item2))); @@ -231,8 +236,8 @@ public function testSearchIndexedCollectionItem($setup, $asserts) // prepare the haystack array foreach ($items as $assertItem) { - // e.g. $properties[1] = $this->createObj(OA\PathItem::class, ['path' => 'path 1']) - $properties[$assertItem['index']] = $this->createObj($assertItem['class'], [ + // e.g. $properties[1] = self::createObj(OA\PathItem::class, ['path' => 'path 1']) + $properties[$assertItem['index']] = self::createObj($assertItem['class'], [ $assertItem['key'] => $assertItem['value'], ]); } @@ -286,18 +291,18 @@ public function testGetIndexedCollectionItem($setup, $asserts) } } - public function provideIndexedCollectionData(): array + public static function provideIndexedCollectionData(): iterable { return [[ 'setup' => [ 'class' => OA\OpenApi::class, 'paths' => [ - $this->createObj(OA\PathItem::class, ['path' => 'path 0']), + self::createObj(OA\PathItem::class, ['path' => 'path 0']), ], - 'components' => $this->createObj(OA\Components::class, [ + 'components' => self::createObj(OA\Components::class, [ 'parameters' => [ - $this->createObj(OA\Parameter::class, ['parameter' => 'parameter 0']), - $this->createObj(OA\Parameter::class, ['parameter' => 'parameter 1']), + self::createObj(OA\Parameter::class, ['parameter' => 'parameter 0']), + self::createObj(OA\Parameter::class, ['parameter' => 'parameter 1']), ], ]), ], @@ -399,12 +404,12 @@ public function testGetChild($setup, $asserts) } } - public function provideChildData(): array + public static function provideChildData(): iterable { return [[ 'setup' => [ 'class' => OA\PathItem::class, - 'get' => $this->createObj(OA\Get::class, []), + 'get' => self::createObj(OA\Get::class, []), ], 'assert' => [ // fixed within setup @@ -463,13 +468,13 @@ public function testGetOperationParameterReturnsExisting() $name = 'operation name'; $in = 'operation in'; - $parameter = $this->createObj(OA\Parameter::class, ['name' => $name, 'in' => $in]); - $operation = $this->createObj(OA\Get::class, ['parameters' => [ - $this->createObj(OA\Parameter::class, []), - $this->createObj(OA\Parameter::class, ['name' => 'foo']), - $this->createObj(OA\Parameter::class, ['in' => 'bar']), - $this->createObj(OA\Parameter::class, ['name' => $name, 'in' => 'bar']), - $this->createObj(OA\Parameter::class, ['name' => 'foo', 'in' => $in]), + $parameter = self::createObj(OA\Parameter::class, ['name' => $name, 'in' => $in]); + $operation = self::createObj(OA\Get::class, ['parameters' => [ + self::createObj(OA\Parameter::class, []), + self::createObj(OA\Parameter::class, ['name' => 'foo']), + self::createObj(OA\Parameter::class, ['in' => 'bar']), + self::createObj(OA\Parameter::class, ['name' => $name, 'in' => 'bar']), + self::createObj(OA\Parameter::class, ['name' => 'foo', 'in' => $in]), $parameter, ]]); @@ -482,12 +487,12 @@ public function testGetOperationParameterCreatesWithNameAndIn() $name = 'operation name'; $in = 'operation in'; - $operation = $this->createObj(OA\Get::class, ['parameters' => [ - $this->createObj(OA\Parameter::class, []), - $this->createObj(OA\Parameter::class, ['name' => 'foo']), - $this->createObj(OA\Parameter::class, ['in' => 'bar']), - $this->createObj(OA\Parameter::class, ['name' => $name, 'in' => 'bar']), - $this->createObj(OA\Parameter::class, ['name' => 'foo', 'in' => $in]), + $operation = self::createObj(OA\Get::class, ['parameters' => [ + self::createObj(OA\Parameter::class, []), + self::createObj(OA\Parameter::class, ['name' => 'foo']), + self::createObj(OA\Parameter::class, ['in' => 'bar']), + self::createObj(OA\Parameter::class, ['name' => $name, 'in' => 'bar']), + self::createObj(OA\Parameter::class, ['name' => 'foo', 'in' => $in]), ]]); $actual = Util::getOperationParameter($operation, $name, $in); @@ -497,8 +502,8 @@ public function testGetOperationParameterCreatesWithNameAndIn() public function testGetOperationReturnsExisting() { - $get = $this->createObj(OA\Get::class, []); - $path = $this->createObj(OA\PathItem::class, ['get' => $get]); + $get = self::createObj(OA\Get::class, []); + $path = self::createObj(OA\PathItem::class, ['get' => $get]); self::assertSame($get, Util::getOperation($path, 'get')); } @@ -506,7 +511,7 @@ public function testGetOperationReturnsExisting() public function testGetOperationCreatesWithPath() { $pathStr = '/testing/get/path'; - $path = $this->createObj(OA\PathItem::class, ['path' => $pathStr]); + $path = self::createObj(OA\PathItem::class, ['path' => $pathStr]); $get = Util::getOperation($path, 'get'); self::assertInstanceOf(OA\Get::class, $get); @@ -515,7 +520,7 @@ public function testGetOperationCreatesWithPath() public function testMergeWithEmptyArray() { - $api = $this->createObj(OA\OpenApi::class, ['_context' => new Context()]); + $api = self::createObj(OA\OpenApi::class, ['_context' => new Context()]); $expected = json_encode($api); Util::merge($api, [], false); @@ -534,7 +539,7 @@ public function testMergeWithEmptyArray() */ public function testMerge($setup, $merge, $assert) { - $api = $this->createObj(OA\OpenApi::class, $setup + ['_context' => new Context()]); + $api = self::createObj(OA\OpenApi::class, $setup + ['_context' => new Context()]); Util::merge($api, $merge, false); self::assertTrue($api->validate()); @@ -543,7 +548,7 @@ public function testMerge($setup, $merge, $assert) self::assertEquals($assert, $actual); } - public function provideMergeData(): array + public static function provideMergeData(): array { $no = 'do not overwrite'; $yes = 'do overwrite'; @@ -551,7 +556,7 @@ public function provideMergeData(): array $requiredInfo = ['title' => '', 'version' => '']; $setupDefaults = [ - 'info' => $this->createObj(OA\Info::class, $requiredInfo), + 'info' => self::createObj(OA\Info::class, $requiredInfo), 'paths' => [], ]; $assertDefaults = [ @@ -563,7 +568,7 @@ public function provideMergeData(): array return [[ // simple child merge 'setup' => [ - 'info' => $this->createObj(OA\Info::class, ['version' => $no]), + 'info' => self::createObj(OA\Info::class, ['version' => $no]), 'paths' => [], ], 'merge' => [ @@ -594,9 +599,9 @@ public function provideMergeData(): array ], [ // indexed collection merge 'setup' => [ - 'components' => $this->createObj(OA\Components::class, [ + 'components' => self::createObj(OA\Components::class, [ 'schemas' => [ - $this->createObj(OA\Schema::class, ['schema' => $no, 'title' => $no]), + self::createObj(OA\Schema::class, ['schema' => $no, 'title' => $no]), ], ]), ] + $setupDefaults, @@ -617,7 +622,7 @@ public function provideMergeData(): array ], [ // collection merge 'setup' => [ - 'tags' => [$this->createObj(OA\Tag::class, ['name' => $no])], + 'tags' => [self::createObj(OA\Tag::class, ['name' => $no])], ] + $setupDefaults, 'merge' => [ 'tags' => [ @@ -766,27 +771,27 @@ public function provideMergeData(): array ], [ // heavy nested merge swagger instance 'setup' => $setupDefaults, - 'merge' => $this->createObj(OA\OpenApi::class, [ + 'merge' => self::createObj(OA\OpenApi::class, [ 'servers' => [ - $this->createObj(OA\Server::class, ['url' => 'http']), - $this->createObj(OA\Server::class, ['url' => 'https']), + self::createObj(OA\Server::class, ['url' => 'http']), + self::createObj(OA\Server::class, ['url' => 'https']), ], 'paths' => [ - $this->createObj(OA\PathItem::class, [ + self::createObj(OA\PathItem::class, [ 'path' => '/path/to/resource', - 'get' => $this->createObj(OA\Get::class, [ + 'get' => self::createObj(OA\Get::class, [ 'responses' => [ - $this->createObj(OA\Response::class, [ + self::createObj(OA\Response::class, [ 'response' => '200', 'ref' => '#/components/responses/default', ]), ], - 'requestBody' => $this->createObj(OA\RequestBody::class, [ + 'requestBody' => self::createObj(OA\RequestBody::class, [ 'description' => 'request foo', 'content' => [ - $this->createObj(OA\MediaType::class, [ + self::createObj(OA\MediaType::class, [ 'mediaType' => 'foo-request', - 'schema' => $this->createObj(OA\Schema::class, [ + 'schema' => self::createObj(OA\Schema::class, [ 'type' => 'object', 'required' => ['baz', 'bar'], ]), @@ -797,23 +802,23 @@ public function provideMergeData(): array ]), ], 'tags' => [ - $this->createObj(OA\Tag::class, ['name' => 'baz']), - $this->createObj(OA\Tag::class, ['name' => 'foo']), - $this->createObj(OA\Tag::class, ['name' => 'baz']), - $this->createObj(OA\Tag::class, ['name' => 'foo']), - $this->createObj(OA\Tag::class, ['name' => 'foo']), + self::createObj(OA\Tag::class, ['name' => 'baz']), + self::createObj(OA\Tag::class, ['name' => 'foo']), + self::createObj(OA\Tag::class, ['name' => 'baz']), + self::createObj(OA\Tag::class, ['name' => 'foo']), + self::createObj(OA\Tag::class, ['name' => 'foo']), ], - 'components' => $this->createObj(OA\Components::class, [ + 'components' => self::createObj(OA\Components::class, [ 'responses' => [ - $this->createObj(OA\Response::class, [ + self::createObj(OA\Response::class, [ 'response' => 'default', 'description' => 'default response', 'headers' => [ - $this->createObj(OA\Header::class, [ + self::createObj(OA\Header::class, [ 'header' => 'foo-header', - 'schema' => $this->createObj(OA\Schema::class, [ + 'schema' => self::createObj(OA\Schema::class, [ 'type' => 'array', - 'items' => $this->createObj(OA\Items::class, [ + 'items' => self::createObj(OA\Items::class, [ 'type' => 'string', 'enum' => ['foo', 'bar', 'baz'], ]), @@ -867,7 +872,7 @@ private function getNonDefaultProperties($object) return $props; } - private function createObj(string $className, array $props = []) + private static function createObj(string $className, array $props = []) { return new $className($props + ['_context' => new Context()]); }