forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[php-symfony] Fix problem with clients, that put charset in content t…
…ype header. (OpenAPITools#6078) * Fix problem with clients, that put charset in content type header. With this fix header "Content-Type: application/json; charset=utf-8" working same as "Content-Type: application/json" for parse input data * Fix code style, add $consumes length check. * Add isContentTypeAllowed static method and tests * Fix old tests Right now serializer doesn't support anything beside json and xml. Call tests with application/json instead of form data. Co-authored-by: Yuriy Belenko <yura-bely@mail.ru>
- Loading branch information
Showing
15 changed files
with
344 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
/** | ||
* ControllerTest | ||
* PHP version 5 | ||
* | ||
* @category Class | ||
* @package {{controllerTestsPackage}} | ||
* @author openapi-generator contributors | ||
* @link https://github.com/openapitools/openapi-generator | ||
*/ | ||
|
||
{{>partial_header}} | ||
/** | ||
* NOTE: This class is auto generated by the openapi generator program. | ||
* https://github.com/openapitools/openapi-generator | ||
* Please update the test case below to test the endpoint. | ||
*/ | ||
|
||
namespace {{controllerTestsPackage}}; | ||
|
||
use {{controllerPackage}}\Controller; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* ControllerTest Class Doc Comment | ||
* | ||
* @category Class | ||
* @package {{controllerTestsPackage}} | ||
* @author openapi-generator contributors | ||
* @link https://github.com/openapitools/openapi-generator | ||
* @coversDefaultClass \{{controllerPackage}}\Controller | ||
*/ | ||
class ControllerTest extends TestCase | ||
{ | ||
/** | ||
* Tests isContentTypeAllowed static method. | ||
* | ||
* @param string $contentType | ||
* @param array $consumes | ||
* @param bool $expectedReturn | ||
* | ||
* @covers ::isContentTypeAllowed | ||
* @dataProvider provideArgumentsForIsContentTypeAllowed | ||
*/ | ||
public function testIsContentTypeAllowed($contentType, array $consumes, $expectedReturn) | ||
{ | ||
$request = new Request(); | ||
$request->headers->set('CONTENT_TYPE', $contentType, true);// last one argument overrides header | ||
$this->assertSame( | ||
$expectedReturn, | ||
Controller::isContentTypeAllowed($request, $consumes), | ||
sprintf( | ||
'Failed assertion that "Content-Type: %s" %s by [%s] consumes array.', | ||
$contentType, | ||
($expectedReturn) ? 'is allowed' : 'is forbidden', | ||
implode(', ', $consumes) | ||
) | ||
); | ||
} | ||
|
||
public function provideArgumentsForIsContentTypeAllowed() | ||
{ | ||
return [ | ||
'usual JSON content type' => [ | ||
'application/json', | ||
['application/json'], | ||
true, | ||
], | ||
'extended content type from PR #6078' => [ | ||
'application/json; charset=utf-8', | ||
['application/json'], | ||
true, | ||
], | ||
'more than one content types' => [ | ||
'application/json', | ||
['application/xml', 'application/json; charset=utf-8'], | ||
true, | ||
], | ||
'empty consumes array' => [ | ||
'application/json', | ||
[], | ||
true, | ||
], | ||
'empty consumes and content type' => [ | ||
null, | ||
[], | ||
true, | ||
], | ||
'consumes everything' => [ | ||
'application/json', | ||
['*/*'], | ||
true, | ||
], | ||
'fancy custom content type' => [ | ||
'foobar/foobaz', | ||
['application/xml', 'foobar/foobaz; charset=utf-8'], | ||
true, | ||
], | ||
'empty content type' => [ | ||
null, | ||
['application/xml', 'application/json; charset=utf-8'], | ||
false, | ||
], | ||
'content type out of consumes' => [ | ||
'text/html', | ||
['application/xml', 'application/json; charset=utf-8'], | ||
false, | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.