All Downloads are FREE. Search and download functionalities are using the official Maven repository.

php-symfony.testing.ControllerTest.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
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.
     *
     * @covers ::isContentTypeAllowed
     * @dataProvider dataProviderIsContentTypeAllowed
     */
    public function testIsContentTypeAllowed(?string $contentType, array $consumes, bool $expectedReturn): void
    {
        $request = new Request();
        $request->headers->set('CONTENT_TYPE', $contentType);// 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 dataProviderIsContentTypeAllowed(): array
    {
        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,
            ],
        ];
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy