Download the PHP package directorytree/dummy without Composer

On this page you can find all versions of the php package directorytree/dummy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dummy

Generate PHP class instances populated with fake dummy data using Faker


Index

Requirements

Installation

You can install the package via composer:

Upgrading

From v1 to v2

Dummy v2 renames the trait API so it is explicitly Dummy-owned and does not reserve the common factory() method name on your classes.

  1. Replace DirectoryTree\Dummy\HasFactory with DirectoryTree\Dummy\HasDummyFactory.
  2. Replace use HasFactory; with use HasDummyFactory;.
  3. Replace YourClass::factory() calls with YourClass::dummy().
  4. Rename toFactoryInstance to toDummyInstance.
  5. Rename getFactoryDefinition to getDummyDefinition.
  6. Change the toDummyInstance argument from array to DirectoryTree\Dummy\DummyData.

Before:

After:

If your constructor or factory method needs a plain array, call all():

You can also replace manual array access with helper methods where useful:

State callbacks, attribute closures, raw(), and custom Factory::generate(array $attributes) methods continue to receive plain arrays.

Introduction

Consider you have a class representing a restaurant reservation:

To make dummy instances of this class during testing, you have to manually populate it with dummy data.

This can quickly get out of hand as your class grows, and you may find yourself writing the same dummy data generation code over and over again.

Dummy provides you with a simple way to generate dummy instances of your classes using a simple API:

Setup

Dummy provides you two different ways to generate classes with dummy data.

HasDummyFactory Trait

The HasDummyFactory trait is applied directly to the class you would like to generate dummy instances of.

To use the HasDummyFactory trait, you must implement the toDummyInstance and getDummyDefinition methods:

The $attributes argument passed into toDummyInstance is a DirectoryTree\Dummy\DummyData instance. It supports array access and common data helpers, such as get, has, filled, notFilled, boolean, integer, enum, enums, only, except, collect, and all.

Once implemented, you may call the Reservation::dummy() method to create a new dummy factory:

Dynamic State Methods

The HasDummyFactory trait supports defining dynamic state methods. You can define state methods in your class using the format get{StateName}State and call them dynamically on the factory:

You can then use these state methods dynamically:

Class Factory

If you need more control over the dummy data generation process, you may use the Factory class.

The Factory class is used to generate dummy instances of a class using a separate factory class definition.

To use the Factory class, you must extend it with your own and override the definition and generate methods:

Usage

Once you've defined a factory, you can generate dummy instances of your class using the make method:

To add or override attributes in your definition, you may pass an array of attributes to the make method:

To generate multiple instances of the class, you may use the count method:

This will return an Illuminate\Support\Collection instance containing the generated classes.

If you have a counted factory but need one instance, use makeOne:

To make several instances with a different state record for each one, use makeMany:

You may also defer generation by creating a lazy callback:

Factory States

State manipulation methods allow you to define discrete modifications that can be applied to your dummy factories in any combination.

For example, your App\Factories\Reservation factory might contain a tomorrow state method that modifies one of its default attribute values:

You may prepend a state when you need it evaluated before the factory's existing states:

Eloquent Attributes

When Laravel's Eloquent is installed, Dummy will expand Eloquent model instances and factories into model keys:

This also works for values returned from attribute closures, so dependent attributes can use previously expanded keys:

Factory Callbacks

Factory callbacks are registered using the afterMaking method and allow you to perform additional tasks after making or creating a class. You should register these callbacks by defining a configure method on your factory class. This method will be automatically called when the factory is instantiated:

You may remove configured afterMaking callbacks for a single factory chain with withoutAfterMaking:

Factory Sequences

Sometimes you may wish to alternate the value of a given attribute for each generated class.

You may accomplish this by defining a state transformation as a sequence:

Factory Collections

By default, when making more than one dummy class, an instance of Illuminate\Support\Collection will be returned.

If you need to customize the collection of classes generated by a factory, you may override the collect method:

Factory Macros

Factories are macroable, allowing you to register reusable factory helpers:

IDE Type Inference

Dummy includes generic PHPDoc annotations so static analysis tools and IDEs can infer factory return types.

When using the HasDummyFactory trait, add an @use annotation to your class:

When using a dedicated factory class, add an @extends annotation:

These annotations allow tools to infer that Reservation::dummy()->makeOne() and ReservationFactory::new()->makeOne() return a Reservation instance.


All versions of dummy with dependencies

PHP Build Version
Package Version
Requires fakerphp/faker Version ^1.0
illuminate/collections Version ^9.0|^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package directorytree/dummy contains the following files

Loading the files please wait ...