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

php-symfony.testing.api_test.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 {{apiTestsPackage}};

use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
 * {{classname}}Test Class Doc Comment
 *
 * @category Class
 * @package  {{apiTestsPackage}}
 * @author   openapi-generator contributors
 * @link     https://github.com/openapitools/openapi-generator
 * @coversDefaultClass \{{apiPackage}}\{{classname}}
 */
{{#operations}}class {{classname}}Test extends WebTestCase
{
    private static ?KernelBrowser $client = null;

    /**
     * Setup before running any test cases
     */
    public static function setUpBeforeClass(): void
    {
    }

    /**
     * Setup before running each test case
     */
    public function setUp(): void
    {
        if (null === self::$client) {
            self::$client = static::createClient();
        }
    }

    /**
     * Clean up after running each test case
     */
    public function tearDown(): void
    {
        static::ensureKernelShutdown();
    }

    /**
     * Clean up after running all test cases
     */
    public static function tearDownAfterClass(): void
    {
    }
    {{#operation}}

    /**
     * Test case for {{{operationId}}}
     *
     * {{{summary}}}.
     *
     */
    public function test{{operationIdCamelCase}}(): void
    {
        $client = self::$client;

        $path = '{{path}}';
        {{#pathParams}}
        {{=<% %>=}}
        $pattern = '{<%paramName%>}';
        <%={{ }}=%>
        {{#pattern}}
        $data = $this->genTestData('{{.}}');
        {{/pattern}}
        {{^pattern}}
        {{#isLong}}
        $data = $this->genTestData('\d+');
        {{/isLong}}
        {{#isInteger}}
        $data = $this->genTestData('\d+');
        {{/isInteger}}
        {{#isString}}
        $data = $this->genTestData('[a-z0-9]+');
        {{/isString}}
        {{#isBoolean}}
        $data = $this->genTestData('true|false');
        {{/isBoolean}}
        {{/pattern}}
        $path = str_replace($pattern, $data, $path);
        {{/pathParams}}

        $crawler = $client->request('{{httpMethod}}', $path{{#hasBodyParam}}, [], [], ['CONTENT_TYPE' => 'application/json']{{/hasBodyParam}});
        $this->markTestSkipped('Test for {{operationId}} not implemented');
    }
    {{/operation}}

    /**
     * @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);
        $ast      = $compiler->parse($regexp);
        $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random());

        return $generator->visit($ast);
    }
}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy