Download the PHP package analogue/factory without Composer

On this page you can find all versions of the php package analogue/factory. 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 factory

Analogue ORM - Entity Factory

This package adds support the laravel's Model Factory' functionnality to the Analogue datamapper ORM.

Installation

Add this line to your composer.json file :

Configuration

Add the Service Provider to config/app.php :

Usage

Analogue Factory uses the same definitions mechanism Eloquent's does. Out of the box, this file provided with the default Laravel's install contains one factory definition:

$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->email,
        'password' => bcrypt(str_random(10)),
        'remember_token' => str_random(10),
    ];
});

Within the Closure, which serves as the factory definition, you may return the default test values of all attributes on the model. The Closure will receive an instance of the Faker PHP library, which allows you to conveniently generate various kinds of random data for testing.

Of course, you are free to add your own additional factories to the ModelFactory.php file.

Multiple Factory Types

Sometimes you may wish to have multiple factories for the same Analogue Entity class. For example, perhaps you would like to have a factory for "Administrator" users in addition to normal users. You may define these factories using the defineAs method:

$factory->defineAs(App\User::class, 'admin', function ($faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->email,
        'password' => str_random(10),
        'remember_token' => str_random(10),
        'admin' => true,
    ];
});

Instead of duplicating all of the attributes from your base user factory, you may use the raw method to retrieve the base attributes. Once you have the attributes, simply supplement them with any additional values you require:

$factory->defineAs(App\User::class, 'admin', function ($faker) use ($factory) {
    $user = $factory->raw(App\User::class);

    return array_merge($user, ['admin' => true]);
});

Using Factories In Tests

Once you have defined your factories, you may use them in your tests or database seed files to generate model instances using the global analogue_factory function. So, let's take a look at a few examples of creating models. First, we'll use the make method, which creates models but does not save them to the database:

public function testDatabase()
{
    $user = analogue_factory(App\User::class)->make();

    // Use entity in tests...
}

If you would like to override some of the default values of your entities, you may pass an array of values to the make method. Only the specified values will be replaced while the rest of the values remain set to their default values as specified by the factory:

$user = analogue_factory(App\User::class)->make([
    'name' => 'Abigail',
   ]);

You may also create a Collection of many models or create models of a given type:

// Create three App\User instances...
$users = analogue_factory(App\User::class, 3)->make();

// Create an App\User "admin" instance...
$user = analogue_factory(App\User::class, 'admin')->make();

// Create three App\User "admin" instances...
$users = analogue_factory(App\User::class, 'admin', 3)->make();

Persisting Factory Entities

The create method not only creates the model instances, but also saves them to the database using Analogue's Mapper store() method.

public function testDatabase()
{
    $user = analogue_factory(App\User::class)->create();

    // Use entity in tests...
}

Again, you may override attributes on the model by passing an array to the create method:

$user = analogue_factory(App\User::class)->create([
    'name' => 'Abigail',
   ]);

Building complex Entities

By recursively calling the analogue_factory function, you can generate complex Entities very easily :

$factory->define(App\Post::class, function (Faker\Generator $faker) {
    return [
        'title' => $faker->sentence,
        'content' => $faker->text,
    ];
});

$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'posts' => analogue_factory(App\Post::class, 10),
    ];
});

You can even persist these complex entities with a single call :

$users = analogue_factory(App\User::class, 3)->create();

All versions of factory with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
illuminate/support Version >=5.6.12
illuminate/database Version >=5.6.12
fzaninotto/faker Version ~1.4
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 analogue/factory contains the following files

Loading the files please wait ....