minicli/pest-plugin-curly

Make curl(y) requests in Pest tests

Fund package maintenance!
erikaheidi

0.3.0 2024-09-28 12:11 UTC

This package is auto-updated.

Last update: 2024-10-28 12:15:46 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();
});