PHPackages                             lukeraymonddowning/poser - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. lukeraymonddowning/poser

AbandonedArchivedPackage[Utility &amp; Helpers](/categories/utility)

lukeraymonddowning/poser
========================

A description for poser.

4.2.0(5y ago)28556.3k↑66.7%10[2 issues](https://github.com/lukeraymonddowning/poser/issues)MITPHP

Since Mar 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/lukeraymonddowning/poser)[ Packagist](https://packagist.org/packages/lukeraymonddowning/poser)[ RSS](/packages/lukeraymonddowning-poser/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (5)Versions (38)Used By (0)

[![](https://github.com/lukeraymonddowning/poser/raw/master/poser-logo.png)](https://github.com/lukeraymonddowning/poser/raw/master/poser-logo.png)

Poser
=====

[](#poser)

[![All Contributors](https://camo.githubusercontent.com/9542ea950e7f95d9eb2bc35a8fa65df66564c5bd447af296074e036652f5cd5a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f616c6c5f636f6e7472696275746f72732d31302d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](#contributors-)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Laravel Class-based Model Factories in literal seconds! Write tests that look as sexy as this...

```
/** @test */
public function a_user_can_have_customers()
{
    UserFactory::times(20)
               ->hasAddress()
               ->withCustomers(CustomerFactory::times(20)->withBooks(5))();

    $this->assertCount(20 * 20 * 5, Book::all());
}
```

...with a Factory that looks like this...

```
namespace Tests\Factories;

use Lukeraymonddowning\Poser\Factory;

class UserFactory extends Factory {

    // No need to write any code here

}
```

Note for Laravel 8 users
------------------------

[](#note-for-laravel-8-users)

Whilst Poser is tagged for Laravel 8, you should start migrating to use Laravel's new built in class based factories. The syntax is nearly identical and you'll pick it up in no time. I want to thank everybody who used, tested, altered and discussed Poser. Its been so much fun to build something to the Laravel community!

Examples
--------

[](#examples)

Want to see what Poser looks like compared with the default Laravel tests? [Check out our examples!](#before-and-after-examples)

Install
-------

[](#install)

First, install into your Laravel project using composer.

`composer require lukeraymonddowning/poser`

Next, publish the Poser config file by calling

`php artisan vendor:publish --tag=poser`

**Lumen Installation**

Create the `poser.php` in your config directory and copy the `lukeraymonddowning/poser/src/config/poser.php` into it

Add `$app->configure('poser');` to the config section in `boostrap/app.php`

Add `$app->register(\Lukeraymonddowning\Poser\PoserServiceProvider::class);` to the providers section in `boostrap/app.php`

**Getting Started**

To get started quickly, we provide a `php artisan make:poser` command. You may pass the desired name of your factory as an argument. So the command to create the `UserFactory` would be `php artisan make:poser UserFactory`.

If you want to let Poser do all of the work, simply call `php artisan make:poser` to turn all the models defined in your `poser.models_namespace` config entry into Poser Factories.

More of a visual person? [Watch this video demonstration of Poser](https://vimeo.com/395500107)

Usage
-----

[](#usage)

Poser takes all of the boilerplate out of writing [class-based model factories](https://tighten.co/blog/tidy-up-your-tests-with-class-based-model-factories). To get started, install Poser and go to your test suite. Please note: Poser uses the database (obviously), so make sure your test class extends Laravel's TestCase, not PhpUnit's.

### The Basics

[](#the-basics)

Let's imagine you have a user model that has many customers...

```
