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

io.vrap.codegen.languages.php.base.PhpBaseTestFileProducer.kt Maven / Gradle / Ivy

Go to download

RAML API client code generators based on the REST Modeling Framework. https://github.com/vrapio/rest-modeling-framework

There is a newer version: 1.0.0-20241120142200
Show newest version
package io.vrap.codegen.languages.php.base

import io.vrap.codegen.languages.php.PhpSubTemplates
import io.vrap.codegen.languages.php.extensions.*
import io.vrap.rmf.codegen.di.BasePackageName
import io.vrap.rmf.codegen.io.TemplateFile
import io.vrap.rmf.codegen.rendering.FileProducer
import io.vrap.rmf.raml.model.modules.Api

class PhpBaseTestFileProducer constructor(val api: Api, @BasePackageName val packagePrefix: String) : FileProducer {

    override fun produceFiles(): List = listOf(
        apiRequestTest()
    )

    private fun apiRequestTest(): TemplateFile {
        return TemplateFile(relativePath = "test/unit/Client/ApiRequestTest.php",
                content = """
                    |createMock(ClientInterface::class);
                    |        $!request = new ApiRequest($!client, 'get', '/');
                    |        $!request = $!request->withQueryParam('foo', 'bar');
                    |        $!this->assertSame('foo=bar', $!request->getUri()->getQuery());
                    |        $!request = $!request->withQueryParam('foo', 'baz');
                    |        $!this->assertSame('foo=bar&foo=baz', $!request->getUri()->getQuery());
                    |        $!request = $!request->withQueryParam('bar', 'foo');
                    |        $!this->assertSame('bar=foo&foo=bar&foo=baz', $!request->getUri()->getQuery());
                    |        $!request = $!request->withQueryParam('bar', 'baz');
                    |        $!this->assertSame('bar=foo&bar=baz&foo=bar&foo=baz', $!request->getUri()->getQuery());
                    |    }
                    |
                    |    public function testWithQueryParamArray()
                    |    {
                    |        $!client = $!this->createMock(ClientInterface::class);
                    |        $!request = new ApiRequest($!client, 'get', '/');
                    |        $!request = $!request->withQueryParam('foo', ['bar']);
                    |        $!this->assertSame('foo=bar', $!request->getUri()->getQuery());
                    |        $!request = $!request->withQueryParam('foo', 'baz');
                    |        $!this->assertSame('foo=bar&foo=baz', $!request->getUri()->getQuery());
                    |        $!request = $!request->withQueryParam('bar', ['foo', 'baz']);
                    |        $!this->assertSame('bar=foo&bar=baz&foo=bar&foo=baz', $!request->getUri()->getQuery());
                    |    }
                    |
                    |    public function testContentTypeHeader()
                    |    {
                    |        $!client = $!this->createMock(ClientInterface::class);
                    |        $!request = new ApiRequest($!client, 'get', '/');
                    |        $!this->assertSame('application/json', $!request->getHeaderLine('content-type'));
                    |    }
                    |
                    |    public function testEnsureHeaders()
                    |    {
                    |        $!client = $!this->createMock(ClientInterface::class);
                    |        $!request = new ApiRequest($!client, 'get', '/', ['X-Foo' => 'bar']);
                    |        $!this->assertSame('application/json', $!request->getHeaderLine('content-type'));
                    |        $!this->assertSame('bar', $!request->getHeaderLine('x-foo'));
                    |    }
                    |}
                """.trimMargin().forcedLiteralEscape()
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy