minicli / pest-plugin-curly
Make curl(y) requests in Pest tests
Fund package maintenance!
erikaheidi
Requires
- php: ^8.2
- minicli/curly: ^0.2.2
- pestphp/pest: ^3.2.0
- pestphp/pest-plugin: ^3.0.0
Requires (Dev)
- pestphp/pest-dev-tools: ^v2.6.0
This package is auto-updated.
Last update: 2024-11-28 12:30:08 UTC
README
This plugin adds basic HTTP requests functionality to Pest tests, using minicli/curly.
Installation
composer require minicli/pest-plugin-curly
Usage
The plugin exposes 3 testcase methods:
get()
matchResponse(string $endpoint, int code)
responseContains(string $endpoint, string $needle)
Examples:
<?php it('makes GET requests', function () { $this->get('https://api.github.com/rate_limit'); }); it('matches response codes', function () { $this->matchResponse('https://api.github.com/rate_limit', 200); }); it('matches strings in response body', function () { $this->responseContains('https://api.github.com/rate_limit', 'rate'); });
It also comes with a shortcut function that you can use to have access to a Curly Client instance. That is useful if you need to check more information about requests, send special headers, or if you need to perform other types of requests supported by Curly (POST and DELETE). The documentation has more info on how to use this library.
use function Minicli\PestCurlyPlugin\curly; it('makes requests using the curly() function to obtain response', function () { expect(curly()->get('https://api.github.com/rate_limit'))->toBeArray(); });