This package provides the database factory experience to fake Http calls in your testsuite.

Overview

Social Card of Laravel Api Factories

Laravel Api Factories

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides the database factory experience to fake Http calls in your testsuite

Installation

You can install the package via composer:

composer require deinternetjongens/laravel-api-factories

Usage

Generate Api factories

php artisan make:api-factory NewsPostResponse

The new api factory class will be placed in your tests/Factories directory.

Configure api factory

The api factories look moslty the same as the Laravel database factories, except it extend the ApiFactory class and you don't need to specify a model.

namespace Tests\Factories;

use DIJ\ApiFactories\ApiFactory;

class NewsPostResponseFactory extends ApiFactory
{
    /**
     * Define the response's default state.
     *
     * @return array
     */
    public function definition(): array
    {
        return [
            'title' => $this->faker->title,
            'intro' => $this->faker->paragraph(),
            'article' => $this->faker->paragraphs(4),
            'author' => $this->faker->name,
            'likes' => $this->faker->randomNumber(2),
            'published_at' => $this->faker->dateTime(),
        ];
    }
}

Use api factory

use \Illuminate\Support\Facades\Http;

$response = NewsPostResponseFactory::new()
    ->state(new Sequence(
        ['author' => 'Taylor'],
        ['author' => 'Mohammed'],
        ['author' => 'Dries']
    ))
    ->count(15)
    ->make();

Http::fakeSequence()->push($response);

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
Opsie Operator is a CLI to check your website for HTTP downtime.

Opsie Operator Monitor any website. Run in Docker or any Kubernetes cluster. Send webhooks. 🤝 Supporting If you are using one or more Renoki Co. open

 Just HTTP Status Codes is a great way to empower your project with clean practice 💫
Just HTTP Status Codes is a great way to empower your project with clean practice 💫

The Simplest & Cleanest HTTP Status Codes for PHP. All PHP HTTP Status Codes are stored into beautiful constant names 🎨 Ideal when you develop an API that involves various HTTP codes 🚀

Guzzle, an extensible PHP HTTP client
Guzzle, an extensible PHP HTTP client

Guzzle, PHP HTTP client Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interf

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.

Httpful Httpful is a simple Http Client library for PHP 7.2+. There is an emphasis of readability, simplicity, and flexibility – basically provide the

PHP's lightweight HTTP client

Buzz - Scripted HTTP browser Buzz is a lightweight (1000 lines of code) PHP 7.1 library for issuing HTTP requests. The library includes three clients

HTTPlug, the HTTP client abstraction for PHP

HTTPlug HTTPlug, the HTTP client abstraction for PHP. Intro HTTP client standard built on PSR-7 HTTP messages. The HTTPlug client interface is compati

PSR-7 HTTP Message implementation

zend-diactoros Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-diactoros. Master: Develop: Diactoros (pronunciation: /dɪʌ

PSR HTTP Message implementations

laminas-diactoros Diactoros (pronunciation: /dɪʌktɒrɒs/): an epithet for Hermes, meaning literally, "the messenger." This package supercedes and repla

Unirest in PHP: Simplified, lightweight HTTP client library.

Unirest for PHP Unirest is a set of lightweight HTTP libraries available in multiple languages, built and maintained by Mashape, who also maintain the

Releases(2.0.0)
  • 2.0.0(May 2, 2022)

    What's Changed

    • Add support for Laravel 9.x by @denniseilander in https://github.com/deInternetJongens/laravel-api-factories/pull/1

    New Contributors

    • @denniseilander made their first contribution in https://github.com/deInternetJongens/laravel-api-factories/pull/1

    Full Changelog: https://github.com/deInternetJongens/laravel-api-factories/compare/1.0.1...2.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
DIJ
Dedicated Digital Development Teams
DIJ
Declarative HTTP Clients using Guzzle HTTP Library and PHP 8 Attributes

Waffler How to install? $ composer require waffler/waffler This package requires PHP 8 or above. How to test? $ composer phpunit Quick start For our e

Waffler 3 Aug 26, 2022
The HttpClient component provides powerful methods to fetch HTTP resources synchronously or asynchronously.

HttpClient component The HttpClient component provides powerful methods to fetch HTTP resources synchronously or asynchronously. Resources Documentati

Symfony 1.7k Jan 6, 2023
Provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests

laminas-http provides the HTTP message abstraction used by laminas-mvc, and also provides an extensible, adapter-driven HTTP client library.

Laminas Project 33 Aug 27, 2022
🐼 Framework agnostic package using asynchronous HTTP requests and PHP generators to load paginated items of JSON APIs into Laravel lazy collections.

Framework agnostic package using asynchronous HTTP requests and generators to load paginated items of JSON APIs into Laravel lazy collections.

Andrea Marco Sartori 61 Dec 3, 2022
Composer package providing HTTP Methods, Status Codes and Reason Phrases for PHP

HTTP Enums For PHP 8.1 and above This package provides HTTP Methods, Status Codes and Reason Phrases as PHP 8.1+ enums All IANA registered HTTP Status

Alexander Pas 72 Dec 23, 2022
Zenscrape package is a simple PHP HTTP client-provider that makes it easy to parsing site-pages

Zenscrape package is a simple PHP HTTP client-provider that makes it easy to parsing site-pages

Andrei 3 Jan 17, 2022
PHP Curl - This package can send HTTP requests to a given site using Curl.

PHP Curl This package can send HTTP requests to a given site using Curl. It provides functions that can take several types of parameters to configure

Mehmet Can 1 Oct 27, 2022
Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

null 3.5k Dec 31, 2022
Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.

This is a port of the VCR Ruby library to PHP. Record your test suite's HTTP interactions and replay them during future test runs for fast, determinis

php-vcr 1.1k Dec 23, 2022
Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

null 3.5k Dec 31, 2022