jeroen/post-request-sender

Micro library with interface for sending post requests. Includes test doubles and adapters

2.0.0 2022-02-03 22:27 UTC

This package is auto-updated.

Last update: 2024-10-14 20:14:36 UTC


README

Build Status codecov Type Coverage Psalm level Latest Stable Version Download count

Micro library with PostRequestSender interface and some test doubles.

For the common cases where you do not need the complexity of the heavyweight libraries.

interface PostRequestSender {

	/**
	 * @param string $url
	 * @param array<string, mixed> $fields
	 */
	public function post( string $url, array $fields ): PostResponse;

}

Usage

$response = $requestSender->post( 'https://example.com', [ 'foo' => 'bar', 'baz' => 42 ] );
echo $response->body;
echo $response->statusCode;

Included implementations

Adapters

  • GuzzlePostRequestSender Adapter for Guzzle

Decorators

  • LoggingPostRequestSender Takes a Psr\Log\LoggerInterface
  • SpyPostRequestSender Test double that records calls

Test doubles

  • SpyPostRequestSender Test double that records calls
  • StubPostRequestSender Test double that returns a response provided in the constructor

Release notes

2.0.0 (2022-02-03)

  • Ditched ResponseInterface in favor of a new simple value object PostResponse

1.0.1 (2022-02-02)

  • Fixed behavior of TestResponse::getBody

1.0.0 (2022-01-30)

Initial release with

  • PostRequestSender interface
  • SpyPostRequestSender test double (and PostRequest value object)
  • StubPostRequestSender test double
  • GuzzlePostRequestSender implementation
  • LoggingPostRequestSender decorator
  • TestResponse helper implementation or PSR7 ResponseInterface