From 3b15bb8a4e5e9b072c263e7e643ad20d7223944a Mon Sep 17 00:00:00 2001 From: Daniel Metzner <40868718+dmetzner@users.noreply.github.com> Date: Sat, 25 Jun 2022 14:53:21 +0200 Subject: [PATCH] [PHP] Enhance Symfony generator (#12532) * Enhance Symfony generator - Add missing typehints - Add missing use statements - Simplify model ctor - Change fallthrough Exception to Throwable - prevent storing result of void methods - fix validate method - add default null values to model properties - simplify API interface return values - fix/rework default value implementation - fix optional params deprecation warnings - .. For more details check out the PR: https://github.com/OpenAPITools/openapi-generator/pull/12532 * Enhance Symfony generator Tests - Skip risky tests - Fix type hint error - Fix class exists tests - Fix broken doc block - Enhance annotations - Update phpunit.xml.dist - Fix test config resource location --- .../languages/PhpSymfonyServerCodegen.java | 86 ++++++++++--------- .../resources/php-symfony/ApiServer.mustache | 8 +- .../resources/php-symfony/Controller.mustache | 65 ++++++++++---- .../resources/php-symfony/Extension.mustache | 2 +- .../resources/php-symfony/README.mustache | 2 +- .../main/resources/php-symfony/api.mustache | 13 +-- .../php-symfony/api_controller.mustache | 13 +-- .../resources/php-symfony/api_doc.mustache | 2 +- .../php-symfony/model_generic.mustache | 12 +-- .../php-symfony/model_variables.mustache | 4 +- .../serialization/JmsSerializer.mustache | 26 ++++-- .../SerializerInterface.mustache | 6 +- .../php-symfony/testing/AppKernel.mustache | 15 ++-- .../testing/ControllerTest.mustache | 13 +-- .../php-symfony/testing/api_test.mustache | 14 +-- .../php-symfony/testing/model_test.mustache | 23 +++-- .../php-symfony/testing/phpunit.xml.mustache | 22 ++--- .../php-symfony/testing/test_config.yml | 2 +- .../validation/SymfonyValidator.mustache | 2 +- .../validation/ValidatorInterface.mustache | 3 + .../SymfonyBundle-php/Api/ApiServer.php | 8 +- .../SymfonyBundle-php/Api/PetApiInterface.php | 86 ++++++++++--------- .../Api/StoreApiInterface.php | 36 ++++---- .../Api/UserApiInterface.php | 66 +++++++------- .../Controller/Controller.php | 65 ++++++++++---- .../Controller/PetController.php | 28 +++--- .../Controller/StoreController.php | 14 +-- .../Controller/UserController.php | 36 +++++--- .../OpenAPIServerExtension.php | 2 +- .../SymfonyBundle-php/Model/ApiResponse.php | 26 +++--- .../SymfonyBundle-php/Model/Category.php | 18 ++-- .../SymfonyBundle-php/Model/Order.php | 48 +++++------ .../SymfonyBundle-php/Model/Pet.php | 70 +++++++-------- .../SymfonyBundle-php/Model/Tag.php | 18 ++-- .../SymfonyBundle-php/Model/User.php | 66 +++++++------- .../php-symfony/SymfonyBundle-php/README.md | 2 +- .../Resources/docs/Api/PetApiInterface.md | 16 ++-- .../Resources/docs/Api/StoreApiInterface.md | 8 +- .../Resources/docs/Api/UserApiInterface.md | 16 ++-- .../Service/JmsSerializer.php | 26 ++++-- .../Service/SerializerInterface.php | 6 +- .../Service/SymfonyValidator.php | 2 +- .../Service/ValidatorInterface.php | 3 + .../Tests/Api/PetApiInterfaceTest.php | 39 +++++---- .../Tests/Api/StoreApiInterfaceTest.php | 27 +++--- .../Tests/Api/UserApiInterfaceTest.php | 39 +++++---- .../SymfonyBundle-php/Tests/AppKernel.php | 15 ++-- .../Tests/Controller/ControllerTest.php | 13 +-- .../Tests/Model/ApiResponseTest.php | 35 ++++++-- .../Tests/Model/CategoryTest.php | 29 +++++-- .../Tests/Model/OrderTest.php | 53 +++++++++--- .../SymfonyBundle-php/Tests/Model/PetTest.php | 53 +++++++++--- .../SymfonyBundle-php/Tests/Model/TagTest.php | 29 +++++-- .../Tests/Model/UserTest.php | 65 +++++++++++--- .../SymfonyBundle-php/Tests/test_config.yml | 2 +- .../SymfonyBundle-php/phpunit.xml.dist | 22 ++--- 56 files changed, 862 insertions(+), 558 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index 6b998abf06c1..ea70427fb3f9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -373,23 +373,15 @@ public void processOpts() { // Type-hintable primitive types // ref: http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration - if (phpLegacySupport) { - typeHintable = new HashSet<>( - Arrays.asList( - "array" - ) - ); - } else { - typeHintable = new HashSet<>( - Arrays.asList( - "array", - "bool", - "float", - "int", - "string" - ) - ); - } + typeHintable = new HashSet<>( + Arrays.asList( + "array", + "bool", + "float", + "int", + "string" + ) + ); } @Override @@ -419,32 +411,24 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, Listapis[$api])) { throw new \InvalidArgumentException('API has already a handler: '.$api); @@ -59,7 +61,7 @@ class ApiServer * @return mixed Returns a handler * @throws \InvalidArgumentException When no such handler exists */ - public function getApiHandler($api) + public function getApiHandler(string $api) { if (!isset($this->apis[$api])) { throw new \InvalidArgumentException('No handler for '.$api.' implemented.'); diff --git a/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache b/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache index 9b0c16fdb004..9366004e84b9 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache @@ -19,10 +19,12 @@ namespace {{controllerPackage}}; +use {{apiPackage}}\ApiServer; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\Validator\ConstraintViolation; use {{servicePackage}}\SerializerInterface; use {{servicePackage}}\ValidatorInterface; @@ -36,23 +38,29 @@ use {{servicePackage}}\ValidatorInterface; */ class Controller extends AbstractController { - protected $validator; - protected $serializer; - protected $apiServer; + protected ValidatorInterface $validator; + protected SerializerInterface $serializer; + protected ApiServer $apiServer; - public function setValidator(ValidatorInterface $validator) + public function setValidator(ValidatorInterface $validator): self { $this->validator = $validator; + + return $this; } - public function setSerializer(SerializerInterface $serializer) + public function setSerializer(SerializerInterface $serializer): self { $this->serializer = $serializer; + + return $this; } - public function setApiServer($server) + public function setApiServer(ApiServer $server): self { $this->apiServer = $server; + + return $this; } /** @@ -63,7 +71,7 @@ class Controller extends AbstractController * * @return Response */ - public function createBadRequestResponse($message = 'Bad Request.') + public function createBadRequestResponse(string $message = 'Bad Request.'): Response { return new Response($message, 400); } @@ -76,7 +84,7 @@ class Controller extends AbstractController * * @return Response */ - public function createErrorResponse(HttpException $exception) + public function createErrorResponse(HttpException $exception): Response { $statusCode = $exception->getStatusCode(); $headers = array_merge($exception->getHeaders(), ['Content-Type' => 'application/json']); @@ -91,12 +99,11 @@ class Controller extends AbstractController * Serializes data to a given type format. * * @param mixed $data The data to serialize. - * @param string $class The source data class. * @param string $format The target serialization format. * * @return string A serialized data string. */ - protected function serialize($data, $format) + protected function serialize($data, string $format): string { return $this->serializer->serialize($data, $format); } @@ -104,35 +111,47 @@ class Controller extends AbstractController /** * Deserializes data from a given type format. * - * @param string $data The data to deserialize. + * @param mixed $data The data to deserialize. * @param string $class The target data class. * @param string $format The source serialization format. * * @return mixed A deserialized data. */ - protected function deserialize($data, $class, $format) + protected function deserialize($data, string $class, string $format) { return $this->serializer->deserialize($data, $class, $format); } - protected function validate($data, $asserts = null) + /** + * @param mixed $data + * @param mixed $asserts + * + * @return Response|null + */ + protected function validate($data, $asserts = null): ?Response { $errors = $this->validator->validate($data, $asserts); if (count($errors) > 0) { - $errorsString = (string)$errors; + $errorsString = ''; + /** @var ConstraintViolation $violation */ + foreach ($errors as $violation) { + $errorsString .= $violation->getMessage()."\n"; + } return $this->createBadRequestResponse($errorsString); } + + return null; } /** * Converts an exception to a serializable array. * - * @param \Exception|null $exception + * @param \Throwable|null $exception * - * @return array + * @return array|null */ - private function exceptionToArray(\Exception $exception = null) + private function exceptionToArray(\Throwable $exception = null): ?array { if (null === $exception) { return null; @@ -151,7 +170,15 @@ class Controller extends AbstractController ]; } - protected function getOutputFormat($accept, array $produced) + /** + * Converts an exception to a serializable array. + * + * @param string $accept + * @param array $produced + * + * @return ?string + */ + protected function getOutputFormat(string $accept, array $produced): ?string { // Figure out what the client accepts $accept = preg_split("/[\s,]+/", $accept); @@ -186,7 +213,7 @@ class Controller extends AbstractController * * @return bool Returns true if Content-Type supported otherwise false. */ - public static function isContentTypeAllowed(Request $request, array $consumes = []) + public static function isContentTypeAllowed(Request $request, array $consumes = []): bool { if (!empty($consumes) && $consumes[0] !== '*/*') { $currentFormat = $request->getContentType(); diff --git a/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache b/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache index 00dd37411c84..dffd4cbb33a1 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/Extension.mustache @@ -34,7 +34,7 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; */ class {{bundleExtensionName}} extends Extension { - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); diff --git a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache index 3ebcc0b43b0c..7cc1cda4719b 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/README.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/README.mustache @@ -106,7 +106,7 @@ class {{baseName}}Api implements {{classname}} // An interface is autogenerated /** * Implementation of {{classname}}#{{operationId}} */ - public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}, &$responseCode, array &$responseHeaders): {{#isArray}}iterable{{/isArray}}{{^isArray}}array|{{{vendorExtensions.x-comment-type}}}{{/isArray}} + public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}, int &$responseCode, array &$responseHeaders): {{{vendorExtensions.x-return-type}}} { // Implement the operation ... } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache index 236e06f02ddf..9d9c75dcee6d 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api.mustache @@ -38,11 +38,11 @@ interface {{classname}} /** * Sets authentication method {{name}} * - * @param string $value Value of the {{name}} authentication method. + * @param string|null $value Value of the {{name}} authentication method. * * @return void */ - public function set{{name}}($value); + public function set{{name}}(?string $value): void; {{/authMethods}} {{#operation}} @@ -58,16 +58,17 @@ interface {{classname}} * {{/description}} {{#allParams}} - * @param {{vendorExtensions.x-comment-type}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}} + * @param {{vendorExtensions.x-parameter-type}}{{^required}}{{^defaultValue}}|null{{/defaultValue}}{{/required}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}} {{/allParams}} - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return {{{vendorExtensions.x-comment-type}}} + * @return {{{vendorExtensions.x-return-type}}} {{#isDeprecated}} * @deprecated {{/isDeprecated}} */ - public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/required}}, {{/allParams}}&$responseCode, array &$responseHeaders): {{{vendorExtensions.x-return-type}}}; + public function {{operationId}}({{#allParams}}{{^required}}{{^defaultValue}}?{{/defaultValue}}{{/required}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}, {{/allParams}}int &$responseCode, array &$responseHeaders): {{{vendorExtensions.x-return-type}}}; {{/operation}} } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache index 219343cd5b5a..89c22354530f 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api_controller.mustache @@ -109,17 +109,17 @@ class {{controllerName}} extends Controller // Read out all input parameter values into variables {{#queryParams}} - ${{paramName}} = $request->query->get('{{paramName}}'); + ${{paramName}} = $request->query->get('{{paramName}}'{{#defaultValue}}, {{{.}}}{{/defaultValue}}); {{/queryParams}} {{#headerParams}} - ${{paramName}} = $request->headers->get('{{baseName}}'); + ${{paramName}} = $request->headers->get('{{baseName}}'{{#defaultValue}}, {{{.}}}{{/defaultValue}}); {{/headerParams}} {{#formParams}} {{#isFile}} - ${{paramName}} = $request->files->get('{{paramName}}'); + ${{paramName}} = $request->files->get('{{paramName}}'{{#defaultValue}}, {{{.}}}{{/defaultValue}}); {{/isFile}} {{^isFile}} - ${{paramName}} = $request->request->get('{{paramName}}'); + ${{paramName}} = $request->request->get('{{paramName}}'{{#defaultValue}}, {{{.}}}{{/defaultValue}}); {{/isFile}} {{/formParams}} {{#bodyParams}} @@ -175,7 +175,8 @@ class {{controllerName}} extends Controller // Make the call to the business logic $responseCode = {{#returnType}}200{{/returnType}}{{^returnType}}204{{/returnType}}; $responseHeaders = []; - $result = $handler->{{operationId}}({{#allParams}}${{paramName}}, {{/allParams}}$responseCode, $responseHeaders); + + {{#returnType}}$result = {{/returnType}}$handler->{{operationId}}({{#allParams}}${{paramName}}, {{/allParams}}$responseCode, $responseHeaders); // Find default response message $message = '{{#responses}}{{#isDefault}}{{message}}{{/isDefault}}{{/responses}}'; @@ -202,7 +203,7 @@ class {{controllerName}} extends Controller ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache index b5823f934b19..67bedf3ed78a 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/api_doc.mustache @@ -61,7 +61,7 @@ class {{baseName}}Api implements {{classname}} /** * Implementation of {{classname}}#{{operationId}} */ - public function {{operationId}}({{#allParams}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}, &$responseCode, array &$responseHeaders): {{{vendorExtensions.x-return-type}}} + public function {{operationId}}({{#allParams}}{{^required}}{{^defaultValue}}?{{/defaultValue}}{{/required}}{{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{paramName}}, {{/allParams}}int &$responseCode, array &$responseHeaders): {{{vendorExtensions.x-return-type}}} { // Implement the operation ... } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache index 67948d61b2a2..5b093b479d46 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache @@ -4,7 +4,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} {{/vars}} /** * Constructor - * @param mixed[] $data Associated array of property values initializing the model + * @param array|null $data Associated array of property values initializing the model */ public function __construct(array $data = null) { @@ -13,7 +13,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} {{/parentSchema}} {{#vars}} - $this->{{name}} = isset($data['{{name}}']) ? $data['{{name}}'] : {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}; + $this->{{name}} = $data['{{name}}'] ?? null; {{/vars}} } {{#vars}} @@ -21,9 +21,9 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} /** * Gets {{name}}. * - * @return {{{vendorExtensions.x-comment-type}}}{{^required}}|null{{/required}} + * @return {{{vendorExtensions.x-comment-type}}} */ - public function {{getter}}(){{#vendorExtensions.x-parameter-type}}: {{^required}}?{{/required}}{{vendorExtensions.x-parameter-type}}{{/vendorExtensions.x-parameter-type}} + public function {{getter}}(){{#vendorExtensions.x-parameter-type}}: {{vendorExtensions.x-parameter-type}}{{/vendorExtensions.x-parameter-type}} { return $this->{{name}}; } @@ -31,11 +31,11 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} /** * Sets {{name}}. * - * @param {{{vendorExtensions.x-comment-type}}}{{^required}}|null{{/required}} ${{name}}{{#description}} {{{.}}}{{/description}} + * @param {{{vendorExtensions.x-comment-type}}} ${{name}}{{#description}} {{{.}}}{{/description}} * * @return $this */ - public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}) + public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}): self { $this->{{name}} = ${{name}}; diff --git a/modules/openapi-generator/src/main/resources/php-symfony/model_variables.mustache b/modules/openapi-generator/src/main/resources/php-symfony/model_variables.mustache index f38550096094..bd7d559d8a15 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/model_variables.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/model_variables.mustache @@ -3,7 +3,7 @@ * {{.}} * {{/description}} - * @var {{{vendorExtensions.x-comment-type}}}{{^required}}|null{{/required}} + * @var {{{vendorExtensions.x-comment-type}}} * @SerializedName("{{baseName}}") {{#required}} * @Assert\NotNull() @@ -98,4 +98,4 @@ {{/minItems}} {{/hasValidation}} */ - protected ${{name}}; + protected {{{vendorExtensions.x-parameter-type}}} ${{name}} = null; diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache index 0a6571e2bde6..0cd5d36ca5cc 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache @@ -5,13 +5,14 @@ namespace {{servicePackage}}; use JMS\Serializer\SerializerBuilder; use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; +use JMS\Serializer\Serializer; use JMS\Serializer\Visitor\Factory\XmlDeserializationVisitorFactory; use DateTime; use RuntimeException; class JmsSerializer implements SerializerInterface { - protected $serializer; + protected Serializer $serializer; public function __construct() { @@ -23,12 +24,18 @@ class JmsSerializer implements SerializerInterface ->build(); } - public function serialize($data, $format) + /** + * @inheritdoc + */ + public function serialize($data, string $format): string { return SerializerBuilder::create()->build()->serialize($data, $this->convertFormat($format)); } - public function deserialize($data, $type, $format) + /** + * @inheritdoc + */ + public function deserialize($data, string $type, string $format) { if ($format == 'string') { return $this->deserializeString($data, $type); @@ -38,7 +45,7 @@ class JmsSerializer implements SerializerInterface return $this->serializer->deserialize($data, $type, $this->convertFormat($format)); } - private function convertFormat($format) + private function convertFormat(string $format): ?string { switch ($format) { case 'application/json': @@ -50,7 +57,7 @@ class JmsSerializer implements SerializerInterface return null; } - private function deserializeString($data, $type) + private function deserializeString($data, string $type) { // Figure out if we have an array format if (1 === preg_match('/array<(csv|ssv|tsv|pipes),(int|string)>/i', $type, $matches)) { @@ -73,6 +80,10 @@ class JmsSerializer implements SerializerInterface break; case 'boolean': case 'bool': + if (is_bool($data)) { + return $data; + } + if (strtolower($data) === 'true') { return true; } @@ -93,10 +104,9 @@ class JmsSerializer implements SerializerInterface return $data; } - private function deserializeArrayString($format, $type, $data) + private function deserializeArrayString(string $format, string $type, $data): array { - if($data === null) - { + if (empty($data)) { return []; } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/SerializerInterface.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/SerializerInterface.mustache index 60ad87246487..35ba55e74280 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/SerializerInterface.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/SerializerInterface.mustache @@ -12,16 +12,16 @@ interface SerializerInterface * * @return string */ - public function serialize($data, $format); + public function serialize($data, string $format): string; /** * Deserializes the given data to the specified type. * - * @param string $data + * @param mixed $data * @param string $type * @param string $format * * @return object|array|scalar */ - public function deserialize($data, $type, $format); + public function deserialize($data, string $type, string $format); } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache index cb6e0f461905..dfd5e83f1f1d 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/AppKernel.mustache @@ -8,15 +8,20 @@ use Symfony\Component\Config\Loader\LoaderInterface; class AppKernel extends Kernel { + /** + * @inheritDoc + */ public function registerBundles(): iterable { - $bundles = array( - new FrameworkBundle() - ); - - return $bundles; + return [ + new FrameworkBundle(), + ]; } + /** + * @inheritDoc + * @throws \Exception + */ public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__.'/test_config.yml'); diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache index 730cba94a113..e4d5039db846 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache @@ -33,21 +33,16 @@ use Symfony\Component\HttpFoundation\Request; */ class ControllerTest extends TestCase { - /** * Tests isContentTypeAllowed static method. * - * @param string $contentType - * @param array $consumes - * @param bool $expectedReturn - * * @covers ::isContentTypeAllowed - * @dataProvider provideArgumentsForIsContentTypeAllowed + * @dataProvider dataProviderIsContentTypeAllowed */ - public function testIsContentTypeAllowed($contentType, array $consumes, $expectedReturn) + public function testIsContentTypeAllowed(?string $contentType, array $consumes, bool $expectedReturn): void { $request = new Request(); - $request->headers->set('CONTENT_TYPE', $contentType, true);// last one argument overrides header + $request->headers->set('CONTENT_TYPE', $contentType);// last one argument overrides header $this->assertSame( $expectedReturn, Controller::isContentTypeAllowed($request, $consumes), @@ -60,7 +55,7 @@ class ControllerTest extends TestCase ); } - public function provideArgumentsForIsContentTypeAllowed() + public function dataProviderIsContentTypeAllowed(): array { return [ 'usual JSON content type' => [ diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache index ebdbc2fa835b..755fb72dba6a 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/api_test.mustache @@ -18,10 +18,6 @@ namespace {{apiTestsPackage}}; -use {{invokerPackage}}\Configuration; -use {{invokerPackage}}\ApiClient; -use {{invokerPackage}}\ApiException; -use {{invokerPackage}}\ObjectSerializer; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -32,6 +28,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; * @package {{apiTestsPackage}} * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \{{apiPackage}}\{{classname}} */ {{#operations}}class {{classname}}Test extends WebTestCase { @@ -76,7 +73,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; * {{{summary}}}. * */ - public function test{{operationIdCamelCase}}() + public function test{{operationIdCamelCase}}(): void { $client = self::$client; @@ -106,10 +103,15 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; {{/pathParams}} $crawler = $client->request('{{httpMethod}}', $path{{#hasBodyParam}}, [], [], ['CONTENT_TYPE' => 'application/json']{{/hasBodyParam}}); + $this->markTestSkipped('Test for {{operationId}} not implemented'); } {{/operation}} - protected function genTestData($regexp) + /** + * @param string $regexp + * @return mixed + */ + protected function genTestData(string $regexp) { $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/model_test.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/model_test.mustache index 0315c358fd69..1d971d7530aa 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/model_test.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/model_test.mustache @@ -21,20 +21,22 @@ namespace {{modelPackage}}; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * {{classname}}Test Class Doc Comment * - * @category Class */ -// * @description {{description}}{{^description}}{{classname}}{{/description}} -/** + * @category Class + * @description {{description}}{{^description}}{{classname}}{{/description}} * @package {{modelTestsPackage}} * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \{{modelPackage}}\{{classname}} */ class {{classname}}Test extends TestCase { + protected {{classname}}|MockObject $object; /** * Setup before running any test case @@ -48,6 +50,7 @@ class {{classname}}Test extends TestCase */ public function setUp(): void { + $this->object = $this->getMockBuilder({{classname}}::class)->getMockForAbstractClass(); } /** @@ -65,19 +68,25 @@ class {{classname}}Test extends TestCase } /** - * Test "{{classname}}" + * @group integration + * @small */ - public function test{{classname}}() + public function testTestClassExists(): void { - $test{{classname}} = new {{classname}}(); + $this->assertTrue(class_exists({{classname}}::class)); + $this->assertInstanceOf({{classname}}::class, $this->object); } {{#vars}} /** * Test attribute "{{name}}" + * + * @group unit + * @small */ - public function testProperty{{nameInCamelCase}}() + public function testProperty{{nameInCamelCase}}(): void { + $this->markTestSkipped('Test for property {{name}} not implemented'); } {{/vars}} } diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/phpunit.xml.mustache b/modules/openapi-generator/src/main/resources/php-symfony/testing/phpunit.xml.mustache index 3c46ece5012f..3e3eebd1bff6 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/phpunit.xml.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/phpunit.xml.mustache @@ -1,24 +1,26 @@ - + stopOnFailure="false" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> + + + {{apiSrcPath}} + {{modelSrcPath}} + {{controllerSrcPath}} + + - + {{apiTestPath}} {{modelTestPath}} {{controllerTestPath}} - - - {{apiSrcPath}} - {{modelSrcPath}} - {{controllerSrcPath}} - - diff --git a/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml b/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml index a06bcfef45aa..4c7970ab71ad 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml +++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/test_config.yml @@ -5,4 +5,4 @@ framework: secret: "testsecret" test: ~ router: - resource: "%kernel.project_dir%/../Resources/config/routing.yml" + resource: "%kernel.project_dir%/Resources/config/routing.yml" diff --git a/modules/openapi-generator/src/main/resources/php-symfony/validation/SymfonyValidator.mustache b/modules/openapi-generator/src/main/resources/php-symfony/validation/SymfonyValidator.mustache index 1ec3b80ce174..e87e56e26d4d 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/validation/SymfonyValidator.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/validation/SymfonyValidator.mustache @@ -6,7 +6,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface as SymfonyValidator class SymfonyValidator implements ValidatorInterface { - protected $validator; + protected SymfonyValidatorInterface $validator; public function __construct(SymfonyValidatorInterface $validator) { diff --git a/modules/openapi-generator/src/main/resources/php-symfony/validation/ValidatorInterface.mustache b/modules/openapi-generator/src/main/resources/php-symfony/validation/ValidatorInterface.mustache index e2a0d9badc5d..e279adc5ba26 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/validation/ValidatorInterface.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/validation/ValidatorInterface.mustache @@ -2,6 +2,9 @@ namespace {{servicePackage}}; +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintViolationListInterface; + interface ValidatorInterface { /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/ApiServer.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/ApiServer.php index 59f3803817ce..2527f15e82f4 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/ApiServer.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/ApiServer.php @@ -29,6 +29,8 @@ namespace OpenAPI\Server\Api; +use Symfony\Component\DependencyInjection\Reference; + /** * ApiServer Class Doc Comment * @@ -45,7 +47,7 @@ class ApiServer /** * @var array */ - private $apis = array(); + private array $apis = array(); /** * Adds an API handler to the server. @@ -53,7 +55,7 @@ class ApiServer * @param string $api An API name of the handle * @param mixed $handler A handler to set for the given API */ - public function addApiHandler($api, $handler) + public function addApiHandler(string $api, $handler): void { if (isset($this->apis[$api])) { throw new \InvalidArgumentException('API has already a handler: '.$api); @@ -69,7 +71,7 @@ public function addApiHandler($api, $handler) * @return mixed Returns a handler * @throws \InvalidArgumentException When no such handler exists */ - public function getApiHandler($api) + public function getApiHandler(string $api) { if (!isset($this->apis[$api])) { throw new \InvalidArgumentException('No handler for '.$api.' implemented.'); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php index f344890fca40..fa0f0bcb450e 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php @@ -47,32 +47,33 @@ interface PetApiInterface /** * Sets authentication method petstore_auth * - * @param string $value Value of the petstore_auth authentication method. + * @param string|null $value Value of the petstore_auth authentication method. * * @return void */ - public function setpetstore_auth($value); + public function setpetstore_auth(?string $value): void; /** * Sets authentication method api_key * - * @param string $value Value of the api_key authentication method. + * @param string|null $value Value of the api_key authentication method. * * @return void */ - public function setapi_key($value); + public function setapi_key(?string $value): void; /** * Operation addPet * * Add a new pet to the store * - * @param \OpenAPI\Server\Model\Pet $pet Pet object that needs to be added to the store (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param Pet $pet Pet object that needs to be added to the store (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \OpenAPI\Server\Model\Pet + * @return array|object|null */ - public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet; + public function addPet(Pet $pet, int &$responseCode, array &$responseHeaders): array|object|null; /** @@ -80,13 +81,14 @@ public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array * * Deletes a pet * - * @param \int $petId Pet id to delete (required) - * @param \string $apiKey (optional) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param int $petId Pet id to delete (required) + * @param string|null $apiKey (optional) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * * @return void */ - public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders): void; + public function deletePet(int $petId, ?string $apiKey, int &$responseCode, array &$responseHeaders): void; /** @@ -94,12 +96,13 @@ public function deletePet($petId, $apiKey = null, &$responseCode, array &$respon * * Finds Pets by status * - * @param \string[] $status Status values that need to be considered for filter (required) (deprecated) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param array $status Status values that need to be considered for filter (required) (deprecated) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \OpenAPI\Server\Model\Pet[] + * @return array|object|null */ - public function findPetsByStatus(array $status, &$responseCode, array &$responseHeaders): iterable; + public function findPetsByStatus(array $status, int &$responseCode, array &$responseHeaders): array|object|null; /** @@ -107,13 +110,14 @@ public function findPetsByStatus(array $status, &$responseCode, array &$response * * Finds Pets by tags * - * @param \string[] $tags Tags to filter by (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param array $tags Tags to filter by (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \OpenAPI\Server\Model\Pet[] + * @return array|object|null * @deprecated */ - public function findPetsByTags(array $tags, &$responseCode, array &$responseHeaders): iterable; + public function findPetsByTags(array $tags, int &$responseCode, array &$responseHeaders): array|object|null; /** @@ -121,12 +125,13 @@ public function findPetsByTags(array $tags, &$responseCode, array &$responseHead * * Find pet by ID * - * @param \int $petId ID of pet to return (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param int $petId ID of pet to return (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \OpenAPI\Server\Model\Pet + * @return array|object|null */ - public function getPetById($petId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet; + public function getPetById(int $petId, int &$responseCode, array &$responseHeaders): array|object|null; /** @@ -134,12 +139,13 @@ public function getPetById($petId, &$responseCode, array &$responseHeaders): arr * * Update an existing pet * - * @param \OpenAPI\Server\Model\Pet $pet Pet object that needs to be added to the store (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param Pet $pet Pet object that needs to be added to the store (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \OpenAPI\Server\Model\Pet + * @return array|object|null */ - public function updatePet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet; + public function updatePet(Pet $pet, int &$responseCode, array &$responseHeaders): array|object|null; /** @@ -147,14 +153,15 @@ public function updatePet(Pet $pet, &$responseCode, array &$responseHeaders): ar * * Updates a pet in the store with form data * - * @param \int $petId ID of pet that needs to be updated (required) - * @param \string $name Updated name of the pet (optional) - * @param \string $status Updated status of the pet (optional) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param int $petId ID of pet that needs to be updated (required) + * @param string|null $name Updated name of the pet (optional) + * @param string|null $status Updated status of the pet (optional) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * * @return void */ - public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders): void; + public function updatePetWithForm(int $petId, ?string $name, ?string $status, int &$responseCode, array &$responseHeaders): void; /** @@ -162,13 +169,14 @@ public function updatePetWithForm($petId, $name = null, $status = null, &$respon * * uploads an image * - * @param \int $petId ID of pet to update (required) - * @param \string $additionalMetadata Additional data to pass to server (optional) - * @param \UploadedFile $file file to upload (optional) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param int $petId ID of pet to update (required) + * @param string|null $additionalMetadata Additional data to pass to server (optional) + * @param UploadedFile|null $file file to upload (optional) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \OpenAPI\Server\Model\ApiResponse + * @return array|object|null */ - public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\ApiResponse; + public function uploadFile(int $petId, ?string $additionalMetadata, ?UploadedFile $file, int &$responseCode, array &$responseHeaders): array|object|null; } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php index d5390b916f4e..89dc4a72a9e8 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/StoreApiInterface.php @@ -46,23 +46,24 @@ interface StoreApiInterface /** * Sets authentication method api_key * - * @param string $value Value of the api_key authentication method. + * @param string|null $value Value of the api_key authentication method. * * @return void */ - public function setapi_key($value); + public function setapi_key(?string $value): void; /** * Operation deleteOrder * * Delete purchase order by ID * - * @param \string $orderId ID of the order that needs to be deleted (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param string $orderId ID of the order that needs to be deleted (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * * @return void */ - public function deleteOrder($orderId, &$responseCode, array &$responseHeaders): void; + public function deleteOrder(string $orderId, int &$responseCode, array &$responseHeaders): void; /** @@ -70,11 +71,12 @@ public function deleteOrder($orderId, &$responseCode, array &$responseHeaders): * * Returns pet inventories by status * - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \int + * @return array|object|null */ - public function getInventory(&$responseCode, array &$responseHeaders): array|\int; + public function getInventory(int &$responseCode, array &$responseHeaders): array|object|null; /** @@ -82,12 +84,13 @@ public function getInventory(&$responseCode, array &$responseHeaders): array|\in * * Find purchase order by ID * - * @param \int $orderId ID of pet that needs to be fetched (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param int $orderId ID of pet that needs to be fetched (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \OpenAPI\Server\Model\Order + * @return array|object|null */ - public function getOrderById($orderId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order; + public function getOrderById(int $orderId, int &$responseCode, array &$responseHeaders): array|object|null; /** @@ -95,11 +98,12 @@ public function getOrderById($orderId, &$responseCode, array &$responseHeaders): * * Place an order for a pet * - * @param \OpenAPI\Server\Model\Order $order order placed for purchasing the pet (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param Order $order order placed for purchasing the pet (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \OpenAPI\Server\Model\Order + * @return array|object|null */ - public function placeOrder(Order $order, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order; + public function placeOrder(Order $order, int &$responseCode, array &$responseHeaders): array|object|null; } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php index 3a5df7cd4d8e..df557493614a 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/UserApiInterface.php @@ -46,23 +46,24 @@ interface UserApiInterface /** * Sets authentication method api_key * - * @param string $value Value of the api_key authentication method. + * @param string|null $value Value of the api_key authentication method. * * @return void */ - public function setapi_key($value); + public function setapi_key(?string $value): void; /** * Operation createUser * * Create user * - * @param \OpenAPI\Server\Model\User $user Created user object (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param User $user Created user object (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * * @return void */ - public function createUser(User $user, &$responseCode, array &$responseHeaders): void; + public function createUser(User $user, int &$responseCode, array &$responseHeaders): void; /** @@ -70,12 +71,13 @@ public function createUser(User $user, &$responseCode, array &$responseHeaders): * * Creates list of users with given input array * - * @param \OpenAPI\Server\Model\User[] $user List of user object (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param array $user List of user object (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * * @return void */ - public function createUsersWithArrayInput(array $user, &$responseCode, array &$responseHeaders): void; + public function createUsersWithArrayInput(array $user, int &$responseCode, array &$responseHeaders): void; /** @@ -83,12 +85,13 @@ public function createUsersWithArrayInput(array $user, &$responseCode, array &$r * * Creates list of users with given input array * - * @param \OpenAPI\Server\Model\User[] $user List of user object (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param array $user List of user object (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * * @return void */ - public function createUsersWithListInput(array $user, &$responseCode, array &$responseHeaders): void; + public function createUsersWithListInput(array $user, int &$responseCode, array &$responseHeaders): void; /** @@ -96,12 +99,13 @@ public function createUsersWithListInput(array $user, &$responseCode, array &$re * * Delete user * - * @param \string $username The name that needs to be deleted (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param string $username The name that needs to be deleted (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * * @return void */ - public function deleteUser($username, &$responseCode, array &$responseHeaders): void; + public function deleteUser(string $username, int &$responseCode, array &$responseHeaders): void; /** @@ -109,12 +113,13 @@ public function deleteUser($username, &$responseCode, array &$responseHeaders): * * Get user by user name * - * @param \string $username The name that needs to be fetched. Use user1 for testing. (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \OpenAPI\Server\Model\User + * @return array|object|null */ - public function getUserByName($username, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\User; + public function getUserByName(string $username, int &$responseCode, array &$responseHeaders): array|object|null; /** @@ -122,13 +127,14 @@ public function getUserByName($username, &$responseCode, array &$responseHeaders * * Logs user into the system * - * @param \string $username The user name for login (required) - * @param \string $password The password for login in clear text (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param string $username The user name for login (required) + * @param string $password The password for login in clear text (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * - * @return \string + * @return array|object|null */ - public function loginUser($username, $password, &$responseCode, array &$responseHeaders): array|\string; + public function loginUser(string $username, string $password, int &$responseCode, array &$responseHeaders): array|object|null; /** @@ -136,11 +142,12 @@ public function loginUser($username, $password, &$responseCode, array &$response * * Logs out current logged in user session * - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * * @return void */ - public function logoutUser(&$responseCode, array &$responseHeaders): void; + public function logoutUser(int &$responseCode, array &$responseHeaders): void; /** @@ -148,12 +155,13 @@ public function logoutUser(&$responseCode, array &$responseHeaders): void; * * Updated user * - * @param \string $username name that need to be deleted (required) - * @param \OpenAPI\Server\Model\User $user Updated user object (required) - * @param \array $responseHeaders Additional HTTP headers to return with the response () + * @param string $username name that need to be deleted (required) + * @param User $user Updated user object (required) + * @param int &$responseCode The HTTP Response Code + * @param array $responseHeaders Additional HTTP headers to return with the response () * * @return void */ - public function updateUser($username, User $user, &$responseCode, array &$responseHeaders): void; + public function updateUser(string $username, User $user, int &$responseCode, array &$responseHeaders): void; } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/Controller.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/Controller.php index 84375dce078b..559f3bd5a4bc 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/Controller.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/Controller.php @@ -29,10 +29,12 @@ namespace OpenAPI\Server\Controller; +use OpenAPI\Server\Api\ApiServer; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\Validator\ConstraintViolation; use OpenAPI\Server\Service\SerializerInterface; use OpenAPI\Server\Service\ValidatorInterface; @@ -46,23 +48,29 @@ */ class Controller extends AbstractController { - protected $validator; - protected $serializer; - protected $apiServer; + protected ValidatorInterface $validator; + protected SerializerInterface $serializer; + protected ApiServer $apiServer; - public function setValidator(ValidatorInterface $validator) + public function setValidator(ValidatorInterface $validator): self { $this->validator = $validator; + + return $this; } - public function setSerializer(SerializerInterface $serializer) + public function setSerializer(SerializerInterface $serializer): self { $this->serializer = $serializer; + + return $this; } - public function setApiServer($server) + public function setApiServer(ApiServer $server): self { $this->apiServer = $server; + + return $this; } /** @@ -73,7 +81,7 @@ public function setApiServer($server) * * @return Response */ - public function createBadRequestResponse($message = 'Bad Request.') + public function createBadRequestResponse(string $message = 'Bad Request.'): Response { return new Response($message, 400); } @@ -86,7 +94,7 @@ public function createBadRequestResponse($message = 'Bad Request.') * * @return Response */ - public function createErrorResponse(HttpException $exception) + public function createErrorResponse(HttpException $exception): Response { $statusCode = $exception->getStatusCode(); $headers = array_merge($exception->getHeaders(), ['Content-Type' => 'application/json']); @@ -101,12 +109,11 @@ public function createErrorResponse(HttpException $exception) * Serializes data to a given type format. * * @param mixed $data The data to serialize. - * @param string $class The source data class. * @param string $format The target serialization format. * * @return string A serialized data string. */ - protected function serialize($data, $format) + protected function serialize($data, string $format): string { return $this->serializer->serialize($data, $format); } @@ -114,35 +121,47 @@ protected function serialize($data, $format) /** * Deserializes data from a given type format. * - * @param string $data The data to deserialize. + * @param mixed $data The data to deserialize. * @param string $class The target data class. * @param string $format The source serialization format. * * @return mixed A deserialized data. */ - protected function deserialize($data, $class, $format) + protected function deserialize($data, string $class, string $format) { return $this->serializer->deserialize($data, $class, $format); } - protected function validate($data, $asserts = null) + /** + * @param mixed $data + * @param mixed $asserts + * + * @return Response|null + */ + protected function validate($data, $asserts = null): ?Response { $errors = $this->validator->validate($data, $asserts); if (count($errors) > 0) { - $errorsString = (string)$errors; + $errorsString = ''; + /** @var ConstraintViolation $violation */ + foreach ($errors as $violation) { + $errorsString .= $violation->getMessage()."\n"; + } return $this->createBadRequestResponse($errorsString); } + + return null; } /** * Converts an exception to a serializable array. * - * @param \Exception|null $exception + * @param \Throwable|null $exception * - * @return array + * @return array|null */ - private function exceptionToArray(\Exception $exception = null) + private function exceptionToArray(\Throwable $exception = null): ?array { if (null === $exception) { return null; @@ -161,7 +180,15 @@ private function exceptionToArray(\Exception $exception = null) ]; } - protected function getOutputFormat($accept, array $produced) + /** + * Converts an exception to a serializable array. + * + * @param string $accept + * @param array $produced + * + * @return ?string + */ + protected function getOutputFormat(string $accept, array $produced): ?string { // Figure out what the client accepts $accept = preg_split("/[\s,]+/", $accept); @@ -196,7 +223,7 @@ protected function getOutputFormat($accept, array $produced) * * @return bool Returns true if Content-Type supported otherwise false. */ - public static function isContentTypeAllowed(Request $request, array $consumes = []) + public static function isContentTypeAllowed(Request $request, array $consumes = []): bool { if (!empty($consumes) && $consumes[0] !== '*/*') { $currentFormat = $request->getContentType(); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php index 8b1cd18657f9..66cec11ee392 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php @@ -114,6 +114,7 @@ public function addPetAction(Request $request) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->addPet($pet, $responseCode, $responseHeaders); // Find default response message @@ -140,7 +141,7 @@ public function addPetAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -198,7 +199,8 @@ public function deletePetAction(Request $request, $petId) // Make the call to the business logic $responseCode = 204; $responseHeaders = []; - $result = $handler->deletePet($petId, $apiKey, $responseCode, $responseHeaders); + + $handler->deletePet($petId, $apiKey, $responseCode, $responseHeaders); // Find default response message $message = ''; @@ -220,7 +222,7 @@ public function deletePetAction(Request $request, $petId) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -286,6 +288,7 @@ public function findPetsByStatusAction(Request $request) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->findPetsByStatus($status, $responseCode, $responseHeaders); // Find default response message @@ -312,7 +315,7 @@ public function findPetsByStatusAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -376,6 +379,7 @@ public function findPetsByTagsAction(Request $request) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->findPetsByTags($tags, $responseCode, $responseHeaders); // Find default response message @@ -402,7 +406,7 @@ public function findPetsByTagsAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -461,6 +465,7 @@ public function getPetByIdAction(Request $request, $petId) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->getPetById($petId, $responseCode, $responseHeaders); // Find default response message @@ -490,7 +495,7 @@ public function getPetByIdAction(Request $request, $petId) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -559,6 +564,7 @@ public function updatePetAction(Request $request) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->updatePet($pet, $responseCode, $responseHeaders); // Find default response message @@ -591,7 +597,7 @@ public function updatePetAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -657,7 +663,8 @@ public function updatePetWithFormAction(Request $request, $petId) // Make the call to the business logic $responseCode = 204; $responseHeaders = []; - $result = $handler->updatePetWithForm($petId, $name, $status, $responseCode, $responseHeaders); + + $handler->updatePetWithForm($petId, $name, $status, $responseCode, $responseHeaders); // Find default response message $message = ''; @@ -679,7 +686,7 @@ public function updatePetWithFormAction(Request $request, $petId) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -753,6 +760,7 @@ public function uploadFileAction(Request $request, $petId) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->uploadFile($petId, $additionalMetadata, $file, $responseCode, $responseHeaders); // Find default response message @@ -776,7 +784,7 @@ public function uploadFileAction(Request $request, $petId) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php index 7ae4ba95a925..28a894894f64 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php @@ -89,7 +89,8 @@ public function deleteOrderAction(Request $request, $orderId) // Make the call to the business logic $responseCode = 204; $responseHeaders = []; - $result = $handler->deleteOrder($orderId, $responseCode, $responseHeaders); + + $handler->deleteOrder($orderId, $responseCode, $responseHeaders); // Find default response message $message = ''; @@ -114,7 +115,7 @@ public function deleteOrderAction(Request $request, $orderId) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -159,6 +160,7 @@ public function getInventoryAction(Request $request) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->getInventory($responseCode, $responseHeaders); // Find default response message @@ -182,7 +184,7 @@ public function getInventoryAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -238,6 +240,7 @@ public function getOrderByIdAction(Request $request, $orderId) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->getOrderById($orderId, $responseCode, $responseHeaders); // Find default response message @@ -267,7 +270,7 @@ public function getOrderByIdAction(Request $request, $orderId) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -331,6 +334,7 @@ public function placeOrderAction(Request $request) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->placeOrder($order, $responseCode, $responseHeaders); // Find default response message @@ -357,7 +361,7 @@ public function placeOrderAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php index ce07da883e30..49287cbbe203 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php @@ -104,7 +104,8 @@ public function createUserAction(Request $request) // Make the call to the business logic $responseCode = 204; $responseHeaders = []; - $result = $handler->createUser($user, $responseCode, $responseHeaders); + + $handler->createUser($user, $responseCode, $responseHeaders); // Find default response message $message = 'successful operation'; @@ -126,7 +127,7 @@ public function createUserAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -188,7 +189,8 @@ public function createUsersWithArrayInputAction(Request $request) // Make the call to the business logic $responseCode = 204; $responseHeaders = []; - $result = $handler->createUsersWithArrayInput($user, $responseCode, $responseHeaders); + + $handler->createUsersWithArrayInput($user, $responseCode, $responseHeaders); // Find default response message $message = 'successful operation'; @@ -210,7 +212,7 @@ public function createUsersWithArrayInputAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -272,7 +274,8 @@ public function createUsersWithListInputAction(Request $request) // Make the call to the business logic $responseCode = 204; $responseHeaders = []; - $result = $handler->createUsersWithListInput($user, $responseCode, $responseHeaders); + + $handler->createUsersWithListInput($user, $responseCode, $responseHeaders); // Find default response message $message = 'successful operation'; @@ -294,7 +297,7 @@ public function createUsersWithListInputAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -344,7 +347,8 @@ public function deleteUserAction(Request $request, $username) // Make the call to the business logic $responseCode = 204; $responseHeaders = []; - $result = $handler->deleteUser($username, $responseCode, $responseHeaders); + + $handler->deleteUser($username, $responseCode, $responseHeaders); // Find default response message $message = ''; @@ -369,7 +373,7 @@ public function deleteUserAction(Request $request, $username) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -423,6 +427,7 @@ public function getUserByNameAction(Request $request, $username) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->getUserByName($username, $responseCode, $responseHeaders); // Find default response message @@ -452,7 +457,7 @@ public function getUserByNameAction(Request $request, $username) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -517,6 +522,7 @@ public function loginUserAction(Request $request) // Make the call to the business logic $responseCode = 200; $responseHeaders = []; + $result = $handler->loginUser($username, $password, $responseCode, $responseHeaders); // Find default response message @@ -543,7 +549,7 @@ public function loginUserAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -579,7 +585,8 @@ public function logoutUserAction(Request $request) // Make the call to the business logic $responseCode = 204; $responseHeaders = []; - $result = $handler->logoutUser($responseCode, $responseHeaders); + + $handler->logoutUser($responseCode, $responseHeaders); // Find default response message $message = 'successful operation'; @@ -601,7 +608,7 @@ public function logoutUserAction(Request $request) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } @@ -669,7 +676,8 @@ public function updateUserAction(Request $request, $username) // Make the call to the business logic $responseCode = 204; $responseHeaders = []; - $result = $handler->updateUser($username, $user, $responseCode, $responseHeaders); + + $handler->updateUser($username, $user, $responseCode, $responseHeaders); // Find default response message $message = ''; @@ -694,7 +702,7 @@ public function updateUserAction(Request $request, $username) ] ) ); - } catch (Exception $fallthrough) { + } catch (\Throwable $fallthrough) { return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough)); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php index beb42649c2fa..02bd9b82fc89 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/DependencyInjection/OpenAPIServerExtension.php @@ -44,7 +44,7 @@ */ class OpenAPIServerExtension extends Extension { - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php index f16d72ad3814..174fd7969e33 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php @@ -49,7 +49,7 @@ class ApiResponse * @Assert\Type("int") * @Type("int") */ - protected $code; + protected ?int $code = null; /** * @var string|null @@ -57,7 +57,7 @@ class ApiResponse * @Assert\Type("string") * @Type("string") */ - protected $type; + protected ?string $type = null; /** * @var string|null @@ -65,17 +65,17 @@ class ApiResponse * @Assert\Type("string") * @Type("string") */ - protected $message; + protected ?string $message = null; /** * Constructor - * @param mixed[] $data Associated array of property values initializing the model + * @param array|null $data Associated array of property values initializing the model */ public function __construct(array $data = null) { - $this->code = isset($data['code']) ? $data['code'] : null; - $this->type = isset($data['type']) ? $data['type'] : null; - $this->message = isset($data['message']) ? $data['message'] : null; + $this->code = $data['code'] ?? null; + $this->type = $data['type'] ?? null; + $this->message = $data['message'] ?? null; } /** @@ -83,7 +83,7 @@ public function __construct(array $data = null) * * @return int|null */ - public function getCode() + public function getCode(): ?int { return $this->code; } @@ -95,7 +95,7 @@ public function getCode() * * @return $this */ - public function setCode($code = null) + public function setCode(?int $code = null): self { $this->code = $code; @@ -107,7 +107,7 @@ public function setCode($code = null) * * @return string|null */ - public function getType() + public function getType(): ?string { return $this->type; } @@ -119,7 +119,7 @@ public function getType() * * @return $this */ - public function setType($type = null) + public function setType(?string $type = null): self { $this->type = $type; @@ -131,7 +131,7 @@ public function setType($type = null) * * @return string|null */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } @@ -143,7 +143,7 @@ public function getMessage() * * @return $this */ - public function setMessage($message = null) + public function setMessage(?string $message = null): self { $this->message = $message; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php index f28e356b3812..0175e84a1b2c 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php @@ -49,7 +49,7 @@ class Category * @Assert\Type("int") * @Type("int") */ - protected $id; + protected ?int $id = null; /** * @var string|null @@ -58,16 +58,16 @@ class Category * @Type("string") * @Assert\Regex("/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/") */ - protected $name; + protected ?string $name = null; /** * Constructor - * @param mixed[] $data Associated array of property values initializing the model + * @param array|null $data Associated array of property values initializing the model */ public function __construct(array $data = null) { - $this->id = isset($data['id']) ? $data['id'] : null; - $this->name = isset($data['name']) ? $data['name'] : null; + $this->id = $data['id'] ?? null; + $this->name = $data['name'] ?? null; } /** @@ -75,7 +75,7 @@ public function __construct(array $data = null) * * @return int|null */ - public function getId() + public function getId(): ?int { return $this->id; } @@ -87,7 +87,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId(?int $id = null): self { $this->id = $id; @@ -99,7 +99,7 @@ public function setId($id = null) * * @return string|null */ - public function getName() + public function getName(): ?string { return $this->name; } @@ -111,7 +111,7 @@ public function getName() * * @return $this */ - public function setName($name = null) + public function setName(?string $name = null): self { $this->name = $name; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php index 7a6c985ae859..9ebeb0a1f57a 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php @@ -49,7 +49,7 @@ class Order * @Assert\Type("int") * @Type("int") */ - protected $id; + protected ?int $id = null; /** * @var int|null @@ -57,7 +57,7 @@ class Order * @Assert\Type("int") * @Type("int") */ - protected $petId; + protected ?int $petId = null; /** * @var int|null @@ -65,7 +65,7 @@ class Order * @Assert\Type("int") * @Type("int") */ - protected $quantity; + protected ?int $quantity = null; /** * @var \DateTime|null @@ -73,7 +73,7 @@ class Order * @Assert\DateTime() * @Type("DateTime") */ - protected $shipDate; + protected ?\DateTime $shipDate = null; /** * Order Status @@ -84,7 +84,7 @@ class Order * @Assert\Type("string") * @Type("string") */ - protected $status; + protected ?string $status = null; /** * @var bool|null @@ -92,20 +92,20 @@ class Order * @Assert\Type("bool") * @Type("bool") */ - protected $complete; + protected ?bool $complete = null; /** * Constructor - * @param mixed[] $data Associated array of property values initializing the model + * @param array|null $data Associated array of property values initializing the model */ public function __construct(array $data = null) { - $this->id = isset($data['id']) ? $data['id'] : null; - $this->petId = isset($data['petId']) ? $data['petId'] : null; - $this->quantity = isset($data['quantity']) ? $data['quantity'] : null; - $this->shipDate = isset($data['shipDate']) ? $data['shipDate'] : null; - $this->status = isset($data['status']) ? $data['status'] : null; - $this->complete = isset($data['complete']) ? $data['complete'] : false; + $this->id = $data['id'] ?? null; + $this->petId = $data['petId'] ?? null; + $this->quantity = $data['quantity'] ?? null; + $this->shipDate = $data['shipDate'] ?? null; + $this->status = $data['status'] ?? null; + $this->complete = $data['complete'] ?? null; } /** @@ -113,7 +113,7 @@ public function __construct(array $data = null) * * @return int|null */ - public function getId() + public function getId(): ?int { return $this->id; } @@ -125,7 +125,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId(?int $id = null): self { $this->id = $id; @@ -137,7 +137,7 @@ public function setId($id = null) * * @return int|null */ - public function getPetId() + public function getPetId(): ?int { return $this->petId; } @@ -149,7 +149,7 @@ public function getPetId() * * @return $this */ - public function setPetId($petId = null) + public function setPetId(?int $petId = null): self { $this->petId = $petId; @@ -161,7 +161,7 @@ public function setPetId($petId = null) * * @return int|null */ - public function getQuantity() + public function getQuantity(): ?int { return $this->quantity; } @@ -173,7 +173,7 @@ public function getQuantity() * * @return $this */ - public function setQuantity($quantity = null) + public function setQuantity(?int $quantity = null): self { $this->quantity = $quantity; @@ -197,7 +197,7 @@ public function getShipDate(): ?\DateTime * * @return $this */ - public function setShipDate(\DateTime $shipDate = null) + public function setShipDate(?\DateTime $shipDate = null): self { $this->shipDate = $shipDate; @@ -209,7 +209,7 @@ public function setShipDate(\DateTime $shipDate = null) * * @return string|null */ - public function getStatus() + public function getStatus(): ?string { return $this->status; } @@ -221,7 +221,7 @@ public function getStatus() * * @return $this */ - public function setStatus($status = null) + public function setStatus(?string $status = null): self { $this->status = $status; @@ -233,7 +233,7 @@ public function setStatus($status = null) * * @return bool|null */ - public function isComplete() + public function isComplete(): ?bool { return $this->complete; } @@ -245,7 +245,7 @@ public function isComplete() * * @return $this */ - public function setComplete($complete = null) + public function setComplete(?bool $complete = null): self { $this->complete = $complete; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php index f0375444f5ce..3e3aa07a6899 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -49,27 +49,27 @@ class Pet * @Assert\Type("int") * @Type("int") */ - protected $id; + protected ?int $id = null; /** - * @var OpenAPI\Server\Model\Category|null + * @var Category|null * @SerializedName("category") * @Assert\Type("OpenAPI\Server\Model\Category") * @Type("OpenAPI\Server\Model\Category") */ - protected $category; + protected ?Category $category = null; /** - * @var string + * @var string|null * @SerializedName("name") * @Assert\NotNull() * @Assert\Type("string") * @Type("string") */ - protected $name; + protected ?string $name = null; /** - * @var string[] + * @var array|null * @SerializedName("photoUrls") * @Assert\NotNull() * @Assert\All({ @@ -77,17 +77,17 @@ class Pet * }) * @Type("array") */ - protected $photoUrls; + protected ?array $photoUrls = null; /** - * @var OpenAPI\Server\Model\Tag[]|null + * @var array|null * @SerializedName("tags") * @Assert\All({ * @Assert\Type("OpenAPI\Server\Model\Tag") * }) * @Type("array") */ - protected $tags; + protected ?array $tags = null; /** * pet status in the store @@ -98,20 +98,20 @@ class Pet * @Assert\Type("string") * @Type("string") */ - protected $status; + protected ?string $status = null; /** * Constructor - * @param mixed[] $data Associated array of property values initializing the model + * @param array|null $data Associated array of property values initializing the model */ public function __construct(array $data = null) { - $this->id = isset($data['id']) ? $data['id'] : null; - $this->category = isset($data['category']) ? $data['category'] : null; - $this->name = isset($data['name']) ? $data['name'] : null; - $this->photoUrls = isset($data['photoUrls']) ? $data['photoUrls'] : null; - $this->tags = isset($data['tags']) ? $data['tags'] : null; - $this->status = isset($data['status']) ? $data['status'] : null; + $this->id = $data['id'] ?? null; + $this->category = $data['category'] ?? null; + $this->name = $data['name'] ?? null; + $this->photoUrls = $data['photoUrls'] ?? null; + $this->tags = $data['tags'] ?? null; + $this->status = $data['status'] ?? null; } /** @@ -119,7 +119,7 @@ public function __construct(array $data = null) * * @return int|null */ - public function getId() + public function getId(): ?int { return $this->id; } @@ -131,7 +131,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId(?int $id = null): self { $this->id = $id; @@ -141,7 +141,7 @@ public function setId($id = null) /** * Gets category. * - * @return OpenAPI\Server\Model\Category|null + * @return Category|null */ public function getCategory(): ?Category { @@ -151,11 +151,11 @@ public function getCategory(): ?Category /** * Sets category. * - * @param OpenAPI\Server\Model\Category|null $category + * @param Category|null $category * * @return $this */ - public function setCategory(Category $category = null) + public function setCategory(?Category $category = null): self { $this->category = $category; @@ -165,9 +165,9 @@ public function setCategory(Category $category = null) /** * Gets name. * - * @return string + * @return string|null */ - public function getName() + public function getName(): ?string { return $this->name; } @@ -175,11 +175,11 @@ public function getName() /** * Sets name. * - * @param string $name + * @param string|null $name * * @return $this */ - public function setName($name) + public function setName(?string $name): self { $this->name = $name; @@ -189,9 +189,9 @@ public function setName($name) /** * Gets photoUrls. * - * @return string[] + * @return array|null */ - public function getPhotoUrls(): array + public function getPhotoUrls(): ?array { return $this->photoUrls; } @@ -199,11 +199,11 @@ public function getPhotoUrls(): array /** * Sets photoUrls. * - * @param string[] $photoUrls + * @param array|null $photoUrls * * @return $this */ - public function setPhotoUrls(array $photoUrls) + public function setPhotoUrls(?array $photoUrls): self { $this->photoUrls = $photoUrls; @@ -213,7 +213,7 @@ public function setPhotoUrls(array $photoUrls) /** * Gets tags. * - * @return OpenAPI\Server\Model\Tag[]|null + * @return array|null */ public function getTags(): ?array { @@ -223,11 +223,11 @@ public function getTags(): ?array /** * Sets tags. * - * @param OpenAPI\Server\Model\Tag[]|null $tags + * @param array|null $tags * * @return $this */ - public function setTags(array $tags = null) + public function setTags(?array $tags = null): self { $this->tags = $tags; @@ -239,7 +239,7 @@ public function setTags(array $tags = null) * * @return string|null */ - public function getStatus() + public function getStatus(): ?string { return $this->status; } @@ -251,7 +251,7 @@ public function getStatus() * * @return $this */ - public function setStatus($status = null) + public function setStatus(?string $status = null): self { $this->status = $status; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php index e07427b14576..fb60b40200df 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php @@ -49,7 +49,7 @@ class Tag * @Assert\Type("int") * @Type("int") */ - protected $id; + protected ?int $id = null; /** * @var string|null @@ -57,16 +57,16 @@ class Tag * @Assert\Type("string") * @Type("string") */ - protected $name; + protected ?string $name = null; /** * Constructor - * @param mixed[] $data Associated array of property values initializing the model + * @param array|null $data Associated array of property values initializing the model */ public function __construct(array $data = null) { - $this->id = isset($data['id']) ? $data['id'] : null; - $this->name = isset($data['name']) ? $data['name'] : null; + $this->id = $data['id'] ?? null; + $this->name = $data['name'] ?? null; } /** @@ -74,7 +74,7 @@ public function __construct(array $data = null) * * @return int|null */ - public function getId() + public function getId(): ?int { return $this->id; } @@ -86,7 +86,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId(?int $id = null): self { $this->id = $id; @@ -98,7 +98,7 @@ public function setId($id = null) * * @return string|null */ - public function getName() + public function getName(): ?string { return $this->name; } @@ -110,7 +110,7 @@ public function getName() * * @return $this */ - public function setName($name = null) + public function setName(?string $name = null): self { $this->name = $name; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php index 4fab9c98f419..8765a4e389ed 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php @@ -49,7 +49,7 @@ class User * @Assert\Type("int") * @Type("int") */ - protected $id; + protected ?int $id = null; /** * @var string|null @@ -57,7 +57,7 @@ class User * @Assert\Type("string") * @Type("string") */ - protected $username; + protected ?string $username = null; /** * @var string|null @@ -65,7 +65,7 @@ class User * @Assert\Type("string") * @Type("string") */ - protected $firstName; + protected ?string $firstName = null; /** * @var string|null @@ -73,7 +73,7 @@ class User * @Assert\Type("string") * @Type("string") */ - protected $lastName; + protected ?string $lastName = null; /** * @var string|null @@ -81,7 +81,7 @@ class User * @Assert\Type("string") * @Type("string") */ - protected $email; + protected ?string $email = null; /** * @var string|null @@ -89,7 +89,7 @@ class User * @Assert\Type("string") * @Type("string") */ - protected $password; + protected ?string $password = null; /** * @var string|null @@ -97,7 +97,7 @@ class User * @Assert\Type("string") * @Type("string") */ - protected $phone; + protected ?string $phone = null; /** * User Status @@ -107,22 +107,22 @@ class User * @Assert\Type("int") * @Type("int") */ - protected $userStatus; + protected ?int $userStatus = null; /** * Constructor - * @param mixed[] $data Associated array of property values initializing the model + * @param array|null $data Associated array of property values initializing the model */ public function __construct(array $data = null) { - $this->id = isset($data['id']) ? $data['id'] : null; - $this->username = isset($data['username']) ? $data['username'] : null; - $this->firstName = isset($data['firstName']) ? $data['firstName'] : null; - $this->lastName = isset($data['lastName']) ? $data['lastName'] : null; - $this->email = isset($data['email']) ? $data['email'] : null; - $this->password = isset($data['password']) ? $data['password'] : null; - $this->phone = isset($data['phone']) ? $data['phone'] : null; - $this->userStatus = isset($data['userStatus']) ? $data['userStatus'] : null; + $this->id = $data['id'] ?? null; + $this->username = $data['username'] ?? null; + $this->firstName = $data['firstName'] ?? null; + $this->lastName = $data['lastName'] ?? null; + $this->email = $data['email'] ?? null; + $this->password = $data['password'] ?? null; + $this->phone = $data['phone'] ?? null; + $this->userStatus = $data['userStatus'] ?? null; } /** @@ -130,7 +130,7 @@ public function __construct(array $data = null) * * @return int|null */ - public function getId() + public function getId(): ?int { return $this->id; } @@ -142,7 +142,7 @@ public function getId() * * @return $this */ - public function setId($id = null) + public function setId(?int $id = null): self { $this->id = $id; @@ -154,7 +154,7 @@ public function setId($id = null) * * @return string|null */ - public function getUsername() + public function getUsername(): ?string { return $this->username; } @@ -166,7 +166,7 @@ public function getUsername() * * @return $this */ - public function setUsername($username = null) + public function setUsername(?string $username = null): self { $this->username = $username; @@ -178,7 +178,7 @@ public function setUsername($username = null) * * @return string|null */ - public function getFirstName() + public function getFirstName(): ?string { return $this->firstName; } @@ -190,7 +190,7 @@ public function getFirstName() * * @return $this */ - public function setFirstName($firstName = null) + public function setFirstName(?string $firstName = null): self { $this->firstName = $firstName; @@ -202,7 +202,7 @@ public function setFirstName($firstName = null) * * @return string|null */ - public function getLastName() + public function getLastName(): ?string { return $this->lastName; } @@ -214,7 +214,7 @@ public function getLastName() * * @return $this */ - public function setLastName($lastName = null) + public function setLastName(?string $lastName = null): self { $this->lastName = $lastName; @@ -226,7 +226,7 @@ public function setLastName($lastName = null) * * @return string|null */ - public function getEmail() + public function getEmail(): ?string { return $this->email; } @@ -238,7 +238,7 @@ public function getEmail() * * @return $this */ - public function setEmail($email = null) + public function setEmail(?string $email = null): self { $this->email = $email; @@ -250,7 +250,7 @@ public function setEmail($email = null) * * @return string|null */ - public function getPassword() + public function getPassword(): ?string { return $this->password; } @@ -262,7 +262,7 @@ public function getPassword() * * @return $this */ - public function setPassword($password = null) + public function setPassword(?string $password = null): self { $this->password = $password; @@ -274,7 +274,7 @@ public function setPassword($password = null) * * @return string|null */ - public function getPhone() + public function getPhone(): ?string { return $this->phone; } @@ -286,7 +286,7 @@ public function getPhone() * * @return $this */ - public function setPhone($phone = null) + public function setPhone(?string $phone = null): self { $this->phone = $phone; @@ -298,7 +298,7 @@ public function setPhone($phone = null) * * @return int|null */ - public function getUserStatus() + public function getUserStatus(): ?int { return $this->userStatus; } @@ -310,7 +310,7 @@ public function getUserStatus() * * @return $this */ - public function setUserStatus($userStatus = null) + public function setUserStatus(?int $userStatus = null): self { $this->userStatus = $userStatus; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md index c39149e71d67..c89ec4ed4fd7 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/README.md @@ -87,7 +87,7 @@ class PetApi implements PetApiInterface // An interface is autogenerated /** * Implementation of PetApiInterface#addPet */ - public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet + public function addPet(Pet $pet, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md index a3e606ce33af..7b690ea767b1 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/PetApiInterface.md @@ -57,7 +57,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#addPet */ - public function addPet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet + public function addPet(Pet $pet, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } @@ -119,7 +119,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#deletePet */ - public function deletePet($petId, $apiKey = null, &$responseCode, array &$responseHeaders): void + public function deletePet(int $petId, ?string $apiKey, int &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -182,7 +182,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByStatus */ - public function findPetsByStatus(array $status, &$responseCode, array &$responseHeaders): iterable + public function findPetsByStatus(array $status, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } @@ -244,7 +244,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#findPetsByTags */ - public function findPetsByTags(array $tags, &$responseCode, array &$responseHeaders): iterable + public function findPetsByTags(array $tags, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } @@ -306,7 +306,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#getPetById */ - public function getPetById($petId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet + public function getPetById(int $petId, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } @@ -368,7 +368,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#updatePet */ - public function updatePet(Pet $pet, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Pet + public function updatePet(Pet $pet, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } @@ -430,7 +430,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#updatePetWithForm */ - public function updatePetWithForm($petId, $name = null, $status = null, &$responseCode, array &$responseHeaders): void + public function updatePetWithForm(int $petId, ?string $name, ?string $status, int &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -494,7 +494,7 @@ class PetApi implements PetApiInterface /** * Implementation of PetApiInterface#uploadFile */ - public function uploadFile($petId, $additionalMetadata = null, UploadedFile $file = null, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\ApiResponse + public function uploadFile(int $petId, ?string $additionalMetadata, ?UploadedFile $file, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md index d721b46d6c15..f7c5893d0d06 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/StoreApiInterface.md @@ -45,7 +45,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#deleteOrder */ - public function deleteOrder($orderId, &$responseCode, array &$responseHeaders): void + public function deleteOrder(string $orderId, int &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -107,7 +107,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#getInventory */ - public function getInventory(, &$responseCode, array &$responseHeaders): array|\int + public function getInventory(int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } @@ -158,7 +158,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#getOrderById */ - public function getOrderById($orderId, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order + public function getOrderById(int $orderId, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } @@ -212,7 +212,7 @@ class StoreApi implements StoreApiInterface /** * Implementation of StoreApiInterface#placeOrder */ - public function placeOrder(Order $order, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\Order + public function placeOrder(Order $order, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md index 2ec5e011214c..24eb29aa6bb9 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Resources/docs/Api/UserApiInterface.md @@ -57,7 +57,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUser */ - public function createUser(User $user, &$responseCode, array &$responseHeaders): void + public function createUser(User $user, int &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -119,7 +119,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithArrayInput */ - public function createUsersWithArrayInput(array $user, &$responseCode, array &$responseHeaders): void + public function createUsersWithArrayInput(array $user, int &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -181,7 +181,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#createUsersWithListInput */ - public function createUsersWithListInput(array $user, &$responseCode, array &$responseHeaders): void + public function createUsersWithListInput(array $user, int &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -243,7 +243,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#deleteUser */ - public function deleteUser($username, &$responseCode, array &$responseHeaders): void + public function deleteUser(string $username, int &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -297,7 +297,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#getUserByName */ - public function getUserByName($username, &$responseCode, array &$responseHeaders): array|\OpenAPI\Server\Model\User + public function getUserByName(string $username, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } @@ -351,7 +351,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#loginUser */ - public function loginUser($username, $password, &$responseCode, array &$responseHeaders): array|\string + public function loginUser(string $username, string $password, int &$responseCode, array &$responseHeaders): array|object|null { // Implement the operation ... } @@ -414,7 +414,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#logoutUser */ - public function logoutUser(, &$responseCode, array &$responseHeaders): void + public function logoutUser(int &$responseCode, array &$responseHeaders): void { // Implement the operation ... } @@ -473,7 +473,7 @@ class UserApi implements UserApiInterface /** * Implementation of UserApiInterface#updateUser */ - public function updateUser($username, User $user, &$responseCode, array &$responseHeaders): void + public function updateUser(string $username, User $user, int &$responseCode, array &$responseHeaders): void { // Implement the operation ... } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php index 8d301b5bba4d..2beafc6fa2dd 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php @@ -5,13 +5,14 @@ use JMS\Serializer\SerializerBuilder; use JMS\Serializer\Naming\CamelCaseNamingStrategy; use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; +use JMS\Serializer\Serializer; use JMS\Serializer\Visitor\Factory\XmlDeserializationVisitorFactory; use DateTime; use RuntimeException; class JmsSerializer implements SerializerInterface { - protected $serializer; + protected Serializer $serializer; public function __construct() { @@ -23,12 +24,18 @@ public function __construct() ->build(); } - public function serialize($data, $format) + /** + * @inheritdoc + */ + public function serialize($data, string $format): string { return SerializerBuilder::create()->build()->serialize($data, $this->convertFormat($format)); } - public function deserialize($data, $type, $format) + /** + * @inheritdoc + */ + public function deserialize($data, string $type, string $format) { if ($format == 'string') { return $this->deserializeString($data, $type); @@ -38,7 +45,7 @@ public function deserialize($data, $type, $format) return $this->serializer->deserialize($data, $type, $this->convertFormat($format)); } - private function convertFormat($format) + private function convertFormat(string $format): ?string { switch ($format) { case 'application/json': @@ -50,7 +57,7 @@ private function convertFormat($format) return null; } - private function deserializeString($data, $type) + private function deserializeString($data, string $type) { // Figure out if we have an array format if (1 === preg_match('/array<(csv|ssv|tsv|pipes),(int|string)>/i', $type, $matches)) { @@ -73,6 +80,10 @@ private function deserializeString($data, $type) break; case 'boolean': case 'bool': + if (is_bool($data)) { + return $data; + } + if (strtolower($data) === 'true') { return true; } @@ -93,10 +104,9 @@ private function deserializeString($data, $type) return $data; } - private function deserializeArrayString($format, $type, $data) + private function deserializeArrayString(string $format, string $type, $data): array { - if($data === null) - { + if (empty($data)) { return []; } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/SerializerInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/SerializerInterface.php index 40ef08f44c9f..5f6b18b59981 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/SerializerInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/SerializerInterface.php @@ -12,16 +12,16 @@ interface SerializerInterface * * @return string */ - public function serialize($data, $format); + public function serialize($data, string $format): string; /** * Deserializes the given data to the specified type. * - * @param string $data + * @param mixed $data * @param string $type * @param string $format * * @return object|array|scalar */ - public function deserialize($data, $type, $format); + public function deserialize($data, string $type, string $format); } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/SymfonyValidator.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/SymfonyValidator.php index 87d4f077916b..6c1c56860a89 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/SymfonyValidator.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/SymfonyValidator.php @@ -6,7 +6,7 @@ class SymfonyValidator implements ValidatorInterface { - protected $validator; + protected SymfonyValidatorInterface $validator; public function __construct(SymfonyValidatorInterface $validator) { diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/ValidatorInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/ValidatorInterface.php index dea541847336..858b1280fdc2 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/ValidatorInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/ValidatorInterface.php @@ -2,6 +2,9 @@ namespace OpenAPI\Server\Service; +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintViolationListInterface; + interface ValidatorInterface { /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php index f8fe90512b12..98d735524b91 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/PetApiInterfaceTest.php @@ -28,10 +28,6 @@ namespace OpenAPI\Server\Tests\Api; -use OpenAPI\Server\Configuration; -use OpenAPI\Server\ApiClient; -use OpenAPI\Server\ApiException; -use OpenAPI\Server\ObjectSerializer; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -42,6 +38,7 @@ * @package OpenAPI\Server\Tests\Api * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \OpenAPI\Server\Api\PetApiInterface */ class PetApiInterfaceTest extends WebTestCase { @@ -85,13 +82,14 @@ public static function tearDownAfterClass(): void * Add a new pet to the store. * */ - public function testAddPet() + public function testAddPet(): void { $client = self::$client; $path = '/pet'; $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + $this->markTestSkipped('Test for addPet not implemented'); } /** @@ -100,7 +98,7 @@ public function testAddPet() * Deletes a pet. * */ - public function testDeletePet() + public function testDeletePet(): void { $client = self::$client; @@ -110,6 +108,7 @@ public function testDeletePet() $path = str_replace($pattern, $data, $path); $crawler = $client->request('DELETE', $path); + $this->markTestSkipped('Test for deletePet not implemented'); } /** @@ -118,13 +117,14 @@ public function testDeletePet() * Finds Pets by status. * */ - public function testFindPetsByStatus() + public function testFindPetsByStatus(): void { $client = self::$client; $path = '/pet/findByStatus'; $crawler = $client->request('GET', $path); + $this->markTestSkipped('Test for findPetsByStatus not implemented'); } /** @@ -133,13 +133,14 @@ public function testFindPetsByStatus() * Finds Pets by tags. * */ - public function testFindPetsByTags() + public function testFindPetsByTags(): void { $client = self::$client; $path = '/pet/findByTags'; $crawler = $client->request('GET', $path); + $this->markTestSkipped('Test for findPetsByTags not implemented'); } /** @@ -148,7 +149,7 @@ public function testFindPetsByTags() * Find pet by ID. * */ - public function testGetPetById() + public function testGetPetById(): void { $client = self::$client; @@ -158,6 +159,7 @@ public function testGetPetById() $path = str_replace($pattern, $data, $path); $crawler = $client->request('GET', $path); + $this->markTestSkipped('Test for getPetById not implemented'); } /** @@ -166,13 +168,14 @@ public function testGetPetById() * Update an existing pet. * */ - public function testUpdatePet() + public function testUpdatePet(): void { $client = self::$client; $path = '/pet'; $crawler = $client->request('PUT', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + $this->markTestSkipped('Test for updatePet not implemented'); } /** @@ -181,7 +184,7 @@ public function testUpdatePet() * Updates a pet in the store with form data. * */ - public function testUpdatePetWithForm() + public function testUpdatePetWithForm(): void { $client = self::$client; @@ -191,6 +194,7 @@ public function testUpdatePetWithForm() $path = str_replace($pattern, $data, $path); $crawler = $client->request('POST', $path); + $this->markTestSkipped('Test for updatePetWithForm not implemented'); } /** @@ -199,7 +203,7 @@ public function testUpdatePetWithForm() * uploads an image. * */ - public function testUploadFile() + public function testUploadFile(): void { $client = self::$client; @@ -209,13 +213,18 @@ public function testUploadFile() $path = str_replace($pattern, $data, $path); $crawler = $client->request('POST', $path); + $this->markTestSkipped('Test for uploadFile not implemented'); } - protected function genTestData($regexp) + /** + * @param string $regexp + * @return mixed + */ + protected function genTestData(string $regexp) { - $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); - $ast = $compiler->parse($regexp); + $ast = $compiler->parse($regexp); $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); return $generator->visit($ast); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php index 2acfddb51ee4..928160a944cf 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/StoreApiInterfaceTest.php @@ -28,10 +28,6 @@ namespace OpenAPI\Server\Tests\Api; -use OpenAPI\Server\Configuration; -use OpenAPI\Server\ApiClient; -use OpenAPI\Server\ApiException; -use OpenAPI\Server\ObjectSerializer; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -42,6 +38,7 @@ * @package OpenAPI\Server\Tests\Api * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \OpenAPI\Server\Api\StoreApiInterface */ class StoreApiInterfaceTest extends WebTestCase { @@ -85,7 +82,7 @@ public static function tearDownAfterClass(): void * Delete purchase order by ID. * */ - public function testDeleteOrder() + public function testDeleteOrder(): void { $client = self::$client; @@ -95,6 +92,7 @@ public function testDeleteOrder() $path = str_replace($pattern, $data, $path); $crawler = $client->request('DELETE', $path); + $this->markTestSkipped('Test for deleteOrder not implemented'); } /** @@ -103,13 +101,14 @@ public function testDeleteOrder() * Returns pet inventories by status. * */ - public function testGetInventory() + public function testGetInventory(): void { $client = self::$client; $path = '/store/inventory'; $crawler = $client->request('GET', $path); + $this->markTestSkipped('Test for getInventory not implemented'); } /** @@ -118,7 +117,7 @@ public function testGetInventory() * Find purchase order by ID. * */ - public function testGetOrderById() + public function testGetOrderById(): void { $client = self::$client; @@ -128,6 +127,7 @@ public function testGetOrderById() $path = str_replace($pattern, $data, $path); $crawler = $client->request('GET', $path); + $this->markTestSkipped('Test for getOrderById not implemented'); } /** @@ -136,20 +136,25 @@ public function testGetOrderById() * Place an order for a pet. * */ - public function testPlaceOrder() + public function testPlaceOrder(): void { $client = self::$client; $path = '/store/order'; $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + $this->markTestSkipped('Test for placeOrder not implemented'); } - protected function genTestData($regexp) + /** + * @param string $regexp + * @return mixed + */ + protected function genTestData(string $regexp) { - $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); - $ast = $compiler->parse($regexp); + $ast = $compiler->parse($regexp); $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); return $generator->visit($ast); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php index 447113b321b8..ce64a85b1004 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Api/UserApiInterfaceTest.php @@ -28,10 +28,6 @@ namespace OpenAPI\Server\Tests\Api; -use OpenAPI\Server\Configuration; -use OpenAPI\Server\ApiClient; -use OpenAPI\Server\ApiException; -use OpenAPI\Server\ObjectSerializer; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -42,6 +38,7 @@ * @package OpenAPI\Server\Tests\Api * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \OpenAPI\Server\Api\UserApiInterface */ class UserApiInterfaceTest extends WebTestCase { @@ -85,13 +82,14 @@ public static function tearDownAfterClass(): void * Create user. * */ - public function testCreateUser() + public function testCreateUser(): void { $client = self::$client; $path = '/user'; $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + $this->markTestSkipped('Test for createUser not implemented'); } /** @@ -100,13 +98,14 @@ public function testCreateUser() * Creates list of users with given input array. * */ - public function testCreateUsersWithArrayInput() + public function testCreateUsersWithArrayInput(): void { $client = self::$client; $path = '/user/createWithArray'; $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + $this->markTestSkipped('Test for createUsersWithArrayInput not implemented'); } /** @@ -115,13 +114,14 @@ public function testCreateUsersWithArrayInput() * Creates list of users with given input array. * */ - public function testCreateUsersWithListInput() + public function testCreateUsersWithListInput(): void { $client = self::$client; $path = '/user/createWithList'; $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + $this->markTestSkipped('Test for createUsersWithListInput not implemented'); } /** @@ -130,7 +130,7 @@ public function testCreateUsersWithListInput() * Delete user. * */ - public function testDeleteUser() + public function testDeleteUser(): void { $client = self::$client; @@ -140,6 +140,7 @@ public function testDeleteUser() $path = str_replace($pattern, $data, $path); $crawler = $client->request('DELETE', $path); + $this->markTestSkipped('Test for deleteUser not implemented'); } /** @@ -148,7 +149,7 @@ public function testDeleteUser() * Get user by user name. * */ - public function testGetUserByName() + public function testGetUserByName(): void { $client = self::$client; @@ -158,6 +159,7 @@ public function testGetUserByName() $path = str_replace($pattern, $data, $path); $crawler = $client->request('GET', $path); + $this->markTestSkipped('Test for getUserByName not implemented'); } /** @@ -166,13 +168,14 @@ public function testGetUserByName() * Logs user into the system. * */ - public function testLoginUser() + public function testLoginUser(): void { $client = self::$client; $path = '/user/login'; $crawler = $client->request('GET', $path); + $this->markTestSkipped('Test for loginUser not implemented'); } /** @@ -181,13 +184,14 @@ public function testLoginUser() * Logs out current logged in user session. * */ - public function testLogoutUser() + public function testLogoutUser(): void { $client = self::$client; $path = '/user/logout'; $crawler = $client->request('GET', $path); + $this->markTestSkipped('Test for logoutUser not implemented'); } /** @@ -196,7 +200,7 @@ public function testLogoutUser() * Updated user. * */ - public function testUpdateUser() + public function testUpdateUser(): void { $client = self::$client; @@ -206,13 +210,18 @@ public function testUpdateUser() $path = str_replace($pattern, $data, $path); $crawler = $client->request('PUT', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + $this->markTestSkipped('Test for updateUser not implemented'); } - protected function genTestData($regexp) + /** + * @param string $regexp + * @return mixed + */ + protected function genTestData(string $regexp) { - $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); - $ast = $compiler->parse($regexp); + $ast = $compiler->parse($regexp); $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); return $generator->visit($ast); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php index 9aed375ad0d7..608b63fdc091 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/AppKernel.php @@ -8,15 +8,20 @@ class AppKernel extends Kernel { + /** + * @inheritDoc + */ public function registerBundles(): iterable { - $bundles = array( - new FrameworkBundle() - ); - - return $bundles; + return [ + new FrameworkBundle(), + ]; } + /** + * @inheritDoc + * @throws \Exception + */ public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load(__DIR__.'/test_config.yml'); diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php index 18671580c34e..9e2328a813f0 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php @@ -43,21 +43,16 @@ */ class ControllerTest extends TestCase { - /** * Tests isContentTypeAllowed static method. * - * @param string $contentType - * @param array $consumes - * @param bool $expectedReturn - * * @covers ::isContentTypeAllowed - * @dataProvider provideArgumentsForIsContentTypeAllowed + * @dataProvider dataProviderIsContentTypeAllowed */ - public function testIsContentTypeAllowed($contentType, array $consumes, $expectedReturn) + public function testIsContentTypeAllowed(?string $contentType, array $consumes, bool $expectedReturn): void { $request = new Request(); - $request->headers->set('CONTENT_TYPE', $contentType, true);// last one argument overrides header + $request->headers->set('CONTENT_TYPE', $contentType);// last one argument overrides header $this->assertSame( $expectedReturn, Controller::isContentTypeAllowed($request, $consumes), @@ -70,7 +65,7 @@ public function testIsContentTypeAllowed($contentType, array $consumes, $expecte ); } - public function provideArgumentsForIsContentTypeAllowed() + public function dataProviderIsContentTypeAllowed(): array { return [ 'usual JSON content type' => [ diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php index 8bbaee822e3d..e1a93fc58dd9 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/ApiResponseTest.php @@ -29,20 +29,22 @@ namespace OpenAPI\Server\Model; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * ApiResponseTest Class Doc Comment * - * @category Class */ -// * @description Describes the result of uploading an image resource -/** + * @category Class + * @description Describes the result of uploading an image resource * @package OpenAPI\Server\Tests\Model * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \OpenAPI\Server\Model\ApiResponse */ class ApiResponseTest extends TestCase { + protected ApiResponse|MockObject $object; /** * Setup before running any test case @@ -56,6 +58,7 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { + $this->object = $this->getMockBuilder(ApiResponse::class)->getMockForAbstractClass(); } /** @@ -73,31 +76,45 @@ public static function tearDownAfterClass(): void } /** - * Test "ApiResponse" + * @group integration + * @small */ - public function testApiResponse() + public function testTestClassExists(): void { - $testApiResponse = new ApiResponse(); + $this->assertTrue(class_exists(ApiResponse::class)); + $this->assertInstanceOf(ApiResponse::class, $this->object); } /** * Test attribute "code" + * + * @group unit + * @small */ - public function testPropertyCode() + public function testPropertyCode(): void { + $this->markTestSkipped('Test for property code not implemented'); } /** * Test attribute "type" + * + * @group unit + * @small */ - public function testPropertyType() + public function testPropertyType(): void { + $this->markTestSkipped('Test for property type not implemented'); } /** * Test attribute "message" + * + * @group unit + * @small */ - public function testPropertyMessage() + public function testPropertyMessage(): void { + $this->markTestSkipped('Test for property message not implemented'); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php index 8b225b838ca2..83357931e9b0 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/CategoryTest.php @@ -29,20 +29,22 @@ namespace OpenAPI\Server\Model; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * CategoryTest Class Doc Comment * - * @category Class */ -// * @description A category for a pet -/** + * @category Class + * @description A category for a pet * @package OpenAPI\Server\Tests\Model * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \OpenAPI\Server\Model\Category */ class CategoryTest extends TestCase { + protected Category|MockObject $object; /** * Setup before running any test case @@ -56,6 +58,7 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { + $this->object = $this->getMockBuilder(Category::class)->getMockForAbstractClass(); } /** @@ -73,24 +76,34 @@ public static function tearDownAfterClass(): void } /** - * Test "Category" + * @group integration + * @small */ - public function testCategory() + public function testTestClassExists(): void { - $testCategory = new Category(); + $this->assertTrue(class_exists(Category::class)); + $this->assertInstanceOf(Category::class, $this->object); } /** * Test attribute "id" + * + * @group unit + * @small */ - public function testPropertyId() + public function testPropertyId(): void { + $this->markTestSkipped('Test for property id not implemented'); } /** * Test attribute "name" + * + * @group unit + * @small */ - public function testPropertyName() + public function testPropertyName(): void { + $this->markTestSkipped('Test for property name not implemented'); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/OrderTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/OrderTest.php index 8a65c0a5115d..230058daff07 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/OrderTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/OrderTest.php @@ -29,20 +29,22 @@ namespace OpenAPI\Server\Model; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * OrderTest Class Doc Comment * - * @category Class */ -// * @description An order for a pets from the pet store -/** + * @category Class + * @description An order for a pets from the pet store * @package OpenAPI\Server\Tests\Model * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \OpenAPI\Server\Model\Order */ class OrderTest extends TestCase { + protected Order|MockObject $object; /** * Setup before running any test case @@ -56,6 +58,7 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { + $this->object = $this->getMockBuilder(Order::class)->getMockForAbstractClass(); } /** @@ -73,52 +76,78 @@ public static function tearDownAfterClass(): void } /** - * Test "Order" + * @group integration + * @small */ - public function testOrder() + public function testTestClassExists(): void { - $testOrder = new Order(); + $this->assertTrue(class_exists(Order::class)); + $this->assertInstanceOf(Order::class, $this->object); } /** * Test attribute "id" + * + * @group unit + * @small */ - public function testPropertyId() + public function testPropertyId(): void { + $this->markTestSkipped('Test for property id not implemented'); } /** * Test attribute "petId" + * + * @group unit + * @small */ - public function testPropertyPetId() + public function testPropertyPetId(): void { + $this->markTestSkipped('Test for property petId not implemented'); } /** * Test attribute "quantity" + * + * @group unit + * @small */ - public function testPropertyQuantity() + public function testPropertyQuantity(): void { + $this->markTestSkipped('Test for property quantity not implemented'); } /** * Test attribute "shipDate" + * + * @group unit + * @small */ - public function testPropertyShipDate() + public function testPropertyShipDate(): void { + $this->markTestSkipped('Test for property shipDate not implemented'); } /** * Test attribute "status" + * + * @group unit + * @small */ - public function testPropertyStatus() + public function testPropertyStatus(): void { + $this->markTestSkipped('Test for property status not implemented'); } /** * Test attribute "complete" + * + * @group unit + * @small */ - public function testPropertyComplete() + public function testPropertyComplete(): void { + $this->markTestSkipped('Test for property complete not implemented'); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php index 0c47d89d1af7..defee76700df 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/PetTest.php @@ -29,20 +29,22 @@ namespace OpenAPI\Server\Model; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * PetTest Class Doc Comment * - * @category Class */ -// * @description A pet for sale in the pet store -/** + * @category Class + * @description A pet for sale in the pet store * @package OpenAPI\Server\Tests\Model * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \OpenAPI\Server\Model\Pet */ class PetTest extends TestCase { + protected Pet|MockObject $object; /** * Setup before running any test case @@ -56,6 +58,7 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { + $this->object = $this->getMockBuilder(Pet::class)->getMockForAbstractClass(); } /** @@ -73,52 +76,78 @@ public static function tearDownAfterClass(): void } /** - * Test "Pet" + * @group integration + * @small */ - public function testPet() + public function testTestClassExists(): void { - $testPet = new Pet(); + $this->assertTrue(class_exists(Pet::class)); + $this->assertInstanceOf(Pet::class, $this->object); } /** * Test attribute "id" + * + * @group unit + * @small */ - public function testPropertyId() + public function testPropertyId(): void { + $this->markTestSkipped('Test for property id not implemented'); } /** * Test attribute "category" + * + * @group unit + * @small */ - public function testPropertyCategory() + public function testPropertyCategory(): void { + $this->markTestSkipped('Test for property category not implemented'); } /** * Test attribute "name" + * + * @group unit + * @small */ - public function testPropertyName() + public function testPropertyName(): void { + $this->markTestSkipped('Test for property name not implemented'); } /** * Test attribute "photoUrls" + * + * @group unit + * @small */ - public function testPropertyPhotoUrls() + public function testPropertyPhotoUrls(): void { + $this->markTestSkipped('Test for property photoUrls not implemented'); } /** * Test attribute "tags" + * + * @group unit + * @small */ - public function testPropertyTags() + public function testPropertyTags(): void { + $this->markTestSkipped('Test for property tags not implemented'); } /** * Test attribute "status" + * + * @group unit + * @small */ - public function testPropertyStatus() + public function testPropertyStatus(): void { + $this->markTestSkipped('Test for property status not implemented'); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php index 313756158238..1296d5972af5 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/TagTest.php @@ -29,20 +29,22 @@ namespace OpenAPI\Server\Model; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * TagTest Class Doc Comment * - * @category Class */ -// * @description A tag for a pet -/** + * @category Class + * @description A tag for a pet * @package OpenAPI\Server\Tests\Model * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \OpenAPI\Server\Model\Tag */ class TagTest extends TestCase { + protected Tag|MockObject $object; /** * Setup before running any test case @@ -56,6 +58,7 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { + $this->object = $this->getMockBuilder(Tag::class)->getMockForAbstractClass(); } /** @@ -73,24 +76,34 @@ public static function tearDownAfterClass(): void } /** - * Test "Tag" + * @group integration + * @small */ - public function testTag() + public function testTestClassExists(): void { - $testTag = new Tag(); + $this->assertTrue(class_exists(Tag::class)); + $this->assertInstanceOf(Tag::class, $this->object); } /** * Test attribute "id" + * + * @group unit + * @small */ - public function testPropertyId() + public function testPropertyId(): void { + $this->markTestSkipped('Test for property id not implemented'); } /** * Test attribute "name" + * + * @group unit + * @small */ - public function testPropertyName() + public function testPropertyName(): void { + $this->markTestSkipped('Test for property name not implemented'); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/UserTest.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/UserTest.php index 0e324a638dc3..c485d931d964 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/UserTest.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Model/UserTest.php @@ -29,20 +29,22 @@ namespace OpenAPI\Server\Model; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * UserTest Class Doc Comment * - * @category Class */ -// * @description A User who is purchasing from the pet store -/** + * @category Class + * @description A User who is purchasing from the pet store * @package OpenAPI\Server\Tests\Model * @author openapi-generator contributors * @link https://github.com/openapitools/openapi-generator + * @coversDefaultClass \OpenAPI\Server\Model\User */ class UserTest extends TestCase { + protected User|MockObject $object; /** * Setup before running any test case @@ -56,6 +58,7 @@ public static function setUpBeforeClass(): void */ public function setUp(): void { + $this->object = $this->getMockBuilder(User::class)->getMockForAbstractClass(); } /** @@ -73,66 +76,100 @@ public static function tearDownAfterClass(): void } /** - * Test "User" + * @group integration + * @small */ - public function testUser() + public function testTestClassExists(): void { - $testUser = new User(); + $this->assertTrue(class_exists(User::class)); + $this->assertInstanceOf(User::class, $this->object); } /** * Test attribute "id" + * + * @group unit + * @small */ - public function testPropertyId() + public function testPropertyId(): void { + $this->markTestSkipped('Test for property id not implemented'); } /** * Test attribute "username" + * + * @group unit + * @small */ - public function testPropertyUsername() + public function testPropertyUsername(): void { + $this->markTestSkipped('Test for property username not implemented'); } /** * Test attribute "firstName" + * + * @group unit + * @small */ - public function testPropertyFirstName() + public function testPropertyFirstName(): void { + $this->markTestSkipped('Test for property firstName not implemented'); } /** * Test attribute "lastName" + * + * @group unit + * @small */ - public function testPropertyLastName() + public function testPropertyLastName(): void { + $this->markTestSkipped('Test for property lastName not implemented'); } /** * Test attribute "email" + * + * @group unit + * @small */ - public function testPropertyEmail() + public function testPropertyEmail(): void { + $this->markTestSkipped('Test for property email not implemented'); } /** * Test attribute "password" + * + * @group unit + * @small */ - public function testPropertyPassword() + public function testPropertyPassword(): void { + $this->markTestSkipped('Test for property password not implemented'); } /** * Test attribute "phone" + * + * @group unit + * @small */ - public function testPropertyPhone() + public function testPropertyPhone(): void { + $this->markTestSkipped('Test for property phone not implemented'); } /** * Test attribute "userStatus" + * + * @group unit + * @small */ - public function testPropertyUserStatus() + public function testPropertyUserStatus(): void { + $this->markTestSkipped('Test for property userStatus not implemented'); } } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml index a06bcfef45aa..4c7970ab71ad 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/test_config.yml @@ -5,4 +5,4 @@ framework: secret: "testsecret" test: ~ router: - resource: "%kernel.project_dir%/../Resources/config/routing.yml" + resource: "%kernel.project_dir%/Resources/config/routing.yml" diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist b/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist index e754829e6283..a12d3c3c8708 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist @@ -1,24 +1,26 @@ - + stopOnFailure="false" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> + + + ././Api + ././Model + ././Controller + + - + ./Tests/Api ./Tests/Model ./Tests/Controller - - - ././Api - ././Model - ././Controller - -