minicli/pest-plugin-curly

Make curl(y) requests in Pest tests
665 17
Install
composer require minicli/pest-plugin-curly
Latest Version:0.3.0
PHP:^8.2
License:MIT
Last Updated:Sep 28, 2024
Links: GitHub  ·  Packagist
Maintainer: erikaheidi

Curly Pest Plugin

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();
});

Related Packages

pestphp/pest-plugin-stressless

Stressless plugin for Pest

1,358,012 67
erikgaal/pest-plugin-sharding

Pest Plugin to split tests into multiple runs

614,369 2
lukeraymonddowning/pest-plugin-money

A Pest PHP plugin that makes testing popular Money packages easy.

69,939 21

Version History

Version Released PHP License
0.3.0 ^8.2 MIT
0.2.1 ^8.1 MIT
0.1.1 ^7.4 || ^8.0 MIT
0.1.0 ^7.3 || ^8.0 MIT