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 d0756dacc2a..ef09fa0caa1 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
@@ -55,6 +55,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
protected String controllerDirName = "Controller";
protected String serviceDirName = "Service";
protected String controllerPackage;
+ protected String controllerTestsPackage;
protected String servicePackage;
protected Boolean phpLegacySupport = Boolean.TRUE;
@@ -301,6 +302,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
additionalProperties.put("servicePackage", servicePackage);
additionalProperties.put("apiTestsPackage", apiTestsPackage);
additionalProperties.put("modelTestsPackage", modelTestsPackage);
+ additionalProperties.put("controllerTestsPackage", controllerTestsPackage);
// make Symonfy-specific properties available
additionalProperties.put("bundleName", bundleName);
@@ -311,11 +313,13 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
// make api and model src path available in mustache template
additionalProperties.put("apiSrcPath", "." + "/" + toSrcPath(apiPackage, srcBasePath));
additionalProperties.put("modelSrcPath", "." + "/" + toSrcPath(modelPackage, srcBasePath));
+ additionalProperties.put("controllerSrcPath", "." + "/" + toSrcPath(controllerPackage, srcBasePath));
additionalProperties.put("testsSrcPath", "." + "/" + toSrcPath(testsPackage, srcBasePath));
additionalProperties.put("apiTestsSrcPath", "." + "/" + toSrcPath(apiTestsPackage, srcBasePath));
additionalProperties.put("modelTestsSrcPath", "." + "/" + toSrcPath(modelTestsPackage, srcBasePath));
additionalProperties.put("apiTestPath", "." + "/" + testsDirName + "/" + apiDirName);
additionalProperties.put("modelTestPath", "." + "/" + testsDirName + "/" + modelDirName);
+ additionalProperties.put("controllerTestPath", "." + "/" + testsDirName + "/" + controllerDirName);
// make api and model doc path available in mustache template
additionalProperties.put("apiDocPath", apiDocPath);
@@ -346,6 +350,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
supportingFiles.add(new SupportingFile("testing/phpunit.xml.mustache", "", "phpunit.xml.dist"));
supportingFiles.add(new SupportingFile("testing/pom.xml", "", "pom.xml"));
supportingFiles.add(new SupportingFile("testing/AppKernel.php", toSrcPath(testsPackage, srcBasePath), "AppKernel.php"));
+ supportingFiles.add(new SupportingFile("testing/ControllerTest.mustache", toSrcPath(controllerTestsPackage, srcBasePath), "ControllerTest.php"));
supportingFiles.add(new SupportingFile("testing/test_config.yml", toSrcPath(testsPackage, srcBasePath), "test_config.yml"));
supportingFiles.add(new SupportingFile("routing.mustache", configDir, "routing.yml"));
@@ -540,6 +545,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
apiTestsPackage = testsPackage + "\\" + apiDirName;
modelTestsPackage = testsPackage + "\\" + modelDirName;
controllerPackage = invokerPackage + "\\" + controllerDirName;
+ controllerTestsPackage = testsPackage + "\\" + controllerDirName;
servicePackage = invokerPackage + "\\" + serviceDirName;
}
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 5922196c186..d7b5d5feec4 100644
--- a/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache
+++ b/modules/openapi-generator/src/main/resources/php-symfony/Controller.mustache
@@ -20,6 +20,7 @@
namespace {{controllerPackage}};
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use {{servicePackage}}\SerializerInterface;
@@ -176,4 +177,40 @@ class Controller extends AbstractController
// If we reach this point, we don't have a common ground between server and client
return null;
}
+
+ /**
+ * Checks whether Content-Type request header presented in supported formats.
+ *
+ * @param Request $request Request instance.
+ * @param array $consumes Array of supported content types.
+ *
+ * @return bool Returns true if Content-Type supported otherwise false.
+ */
+ public static function isContentTypeAllowed(Request $request, array $consumes = [])
+ {
+ if (!empty($consumes) && $consumes[0] !== '*/*') {
+ $currentFormat = $request->getContentType();
+ foreach ($consumes as $mimeType) {
+ // canonize mime type
+ if (is_string($mimeType) && false !== $pos = strpos($mimeType, ';')) {
+ $mimeType = trim(substr($mimeType, 0, $pos));
+ }
+
+ if (!$format = $request->getFormat($mimeType)) {
+ // add custom format to request
+ $format = $mimeType;
+ $request->setFormat($format, $format);
+ $currentFormat = $request->getContentType();
+ }
+
+ if ($format === $currentFormat) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ return true;
+ }
}
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 0a89e839938..c0948e7c2a4 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
@@ -60,8 +60,7 @@ class {{controllerName}} extends Controller
{{#bodyParams}}
// Make sure that the client is providing something that we can consume
$consumes = [{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}];
- $inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
- if (!in_array($inputFormat, $consumes)) {
+ if (!static::isContentTypeAllowed($request, $consumes)) {
// We can't consume the content that the client is sending us
return new Response('', 415);
}
@@ -146,6 +145,7 @@ class {{controllerName}} extends Controller
{{#allParams}}
{{^isFile}}
{{#isBodyParam}}
+ $inputFormat = $request->getMimeType($request->getContentType());
${{paramName}} = $this->deserialize(${{paramName}}, '{{#isContainer}}{{#items}}array<{{dataType}}>{{/items}}{{/isContainer}}{{^isContainer}}{{dataType}}{{/isContainer}}', $inputFormat);
{{/isBodyParam}}
{{^isBodyParam}}
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
new file mode 100644
index 00000000000..382b66c9154
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/php-symfony/testing/ControllerTest.mustache
@@ -0,0 +1,113 @@
+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,
+ ],
+ ];
+ }
+}
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 a279d6e61ea..d7f3c1f7603 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
@@ -99,7 +99,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
$path = str_replace($pattern, $data, $path);
{{/pathParams}}
- $crawler = $client->request('{{httpMethod}}', $path);
+ $crawler = $client->request('{{httpMethod}}', $path{{#hasBodyParam}}, [], [], ['CONTENT_TYPE' => 'application/json']{{/hasBodyParam}});
}
{{/operation}}
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 8a6ff770c44..35e39a7db34 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
@@ -9,12 +9,14 @@
{{apiTestPath}}
{{modelTestPath}}
+ {{controllerTestPath}}
{{apiSrcPath}}
{{modelSrcPath}}
+ {{controllerSrcPath}}
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 2412b9bd264..8f6030e3bd0 100644
--- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/Controller.php
+++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/Controller.php
@@ -30,6 +30,7 @@
namespace OpenAPI\Server\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use OpenAPI\Server\Service\SerializerInterface;
@@ -186,4 +187,40 @@ class Controller extends AbstractController
// If we reach this point, we don't have a common ground between server and client
return null;
}
+
+ /**
+ * Checks whether Content-Type request header presented in supported formats.
+ *
+ * @param Request $request Request instance.
+ * @param array $consumes Array of supported content types.
+ *
+ * @return bool Returns true if Content-Type supported otherwise false.
+ */
+ public static function isContentTypeAllowed(Request $request, array $consumes = [])
+ {
+ if (!empty($consumes) && $consumes[0] !== '*/*') {
+ $currentFormat = $request->getContentType();
+ foreach ($consumes as $mimeType) {
+ // canonize mime type
+ if (is_string($mimeType) && false !== $pos = strpos($mimeType, ';')) {
+ $mimeType = trim(substr($mimeType, 0, $pos));
+ }
+
+ if (!$format = $request->getFormat($mimeType)) {
+ // add custom format to request
+ $format = $mimeType;
+ $request->setFormat($format, $format);
+ $currentFormat = $request->getContentType();
+ }
+
+ if ($format === $currentFormat) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ return true;
+ }
}
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 8a1c9521a6b..5cd8e8c4899 100644
--- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php
+++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/PetController.php
@@ -62,8 +62,7 @@ class PetController extends Controller
{
// Make sure that the client is providing something that we can consume
$consumes = ['application/json', 'application/xml'];
- $inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
- if (!in_array($inputFormat, $consumes)) {
+ if (!static::isContentTypeAllowed($request, $consumes)) {
// We can't consume the content that the client is sending us
return new Response('', 415);
}
@@ -80,6 +79,7 @@ class PetController extends Controller
// Deserialize the input values that needs it
try {
+ $inputFormat = $request->getMimeType($request->getContentType());
$body = $this->deserialize($body, 'OpenAPI\Server\Model\Pet', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
@@ -491,8 +491,7 @@ class PetController extends Controller
{
// Make sure that the client is providing something that we can consume
$consumes = ['application/json', 'application/xml'];
- $inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
- if (!in_array($inputFormat, $consumes)) {
+ if (!static::isContentTypeAllowed($request, $consumes)) {
// We can't consume the content that the client is sending us
return new Response('', 415);
}
@@ -509,6 +508,7 @@ class PetController extends Controller
// Deserialize the input values that needs it
try {
+ $inputFormat = $request->getMimeType($request->getContentType());
$body = $this->deserialize($body, 'OpenAPI\Server\Model\Pet', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
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 a7c17cae0b4..43321377617 100644
--- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php
+++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/StoreController.php
@@ -284,8 +284,7 @@ class StoreController extends Controller
{
// Make sure that the client is providing something that we can consume
$consumes = [];
- $inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
- if (!in_array($inputFormat, $consumes)) {
+ if (!static::isContentTypeAllowed($request, $consumes)) {
// We can't consume the content that the client is sending us
return new Response('', 415);
}
@@ -308,6 +307,7 @@ class StoreController extends Controller
// Deserialize the input values that needs it
try {
+ $inputFormat = $request->getMimeType($request->getContentType());
$body = $this->deserialize($body, 'OpenAPI\Server\Model\Order', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
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 b67fc280982..fcb17c69891 100644
--- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php
+++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Controller/UserController.php
@@ -61,8 +61,7 @@ class UserController extends Controller
{
// Make sure that the client is providing something that we can consume
$consumes = [];
- $inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
- if (!in_array($inputFormat, $consumes)) {
+ if (!static::isContentTypeAllowed($request, $consumes)) {
// We can't consume the content that the client is sending us
return new Response('', 415);
}
@@ -76,6 +75,7 @@ class UserController extends Controller
// Deserialize the input values that needs it
try {
+ $inputFormat = $request->getMimeType($request->getContentType());
$body = $this->deserialize($body, 'OpenAPI\Server\Model\User', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
@@ -138,8 +138,7 @@ class UserController extends Controller
{
// Make sure that the client is providing something that we can consume
$consumes = [];
- $inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
- if (!in_array($inputFormat, $consumes)) {
+ if (!static::isContentTypeAllowed($request, $consumes)) {
// We can't consume the content that the client is sending us
return new Response('', 415);
}
@@ -153,6 +152,7 @@ class UserController extends Controller
// Deserialize the input values that needs it
try {
+ $inputFormat = $request->getMimeType($request->getContentType());
$body = $this->deserialize($body, 'array', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
@@ -217,8 +217,7 @@ class UserController extends Controller
{
// Make sure that the client is providing something that we can consume
$consumes = [];
- $inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
- if (!in_array($inputFormat, $consumes)) {
+ if (!static::isContentTypeAllowed($request, $consumes)) {
// We can't consume the content that the client is sending us
return new Response('', 415);
}
@@ -232,6 +231,7 @@ class UserController extends Controller
// Deserialize the input values that needs it
try {
+ $inputFormat = $request->getMimeType($request->getContentType());
$body = $this->deserialize($body, 'array', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
@@ -592,8 +592,7 @@ class UserController extends Controller
{
// Make sure that the client is providing something that we can consume
$consumes = [];
- $inputFormat = $request->headers->has('Content-Type')?$request->headers->get('Content-Type'):$consumes[0];
- if (!in_array($inputFormat, $consumes)) {
+ if (!static::isContentTypeAllowed($request, $consumes)) {
// We can't consume the content that the client is sending us
return new Response('', 415);
}
@@ -608,6 +607,7 @@ class UserController extends Controller
// Deserialize the input values that needs it
try {
$username = $this->deserialize($username, 'string', 'string');
+ $inputFormat = $request->getMimeType($request->getContentType());
$body = $this->deserialize($body, 'OpenAPI\Server\Model\User', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
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 91b849f2b27..de5c77400fe 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
@@ -85,7 +85,7 @@ class PetApiInterfaceTest extends WebTestCase
$path = '/pet';
- $crawler = $client->request('POST', $path);
+ $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']);
}
/**
@@ -166,7 +166,7 @@ class PetApiInterfaceTest extends WebTestCase
$path = '/pet';
- $crawler = $client->request('PUT', $path);
+ $crawler = $client->request('PUT', $path, [], [], ['CONTENT_TYPE' => 'application/json']);
}
/**
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 919d30cf9a1..9d10d568921 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
@@ -136,7 +136,7 @@ class StoreApiInterfaceTest extends WebTestCase
$path = '/store/order';
- $crawler = $client->request('POST', $path);
+ $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']);
}
protected function genTestData($regexp)
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 6f2e3ba0b6c..775ec670422 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
@@ -85,7 +85,7 @@ class UserApiInterfaceTest extends WebTestCase
$path = '/user';
- $crawler = $client->request('POST', $path);
+ $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']);
}
/**
@@ -100,7 +100,7 @@ class UserApiInterfaceTest extends WebTestCase
$path = '/user/createWithArray';
- $crawler = $client->request('POST', $path);
+ $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']);
}
/**
@@ -115,7 +115,7 @@ class UserApiInterfaceTest extends WebTestCase
$path = '/user/createWithList';
- $crawler = $client->request('POST', $path);
+ $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']);
}
/**
@@ -199,7 +199,7 @@ class UserApiInterfaceTest extends WebTestCase
$data = $this->genTestData('[a-z0-9]+');
$path = str_replace($pattern, $data, $path);
- $crawler = $client->request('PUT', $path);
+ $crawler = $client->request('PUT', $path, [], [], ['CONTENT_TYPE' => 'application/json']);
}
protected function genTestData($regexp)
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
new file mode 100644
index 00000000000..e23c4afc7ca
--- /dev/null
+++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/Controller/ControllerTest.php
@@ -0,0 +1,123 @@
+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,
+ ],
+ ];
+ }
+}
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 6f8b5ca0f93..38a8370fec6 100644
--- a/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist
+++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/phpunit.xml.dist
@@ -9,12 +9,14 @@
./Tests/Api
./Tests/Model
+ ./Tests/Controller
././Api
././Model
+ ././Controller