New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

apie/faker

Composer package of the apie library: faker
7,385

Larablocks Analysis

apie/faker works with any PHP project: the latest release (1.0.0-RC2, Mar 18, 2025) doesn't depend on Laravel.

Recommendation checks

Use with care

Use with care: meets 0 of 3 checks.

  • No release in the last 12 months (last: Mar 18, 2025)
  • 306 downloads a month (needs 10,000)
  • 0 GitHub stars (needs 100)

State

Quiet
  • Last release (pre-release): Mar 18, 2025.
  • No releases in the last 12 months.
  • First released: Mar 18, 2025.
  • Monthly downloads: 306.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 30, 2026.

Install
composer require apie/faker:1.0.0-RC2
Latest Version:1.0.0-RC2
PHP:>=8.3
License:MIT
Last Updated:Nov 20, 2026
Links: GitHub  ·  Packagist
Maintainer: pjordaan

faker

Latest Stable Version Total Downloads Latest Unstable Version License PHP Composer

PHP Composer

This package is part of the Apie library. The code is maintained in a monorepo, so PR's need to be sent to the monorepo

Documentation

This package adds a method to the library Faker to fake domain object and value object contents.

Because of the recursive nature this is the easiest setup:

<?php
use Apie\Faker\ApieObjectFaker;
use Faker\Factory;

$faker = Factory::create();
$faker->addProvider(ApieObjectFaker::createWithDefaultFakers($faker));

// returns a random Gender enum value.
$faker->fakeClass(Gender::class);

class User implements EntityInterface
{
    // ...
    public function __construct(private Gender $gender, private FirstName $firstName, private LastName $lastName)
    {
    }
}
// creates a User with random constructor arguments.
$faker->fakeClass(User::class);

String value objects with regular expressions.

String value objects that have the trait IsStringWithRegexValueObject and implement HasRegexValueObjectInterface will be faked easily by using the regular expression to make a valid value object.

Adding custom support

You can create a class implementing ApieClassFaker to make your own fake methods. You can reuse the methods available in Faker itself.

<?php
use Apie\Faker\Interfaces\ApieClassFaker;
use Faker\Generator;
use ReflectionClass;

class SpecificClassFaker implements ApieClassFaker
{
    public function supports(ReflectionClass $class): bool
    {
        return $class->name === SpecificValueObject::class;
    }
    public function fakeFor(Generator $generator, ReflectionClass $class): SpecificValueObject
    {
        return new SpecificValueObject($generator->randomElement([1, 2, 3]));
    }
}

Adding a createRandom method in the object itself.

Instead of making many ApieClassFaker methods you can make a method on the value object that will result in a random value object.

<?php
use Apie\Core\Attributes\FakeMethod;
use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface;

#[FakeMethod("createRandom")]
class SpecificClass implements ValueObjectInterface
{
    public static function createRandom(): self
    {
        return new self(rand(1, 3));
    }
}

You can also provide arguments to this method or the Faker generator itself:

<?php
use Apie\Core\Attributes\FakeMethod;
use Apie\Core\ValueObjects\Interfaces\ValueObjectInterface;
use Faker\Generator;

#[FakeMethod("createRandom")]
class SpecificClass implements ValueObjectInterface
{
    public static function createRandom(Generator $generator, int $maximum): self
    {
        return new self($generator->numberBetween(1, $maximum));
    }
}

In this case calling $faker->fakeClass(SpecificClass::class); will run SpecificClass::createRandom() with the faker and a random integer.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

670,032,257 9,703
laravel/framework

The Laravel Framework.

640,572,096 35,338
laravel/tinker

Powerful REPL for the Laravel framework.

546,909,908 7,440
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

465,816,364 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

431,187,642 4,660

Version History

Pre-releases (1)
Version Released PHP License
1.0.0-RC2 >=8.3 MIT