Componette

Componette

adbrosaci

adbrosaci / controller-tester v0.1.6

Simple Apitte testing with Nette\Tester.

download-cloud-line composer require adbros/controller-tester

ControllerTester

Simple Apitte Controllers testing.


Build Status 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.

withHeaders(array $headers)

Add HTTP headers.

  • v0.1.6 stable version released

bar-chart-fill

Statistics

download-cloud-fill
2179
star-fill
0
bug-fill
0
flashlight-fill
132d
price-tag-2-line

Badges

guide-fill

Dependencies

php (>=7.2)
apitte/core (^0.5 || ^0.6)
Componette Componette felix@nette.org