PHPackages                             deinternetjongens/laravel-api-factories - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. deinternetjongens/laravel-api-factories

ActiveLibrary[Testing &amp; Quality](/categories/testing)

deinternetjongens/laravel-api-factories
=======================================

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

3.0.0(1y ago)1218.5k↓31.7%1[1 PRs](https://github.com/deInternetJongens/laravel-api-factories/pulls)MITPHPPHP ^8.2CI passing

Since Jul 16Pushed 1y ago8 watchersCompare

[ Source](https://github.com/deInternetJongens/laravel-api-factories)[ Packagist](https://packagist.org/packages/deinternetjongens/laravel-api-factories)[ Docs](https://github.com/deinternetjongens/laravel-api-factories)[ RSS](/packages/deinternetjongens-laravel-api-factories/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (9)Used By (0)

[![Social Card of Laravel Api Factories](https://camo.githubusercontent.com/c0acaa68b157f930e11bffa34db8dd56847da0baaeda4d02ea1631789fe66604/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f417069253230466163746f726965732e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6465696e7465726e65746a6f6e67656e732532466c61726176656c2d6170692d666163746f72696573267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d4765742b7468652b64617461626173652b666163746f726965732b657870657269656e63652b776974682b66616b652b487474702b63616c6c2b696e2b796f75722b746573747375697465266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/c0acaa68b157f930e11bffa34db8dd56847da0baaeda4d02ea1631789fe66604/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f417069253230466163746f726965732e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6465696e7465726e65746a6f6e67656e732532466c61726176656c2d6170692d666163746f72696573267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d4765742b7468652b64617461626173652b666163746f726965732b657870657269656e63652b776974682b66616b652b487474702b63616c6c2b696e2b796f75722b746573747375697465266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

Laravel Api Factories
=====================

[](#laravel-api-factories)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5623aaa860543a9a392f75cb502dd21cdf78acd7848fdcac301a07959f4d538a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465696e7465726e65746a6f6e67656e732f6c61726176656c2d6170692d666163746f726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/deinternetjongens/laravel-api-factories)[![PHP Version Support](https://camo.githubusercontent.com/387feb1cba87dfd1ca4183f83dc64de65346a8e14d561c13427da4b23bfde496/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6465696e7465726e65746a6f6e67656e732f6c61726176656c2d6170692d666163746f726965733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/387feb1cba87dfd1ca4183f83dc64de65346a8e14d561c13427da4b23bfde496/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6465696e7465726e65746a6f6e67656e732f6c61726176656c2d6170692d666163746f726965733f7374796c653d666c61742d737175617265)[![GitHub Tests Action Status](https://camo.githubusercontent.com/df1d0916c2259d7591fcaa9a2d8c3b5c624f9900293fdb6a65e372b15ca0db0b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6465696e7465726e65746a6f6e67656e732f6c61726176656c2d6170692d666163746f726965732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/deinternetjongens/laravel-api-factories/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/97d1559f7029e8b07b160e93de5cb347284d64f241d645d19b737a1c3500cd3b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6465696e7465726e65746a6f6e67656e732f6c61726176656c2d6170692d666163746f726965732f7068702d63732d66697865722e796d6c3f6272616e63683d6d61696e266c6162656c3d436f64657374796c65267374796c653d666c61742d737175617265)](https://github.com/deinternetjongens/laravel-api-factories/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/1b6748dde34aef148008edff8eba4d6481cfedeb5eb3ca6a2c61efe1240f34d6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465696e7465726e65746a6f6e67656e732f6c61726176656c2d6170692d666163746f726965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/deinternetjongens/laravel-api-factories)

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

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require deinternetjongens/laravel-api-factories
```

Usage
-----

[](#usage)

### Generate Api factories

[](#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

[](#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
{
    protected ?string $wrapper = ResponseFactoryWrapper::class;

    /**
     * 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(),
        ];
    }
}

class ResponseFactoryWrapper extends ApiFactory
{
    protected ?string $wrapper = 'data';

    /**
     * Define the response's default state.
     *
     * @return array
     */
    public function definition(): array
    {
        return [
            'items' => $this->children(),
            'meta' => [
                'total' => rand(0, 10),
            ]
        ];
    }
}
```

### Use api factory

[](#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
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Kevin Pijning](https://github.com/kevinpijning)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance46

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 54.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~226 days

Recently: every ~266 days

Total

7

Last Release

404d ago

Major Versions

1.0.1 → 2.0.02022-05-02

2.3.0 → 3.0.02025-04-03

PHP version history (3 changes)1.0PHP ^7.4|^8.0

2.0.0PHP ^7.4|^8.0|^8.1

3.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ab892324187874b808c0bd037ff12f74fcb3257f0cf8d9723bbd30768d482ac?d=identicon)[DIJ](/maintainers/DIJ)

---

Top Contributors

[![denniseilander](https://avatars.githubusercontent.com/u/3907144?v=4)](https://github.com/denniseilander "denniseilander (12 commits)")[![kevinpijning](https://avatars.githubusercontent.com/u/2886081?v=4)](https://github.com/kevinpijning "kevinpijning (8 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")

---

Tags

laravelDIJlaravel-api-factories

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/deinternetjongens-laravel-api-factories/health.svg)

```
[![Health](https://phpackages.com/badges/deinternetjongens-laravel-api-factories/health.svg)](https://phpackages.com/packages/deinternetjongens-laravel-api-factories)
```

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-visit

Quickly visit any route of your Laravel app

15614.6k](/packages/spatie-laravel-visit)[christophrumpel/missing-livewire-assertions

This package adds missing livewire test assertions.

149336.0k9](/packages/christophrumpel-missing-livewire-assertions)[encodia/laravel-health-env-vars

Custom check for Spatie's Laravel Health - Ensure every .env variable you need has been set

20143.5k](/packages/encodia-laravel-health-env-vars)[michiruf/laravel-http-automock

Automatically mock http requests when testing

161.0k](/packages/michiruf-laravel-http-automock)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
