Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks for php generator, based on issues reported by PHP static analysis tools (PHPStan) #7376

Merged
merged 1 commit into from
Sep 27, 2020

Conversation

dkarlovi
Copy link
Contributor

@dkarlovi dkarlovi commented Sep 9, 2020

About

Purpose of this PR is to start fixing small and not so small issues found by PHPStan, after having applied CS Fixer 2.x.

hese templates are directly used in my specialization of OpenAPI generator, you can see a sample Reddit client. The purpose of the specialization is to iterate quickly, being able to collect many issues and fix them in bulk.

How to see the issues (required functional Docker):

Reported by Psalm:

git clone [email protected]:flexolabs/reddit-client.git
cd reddit-client/
make composer-install
make psalm

You can also run PHPStan, but need to change level in phpstan.neon.dist to:

level: max

and then run:

make phpstan

With everything enabled (strict rules, all other checks), this version of PHPStan finds 109 errors for me.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ackintosh (2017/09) heart, @ybelenko (2018/07), @renepardon (2018/12)

@ybelenko
Copy link
Contributor

ybelenko commented Sep 9, 2020

@dkarlovi Can you attach Psalm report from you build(any php generator) right to that conversion? Just as a visual example of what should be fixed in next PRs.

@@ -423,7 +426,7 @@ class Configuration
/**
* Returns an array of host settings
*
* @return an array of host settings
* @return array an array of host settings
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type completely missing here.

* @return URL based on host settings
* @param int $index index of the host settings
* @param array|null $variables hash of variable and the corresponding value (optional)
* @return string URL based on host settings
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type completely missing here.

@@ -51,20 +51,26 @@ class ObjectSerializer
* @param string $type the OpenAPIToolsType of the data
* @param string $format the format of the OpenAPITools type of the data
*
* @return string|object serialized form of $data
* @return scalar|object|array|null serialized form of $data
*/
public static function sanitizeForSerialization($data, $type = null, $format = null)
{
if (is_scalar($data) || null === $data) {
return $data;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code simplified since it's returning, no need for elseif.

*/
public function setHostIndex($host_index)
public function setHostIndex($hostIndex)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS change

}

/**
* Get the host index
*
* @return Host index
* @return int Host index
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing type.

@@ -16,7 +16,7 @@
* Please update the test case below to test the endpoint.
*/

namespace {{invokerPackage}};
namespace {{invokerPackage}}\Test\Api;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests were placed in totally wrong namespace.

@@ -36,6 +36,6 @@
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" }
},
"autoload-dev": {
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{testBasePath}}/" }
"psr-4": { "{{escapedInvokerPackage}}\\Test\\" : "{{testBasePath}}/" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests placed in the wrong namespace.

@@ -38,6 +38,11 @@ use \{{invokerPackage}}\ObjectSerializer;
* @package {{invokerPackage}}
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
{{^isEnum}}
* @implements \ArrayAccess<TKey, TValue>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generics.

@dkarlovi
Copy link
Contributor Author

dkarlovi commented Sep 9, 2020

@ybelenko

 ------ ----------------------------------------------------------------------- 
  Line   src/Api/UserApi.php                                                    
 ------ ----------------------------------------------------------------------- 
  88     Short ternary operator is not allowed. Use null coalesce operator if   
         applicable or consider using long ternary.                             
  89     Short ternary operator is not allowed. Use null coalesce operator if   
         applicable or consider using long ternary.                             
  90     Short ternary operator is not allowed. Use null coalesce operator if   
         applicable or consider using long ternary.                             
  130    Method Flexolabs\RedditClient\Api\UserApi::getSaved() return type      
         with generic class Flexolabs\RedditClient\Model\Me does not specify    
         its types: TKey, TValue                                                
         💡 You can turn this off by setting                                     
         checkGenericClassInNonGenericObjectType: false in your                 
         phpstan.neon.dist.                                                     
  150    Method Flexolabs\RedditClient\Api\UserApi::getSavedWithHttpInfo()      
         return type has no value type specified in iterable type array.        
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  159    Cannot call method getBody() on                                        
         Psr\Http\Message\ResponseInterface|null.                               
  159    Cannot call method getHeaders() on                                     
         Psr\Http\Message\ResponseInterface|null.                               
  159    Only booleans are allowed in a ternary operator condition,             
         Psr\Http\Message\ResponseInterface|null given.                         
  159    Only booleans are allowed in a ternary operator condition,             
         Psr\Http\Message\ResponseInterface|null given.                         
  159    Parameter #3 $responseHeaders of class                                 
         Flexolabs\RedditClient\ApiException constructor expects                
         array<string>|null, array<array<string>>|null given.                   
  165    Parameter #3 $responseHeaders of class                                 
         Flexolabs\RedditClient\ApiException constructor expects                
         array<string>|null, array<array<string>> given.                        
  165    Parameter #4 $responseBody of class                                    
         Flexolabs\RedditClient\ApiException constructor expects                
         stdClass|string|null, Psr\Http\Message\StreamInterface given.          
  171    Strict comparison using === between '\\Flexolabs…' and                 
         '\\SplFileObject' will always evaluate to false.                       
  186    Strict comparison using === between '\\Flexolabs…' and                 
         '\\SplFileObject' will always evaluate to false.                       
  250    Anonymous function should have native return typehint "array".         
  252    Strict comparison using === between '\\Flexolabs…' and                 
         '\\SplFileObject' will always evaluate to false.                       
  283    Method Flexolabs\RedditClient\Api\UserApi::me() return type with       
         generic class Flexolabs\RedditClient\Model\Me does not specify its     
         types: TKey, TValue                                                    
         💡 You can turn this off by setting                                     
         checkGenericClassInNonGenericObjectType: false in your                 
         phpstan.neon.dist.                                                     
  303    Method Flexolabs\RedditClient\Api\UserApi::meWithHttpInfo() return     
         type has no value type specified in iterable type array.               
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  312    Cannot call method getBody() on                                        
         Psr\Http\Message\ResponseInterface|null.                               
  312    Cannot call method getHeaders() on                                     
         Psr\Http\Message\ResponseInterface|null.                               
  312    Only booleans are allowed in a ternary operator condition,             
         Psr\Http\Message\ResponseInterface|null given.                         
  312    Only booleans are allowed in a ternary operator condition,             
         Psr\Http\Message\ResponseInterface|null given.                         
  312    Parameter #3 $responseHeaders of class                                 
         Flexolabs\RedditClient\ApiException constructor expects                
         array<string>|null, array<array<string>>|null given.                   
  318    Parameter #3 $responseHeaders of class                                 
         Flexolabs\RedditClient\ApiException constructor expects                
         array<string>|null, array<array<string>> given.                        
  318    Parameter #4 $responseBody of class                                    
         Flexolabs\RedditClient\ApiException constructor expects                
         stdClass|string|null, Psr\Http\Message\StreamInterface given.          
  324    Strict comparison using === between '\\Flexolabs…' and                 
         '\\SplFileObject' will always evaluate to false.                       
  339    Strict comparison using === between '\\Flexolabs…' and                 
         '\\SplFileObject' will always evaluate to false.                       
  403    Anonymous function should have native return typehint "array".         
  405    Strict comparison using === between '\\Flexolabs…' and                 
         '\\SplFileObject' will always evaluate to false.                       
  436    Call to function is_array() with string will always evaluate to        
         false.                                                                 
         💡 Because the type is coming from a PHPDoc, you can turn off this      
         check by setting treatPhpDocTypesAsCertain: false in your              
         phpstan.neon.dist.                                                     
  436    Result of && is always false.                                          
  436    Result of || is always false.                                          
         💡 Because the type is coming from a PHPDoc, you can turn off this      
         check by setting treatPhpDocTypesAsCertain: false in your              
         phpstan.neon.dist.                                                     
  436    Strict comparison using === between string and null will always        
         evaluate to false.                                                     
  454    Call to function is_array() with int|null will always evaluate to      
         false.                                                                 
         💡 Because the type is coming from a PHPDoc, you can turn off this      
         check by setting treatPhpDocTypesAsCertain: false in your              
         phpstan.neon.dist.                                                     
  462    Strict comparison using !== between string and null will always        
         evaluate to true.                                                      
  473    If condition is always false.                                          
  485    Variable $_tempBody in isset() is always null.                         
  492    Comparison operation ">" between 0 and 0 is always false.              
  493    If condition is always false.                                          
  495    Empty array passed to foreach.                                         
  496    Call to function is_array() with *NEVER* will always evaluate to       
         true.                                                                  
  496    Else branch is unreachable because ternary operator condition is       
         always true.                                                           
  515    Strict comparison using !== between string and null will always        
         evaluate to true.                                                      
  520    Only booleans are allowed in an if condition, string given.            
  534    Only booleans are allowed in a ternary operator condition, string      
         given.                                                                 
  560    If condition is always false.                                          
  572    Variable $_tempBody in isset() is always null.                         
  579    Comparison operation ">" between 0 and 0 is always false.              
  580    If condition is always false.                                          
  582    Empty array passed to foreach.                                         
  583    Call to function is_array() with *NEVER* will always evaluate to       
         true.                                                                  
  583    Else branch is unreachable because ternary operator condition is       
         always true.                                                           
  602    Strict comparison using !== between string and null will always        
         evaluate to true.                                                      
  607    Only booleans are allowed in an if condition, string given.            
  627    Only booleans are allowed in a ternary operator condition, string      
         given.                                                                 
  640    Method Flexolabs\RedditClient\Api\UserApi::createHttpClientOption()    
         return type has no value type specified in iterable type array.        
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  645    Only booleans are allowed in a negated boolean, resource|false given.  
 ------ ----------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------- 
  Line   src/Configuration.php                                                  
 ------ ----------------------------------------------------------------------- 
  287    Call to function is_string() with string will always evaluate to       
         true.                                                                  
         💡 Because the type is coming from a PHPDoc, you can turn off this      
         check by setting treatPhpDocTypesAsCertain: false in your              
         phpstan.neon.dist.                                                     
  442    Method Flexolabs\RedditClient\Configuration::getHostSettings() return  
         type has no value type specified in iterable type array.               
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  460    Method Flexolabs\RedditClient\Configuration::getHostFromSettings()     
         has parameter $variables with no value type specified in iterable      
         type array.                                                            
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
 ------ ----------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------- 
  Line   src/HeaderSelector.php                                                
 ------ ---------------------------------------------------------------------- 
  49     Method Flexolabs\RedditClient\HeaderSelector::selectHeaders() return  
         type has no value type specified in iterable type array.              
         💡 Consider adding something like array<Foo> to the                    
         PHPDoc.                                                               
         You can turn off this check by setting                                
         checkMissingIterableValueType: false in your                          
         phpstan.neon.dist.                                                    
  66     Method                                                                
         Flexolabs\RedditClient\HeaderSelector::selectHeadersForMultipart()    
         return type has no value type specified in iterable type array.       
         💡 Consider adding something like array<Foo> to the                    
         PHPDoc.                                                               
         You can turn off this check by setting                                
         checkMissingIterableValueType: false in your                          
         phpstan.neon.dist.                                                    
  86     Only booleans are allowed in an elseif condition, array given.        
  104    Only booleans are allowed in an elseif condition, array given.        
 ------ ---------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------- 
  Line   src/Model/Me.php                                                       
 ------ ----------------------------------------------------------------------- 
  138    Method Flexolabs\RedditClient\Model\Me::__toString() should return     
         string but returns string|false.                                       
  147    Method Flexolabs\RedditClient\Model\Me::openAPITypes() return type     
         has no value type specified in iterable type array.                    
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  155    Method Flexolabs\RedditClient\Model\Me::openAPIFormats() return type   
         has no value type specified in iterable type array.                    
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  164    Method Flexolabs\RedditClient\Model\Me::attributeMap() return type     
         has no value type specified in iterable type array.                    
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  172    Method Flexolabs\RedditClient\Model\Me::setters() return type has no   
         value type specified in iterable type array.                           
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  180    Method Flexolabs\RedditClient\Model\Me::getters() return type has no   
         value type specified in iterable type array.                           
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  198    Method Flexolabs\RedditClient\Model\Me::listInvalidProperties()        
         return type has no value type specified in iterable type array.        
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  236    Method Flexolabs\RedditClient\Model\Me::setId() return type with       
         generic class Flexolabs\RedditClient\Model\Me does not specify its     
         types: TKey, TValue                                                    
         💡 You can turn this off by setting                                     
         checkGenericClassInNonGenericObjectType: false in your                 
         phpstan.neon.dist.                                                     
  256    Method Flexolabs\RedditClient\Model\Me::setName() return type with     
         generic class Flexolabs\RedditClient\Model\Me does not specify its     
         types: TKey, TValue                                                    
         💡 You can turn this off by setting                                     
         checkGenericClassInNonGenericObjectType: false in your                 
         phpstan.neon.dist.                                                     
  280    Return type (mixed) of method                                          
         Flexolabs\RedditClient\Model\Me::offsetGet() should be covariant with  
         return type (TValue|null) of method                                    
         ArrayAccess<TKey,TValue>::offsetGet()                                  
  315    Method Flexolabs\RedditClient\Model\Me::toHeaderValue() should return  
         string but returns string|false.                                       
 ------ ----------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------- 
  Line   src/Model/ModelInterface.php                                          
 ------ ---------------------------------------------------------------------- 
  50     Method Flexolabs\RedditClient\Model\ModelInterface::openAPITypes()    
         return type has no value type specified in iterable type array.       
         💡 Consider adding something like array<Foo> to the                    
         PHPDoc.                                                               
         You can turn off this check by setting                                
         checkMissingIterableValueType: false in your                          
         phpstan.neon.dist.                                                    
  55     Method Flexolabs\RedditClient\Model\ModelInterface::openAPIFormats()  
         return type has no value type specified in iterable type array.       
         💡 Consider adding something like array<Foo> to the                    
         PHPDoc.                                                               
         You can turn off this check by setting                                
         checkMissingIterableValueType: false in your                          
         phpstan.neon.dist.                                                    
  60     Method Flexolabs\RedditClient\Model\ModelInterface::attributeMap()    
         return type has no value type specified in iterable type array.       
         💡 Consider adding something like array<Foo> to the                    
         PHPDoc.                                                               
         You can turn off this check by setting                                
         checkMissingIterableValueType: false in your                          
         phpstan.neon.dist.                                                    
  65     Method Flexolabs\RedditClient\Model\ModelInterface::setters() return  
         type has no value type specified in iterable type array.              
         💡 Consider adding something like array<Foo> to the                    
         PHPDoc.                                                               
         You can turn off this check by setting                                
         checkMissingIterableValueType: false in your                          
         phpstan.neon.dist.                                                    
  70     Method Flexolabs\RedditClient\Model\ModelInterface::getters() return  
         type has no value type specified in iterable type array.              
         💡 Consider adding something like array<Foo> to the                    
         PHPDoc.                                                               
         You can turn off this check by setting                                
         checkMissingIterableValueType: false in your                          
         phpstan.neon.dist.                                                    
  75     Method                                                                
         Flexolabs\RedditClient\Model\ModelInterface::listInvalidProperties()  
         return type has no value type specified in iterable type array.       
         💡 Consider adding something like array<Foo> to the                    
         PHPDoc.                                                               
         You can turn off this check by setting                                
         checkMissingIterableValueType: false in your                          
         phpstan.neon.dist.                                                    
 ------ ---------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------- 
  Line   src/ObjectSerializer.php                                               
 ------ ----------------------------------------------------------------------- 
  70     Method                                                                 
         Flexolabs\RedditClient\ObjectSerializer::sanitizeForSerialization()    
         return type has no value type specified in iterable type array.        
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  94     Variable method call on Flexolabs\RedditClient\Model\ModelInterface.   
  98     Static call to instance method stdClass::getAllowableEnumValues().     
  99     Static call to instance method stdClass::getAllowableEnumValues().     
  107    Argument of an invalid type object supplied for foreach, only          
         iterables are supported.                                               
  128    Only booleans are allowed in an if condition, int|false given.         
  179    Cannot call method toHeaderValue() on string.                          
  197    Method Flexolabs\RedditClient\ObjectSerializer::toFormValue() should   
         return string but returns string|false.                                
  215    Instanceof between bool|DateTime|string and DateTimeImmutable will     
         always evaluate to false.                                              
         💡 Because the type is coming from a PHPDoc, you can turn off this      
         check by setting treatPhpDocTypesAsCertain: false in your              
         phpstan.neon.dist.                                                     
  221    Method Flexolabs\RedditClient\ObjectSerializer::toString() should      
         return string but returns DateTime|string.                             
  232    Method Flexolabs\RedditClient\ObjectSerializer::serializeCollection()  
         has parameter $collection with no value type specified in iterable     
         type array.                                                            
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  237    Method Flexolabs\RedditClient\ObjectSerializer::serializeCollection()  
         should return string but returns string|null.                          
  268    Method Flexolabs\RedditClient\ObjectSerializer::deserialize() return   
         type has no value type specified in iterable type array.               
         💡 Consider adding something like array<Foo> to the                     
         PHPDoc.                                                                
         You can turn off this check by setting                                 
         checkMissingIterableValueType: false in your                           
         phpstan.neon.dist.                                                     
  319    Construct empty() is not allowed. Use more strict comparison.          
  336    Only booleans are allowed in &&, int|false given on the right side.    
  336    Parameter #2 $search of function array_key_exists expects array,       
         array<string>|null given.                                              
  343    Parameter #1 $filename of function fopen expects string, string|false  
         given.                                                                 
  345    Parameter #1 $fp of function fwrite expects resource, resource|false   
         given.                                                                 
  347    Parameter #1 $fp of function fclose expects resource, resource|false   
         given.                                                                 
  349    Parameter #1 $filename of class SplFileObject constructor expects      
         string, string|false given.                                            
  361    Construct empty() is not allowed. Use more strict comparison.          
  361    Variable property access on mixed.                                     
  361    Variable property access on mixed.                                     
  362    Variable property access on mixed.                                     
  371    Variable property access on mixed.                                     
  375    Variable property access on mixed.                                     
  376    Variable $propertyValue in isset() always exists and is not nullable.  
  377    Variable method call on mixed.                                         
 ------ ----------------------------------------------------------------------- 

 [ERROR] Found 109 errors                                                       

@dkarlovi
Copy link
Contributor Author

@ybelenko note these errors are after this PR, which fixes quite a bit of them already, this is only one step in the direction of #7284, improving the generated code significantly, one PR at a time.

@dkarlovi
Copy link
Contributor Author

@ybelenko @wing328 are there any objections here?

@ybelenko
Copy link
Contributor

@dkarlovi Cannot review until Tuesday Sep 22th, sorry.

@dkarlovi
Copy link
Contributor Author

No rush, was just interested if there is something I should do to get it in since I have some time now. Whenever you have time is great, thanks!

@ybelenko
Copy link
Contributor

Can we fix it somehow?

$  vendor/bin/phpunit tests
PHPUnit 9.3.11 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

EEEEE.........ES.................................ESSSSSSSSSSSSSS. 65 / 73 ( 89%)
......E.                                                          73 / 73 (100%)

Time: 00:10.930, Memory: 12.00 MB

There were 8 errors:

1) OpenAPI\Client\AsyncTest::testAsyncRequest
OpenAPI\Client\ApiException: [405] Client error: `POST http://petstore.swagger.io/v2/pet` resulted in a `405 Method Not Allowed` response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiResponse><type>unknown</type></apiResponse>


/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:162
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:135
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/AsyncTest.php:40

2) OpenAPI\Client\AsyncTest::testAsyncRequestWithHttpInfo
OpenAPI\Client\ApiException: [405] Client error: `POST http://petstore.swagger.io/v2/pet` resulted in a `405 Method Not Allowed` response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiResponse><type>unknown</type></apiResponse>


/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:162
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:135
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/AsyncTest.php:40

3) OpenAPI\Client\AsyncTest::testAsyncThrowingException
OpenAPI\Client\ApiException: [405] Client error: `POST http://petstore.swagger.io/v2/pet` resulted in a `405 Method Not Allowed` response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiResponse><type>unknown</type></apiResponse>


/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:162
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:135
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/AsyncTest.php:40

4) OpenAPI\Client\AsyncTest::testAsyncApiExceptionWithoutWaitIsNotThrown
OpenAPI\Client\ApiException: [405] Client error: `POST http://petstore.swagger.io/v2/pet` resulted in a `405 Method Not Allowed` response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiResponse><type>unknown</type></apiResponse>


/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:162
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:135
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/AsyncTest.php:40

5) OpenAPI\Client\AsyncTest::testAsyncHttpInfoThrowingException
OpenAPI\Client\ApiException: [405] Client error: `POST http://petstore.swagger.io/v2/pet` resulted in a `405 Method Not Allowed` response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiResponse><type>unknown</type></apiResponse>


/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:162
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:135
/Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/AsyncTest.php:40

6) OpenAPI\Client\DebugTest::testEnableDebugOutput
OpenAPI\Client\ApiException: [405] Client error: `POST http://petstore.swagger.io/v2/pet` resulted in a `405 Method Not Allowed` response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiResponse><type>unknown</type></apiResponse>
 in /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:162
Stack trace:
#0 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/DebugTest.php(15): OpenAPI\Client\Api\PetApi->addPetWithHttpInfo(Object(OpenAPI\Client\Model\Pet))
#1 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/Framework/TestSuite.php(610): OpenAPI\Client\DebugTest::setUpBeforeClass()
#2 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/Framework/TestSuite.php(665): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#3 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(671): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#4 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/TextUI/Command.php(148): PHPUnit\TextUI\TestRunner->run(Object(PHPUnit\Framework\TestSuite), Array, Array, true)
#5 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/TextUI/Command.php(101): PHPUnit\TextUI\Command->run(Array, true)
#6 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#7 {main}
7) OpenAPI\Client\PetApiTest::testGetPetById
OpenAPI\Client\ApiException: [405] Client error: `POST http://petstore.swagger.io/v2/pet` resulted in a `405 Method Not Allowed` response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiResponse><type>unknown</type></apiResponse>
 in /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:162
Stack trace:
#0 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/PetApiTest.php(49): OpenAPI\Client\Api\PetApi->addPetWithHttpInfo(Object(OpenAPI\Client\Model\Pet))
#1 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/Framework/TestSuite.php(610): OpenAPI\Client\PetApiTest::setUpBeforeClass()
#2 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/Framework/TestSuite.php(665): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#3 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(671): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#4 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/TextUI/Command.php(148): PHPUnit\TextUI\TestRunner->run(Object(PHPUnit\Framework\TestSuite), Array, Array, true)
#5 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/TextUI/Command.php(101): PHPUnit\TextUI\Command->run(Array, true)
#6 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#7 {main}
8) OpenAPI\Client\StoreApiTest::testGetInventory
OpenAPI\Client\ApiException: [405] Client error: `POST http://petstore.swagger.io/v2/pet` resulted in a `405 Method Not Allowed` response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiResponse><type>unknown</type></apiResponse>
 in /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php:162
Stack trace:
#0 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php(135): OpenAPI\Client\Api\PetApi->addPetWithHttpInfo(Object(OpenAPI\Client\Model\Pet))
#1 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/StoreApiTest.php(47): OpenAPI\Client\Api\PetApi->addPet(Object(OpenAPI\Client\Model\Pet))
#2 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/Framework/TestSuite.php(610): OpenAPI\Client\StoreApiTest::setUpBeforeClass()
#3 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/Framework/TestSuite.php(665): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#4 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(671): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#5 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/TextUI/Command.php(148): PHPUnit\TextUI\TestRunner->run(Object(PHPUnit\Framework\TestSuite), Array, Array, true)
#6 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/src/TextUI/Command.php(101): PHPUnit\TextUI\Command->run(Array, true)
#7 /Users/ybelenko/Sites/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#8 {main}
ERRORS!
Tests: 73, Assertions: 140, Errors: 8, Skipped: 15.

@dkarlovi
Copy link
Contributor Author

@ybelenko how did you get these errors? Running the same command as you, I get:

OK, but incomplete, skipped, or risky tests!
Tests: 288, Assertions: 0, Risky: 288.

@dkarlovi
Copy link
Contributor Author

Oh right, I need to specify tests/ for some reason. Looking at it now.

@dkarlovi
Copy link
Contributor Author

@ybelenko testing this with current master gives me exactly the same result. Is this broken in general?

@ybelenko
Copy link
Contributor

@ybelenko testing this with current master gives me exactly the same result. Is this broken in general?

Yeah, that what I've been afraid of. Ok, let's fix it in another PR.
At least we know that static tests a broken now and I think it's because something changed at http://petstore.swagger.io, not from our side.

@ybelenko ybelenko added this to the 5.0.0 milestone Sep 27, 2020
@ybelenko ybelenko merged commit 2c59f1d into OpenAPITools:master Sep 27, 2020
@dkarlovi dkarlovi deleted the php-tweaks branch September 27, 2020 10:01
@wing328
Copy link
Member

wing328 commented Sep 28, 2020

Looks like this breaks the Travis CI build:

Time: 1.46 seconds, Memory: 10.00 MB

There was 1 failure:

1) OpenAPI\Client\PetApiTest::testFindPetByStatus
Failed asserting that 'available' is identical to true.

/home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/PetApiTest.php:125

Ref: https://travis-ci.org/github/OpenAPITools/openapi-generator/builds/730663358

I'll comment it out for the time being. Please take a look when you guys have time.

@wing328
Copy link
Member

wing328 commented Sep 28, 2020

UPDATE: the failure seems to be intermittent. I'll take another look later today to see what's wrong.

@wing328
Copy link
Member

wing328 commented Sep 28, 2020

FYI. Filed #7525 to fix the issue. The results look good so far.

@dkarlovi
Copy link
Contributor Author

@wing328 AFAIK, this PR should not influence that since it's mostly PHPDoc, we did find out the tests are failing in master prior to merging this also.

@wing328
Copy link
Member

wing328 commented Sep 28, 2020

@dkarlovi I agreed with you this PR didn't cause the failure.

My guess is that it's due to changes in the PHP version or something else in the Travis build images.

@dkarlovi
Copy link
Contributor Author

The PHP client generator could use quite a bit of love in general, I'm working on a specialization of this project and hoping to polish the generator quite a bit, basically doing #7284 here.

@wing328
Copy link
Member

wing328 commented Sep 28, 2020

Totally agreed with you there are rooms for improvements. Look forward to your PRs.

@dkarlovi
Copy link
Contributor Author

@wing328 which generator would you recommend me to look at for good -l integration? Preferably, being able to supply -l multiple times too.

@wing328
Copy link
Member

wing328 commented Sep 28, 2020

What do you mean by -l integration?

I believe -l was replaced by -g a while ago.

@dkarlovi
Copy link
Contributor Author

dkarlovi commented Sep 28, 2020

@wing328 Sorry, I meant this

        --library <library>
            library template (sub-template)

The use case is adding support to build glue code for one or more frameworks directly into the client, making the package work there automagically.

Example

openapi-generator -g php -l symfony -l laravel spec.yaml

Generates:

  1. the current client, this would be helped immensely with [REQ][PHP] depend on meta packages providing the HTTP implementation instead of directly on Guzzle #7518
  2. Symfony bundle bindings
  3. Laravel package bindings

so you can pull the package, it works as raw PHP code, but also as a Symfony or Laravel package by default.

@wing328
Copy link
Member

wing328 commented Sep 28, 2020

The library option usually refers to HTTP library. java client generator supports many different HTTP libraries (e.g. jersey, okhttp, retrofit, resttemplate, resteasy, etc). Usually that done by swapping a different api_client.mustache template.

From what I recall, none of the generators support multiple library option.

You may want to add an option to take a list of supported frameworks/libraries for your use cases (e.g. --additional-properties framework="symfony,laravel")

@dkarlovi
Copy link
Contributor Author

@wing328 OK, I'll take a look, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants