adbros / controller-tester
Simple Apitte Controllers testing.
Installs: 26 697
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=7.4
- contributte/apitte: ^0.9 | ^0.10 | ^0.11 || ^0.12
- nette/tester: ^2.0
Requires (Dev)
- contributte/qa: ^0.3.0
- contributte/tester: ^0.3.0
- nepada/phpstan-nette-tester: ^1.1
- php-parallel-lint/php-console-highlighter: ^1.0
- php-parallel-lint/php-parallel-lint: ^1.2
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.0
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-nette: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
README
Simple Apitte Controllers testing.
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.