Skip to content

adbrosaci/controller-tester

Repository files navigation

ControllerTester

Simple Apitte Controllers testing.


main workflow Code coverage Licence Downloads this Month Downloads total Latest stable

Installation

composer require adbros/controller-tester --dev

Configuration

Just register ControllerTester in config.neon.

services:
    - Adbros\Tester\ControllerTester\ControllerTester

Usage

public function testPostHelloWorld(): void
{
    $controllerTester = $this->container->getByType(ControllerTester::class);

    $request = $controllerTester->createRequest('/api/v1/dummy/hello-world')
        ->withMethod('POST')
        ->withJsonBody([
            'foo' => 'bar',
        ]);
    $result = $controllerTester->execute($request);

    $result->assertJson([
        'status' => 'ok',
        'payload' => [
            'foo' => 'bar',
        ],
    ]);
    $result->assertStatusCode(200);
}

TestControllerRequest API

TestControllerRequest is immutable object.

withParameters(array $parameters)

Add QUERY parameters.

withMethod(string $method)

Set HTTP method. Default method is GET.

withRawBody(string $body)

Set request RAW body.

withJsonBody(array $body)

Set request JSON body.

withParsedBody(array $body)

Set POST request with parsed body like x-www-form-urlencoded.

withFile(string $name, string $filePath)

Add file - Psr7UploadedFile

withHeaders(array $headers)

Add HTTP headers.

withProtocolVersion(string $protocolVersion)

Set HTTP protocol version. Default protocol version is 1.1.

withServerParams(array $serverParams)

Add SERVER parameters.

About

Simple Apitte testing with Nette\Tester.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages