PHPackages                             invertus/prestashop-models - 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. invertus/prestashop-models

ActiveLibrary

invertus/prestashop-models
==========================

This package provides ability to test your database driven applications. Model factories make it easier to create test database records using Prestashop models.

1.0.4(2y ago)124.1k↓32.8%MITPHPPHP &gt;=5.6.0

Since Jul 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/tomjas1997/prestashop-model-factory)[ Packagist](https://packagist.org/packages/invertus/prestashop-models)[ RSS](/packages/invertus-prestashop-models/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

Introduction
------------

[](#introduction)

This package provides ability to test your database driven applications. Model factories make it easier to create test database records using Prestashop models.

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

[](#installation)

Require this package with composer. It is recommended to only require the package for development.

```
composer require invertus/prestashop-models --dev
```

Defining Model Factories
------------------------

[](#defining-model-factories)

### Concept Overview

[](#concept-overview)

When testing, you may need to insert a few records into your database before executing your test. Instead of manually specifying the value of each column when you create this test data, this package allows you to define a set of default attributes for each of your Prestashop models using model factories.

To see an example of how to write a factory, take a look at the `tests/Factories/Models/UserFactory.php` file in your application.

```
namespace Tests\Factories\Models;

use Invertus\Prestashop\Models\Factory\Factory;
use Customer;

class CustomerFactory extends Factory
{
    protected $model = Customer::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'name' => $this->faker->name(),
            'email' => $this->faker->unique()->safeEmail(),
            'email_verified_at' => now(),
            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
        ];
    }
}

```

`

As you can see, in their most basic form, factories are classes that extend this package's base factory class and define `definition` method. The `definition` method returns the default set of attribute values that should be applied when creating a model using the factory.

Via the `faker` property, factories have access to the [Faker](https://github.com/FakerPHP/Faker) PHP library, which allows you to conveniently generate various kinds of random data for testing.

> {tip} You can override faker by overriding withFaker() function in Factory class.

### Generating Factories

[](#generating-factories)

To create a factory, execute the `make:factory`:

```
php vendor/bin/prestashop-models make:factory ProductFactory

```

To create a factory with specific different name than {model}Factory execute this command:

```
php vendor/bin/prestashop-models make:factory TestProductFactory --model="\Product"

```

**--model should have full namespace to model.**

The new factory class will be placed in your `tests/Factories/Models` directory.

### Factory States

[](#factory-states)

State manipulation methods allow you to define discrete modifications that can be applied to your model factories in any combination. For example, your `Tests\Factories\Models\CustomerFactory` factory might contain a `suspended` state method that modifies one of its default attribute values.

State transformation methods typically call the `state` method provided by package's base factory class. The `state` method accepts a closure which will receive the array of raw attributes defined for the factory and should return an array of attributes to modify:

```
/**
 * Indicate that the customer is suspended.
 *
 * @return self
 */
public function suspended()
{
    return $this->state(function (array $attributes) {
        return [
            'account_status' => 'suspended',
        ];
    });
}

```

### Factory Callbacks

[](#factory-callbacks)

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

```
namespace Tests\Factories\Models;

use Invertus\Prestashop\Models\Factory\Factory;
use Customer;

class CustomerFactory extends Factory
{
    /**
     * Configure the model factory.
     *
     * @return $this
     */
    public function configure()
    {
        return $this->afterMaking(function (Customer $customer) {
            //
        })->afterCreating(function (Customer $customer) {
            //
        });
    }

    // ...
}

```

Creating Models Using Factories
-------------------------------

[](#creating-models-using-factories)

### Instantiating Models

[](#instantiating-models)

Once you have defined your factories, you may use the static `factory` method provided to your models by the `Illuminate\Database\Eloquent\Factories\HasFactory` trait in order to instantiate a factory instance for that model. Let's take a look at a few examples of creating models. First, we'll use the `make` method to create models without persisting them to the database:

```
use Tests\Factories\Models\CustomerFactory;

public function test_models_can_be_instantiated()
{
    $customer = CustomerFactory::initialize()->make();

    // Use model in tests...
}

```

You may create a collection of many models using the `count` method:

```
$customers = CustomerFactory::initialize()->count(3)->make();

```

#### Applying States

[](#applying-states)

You may also apply any of your states to the models. If you would like to apply multiple state transformations to the models, you may simply call the state transformation methods directly:

```
$customers = CustomerFactory::initialize()->count(5)->suspended()->make();

```

#### Overriding Attributes

[](#overriding-attributes)

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

```
$customer = CustomerFactory::initialize()->make([
    'name' => 'Abigail Otwell',
]);

```

### Persisting Models

[](#persisting-models)

The `create` method instantiates model instances and persists them to the database using model's `save` method:

```
use Tests\Factories\Models\CustomerFactory;

public function test_models_can_be_persisted()
{
    // Create a single App\Models\User instance...
    $customer = CustomerFactory::initialize()->create();

    // Create three App\Models\User instances...
    $customers = CustomerFactory::initialize()->count(3)->create();

    // Use model in tests...
}

```

You may override the factory's default model attributes by passing an array of attributes to the `create` method:

```
$customer = CustomerFactory::initialize()->create([
    'name' => 'Abigail',
]);

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~101 days

Total

5

Last Release

983d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/72136043?v=4)[Tomas J.](/maintainers/tomjas1997)[@tomjas1997](https://github.com/tomjas1997)

---

Top Contributors

[![tomjas1997](https://avatars.githubusercontent.com/u/72136043?v=4)](https://github.com/tomjas1997 "tomjas1997 (29 commits)")

### Embed Badge

![Health badge](/badges/invertus-prestashop-models/health.svg)

```
[![Health](https://phpackages.com/badges/invertus-prestashop-models/health.svg)](https://phpackages.com/packages/invertus-prestashop-models)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[phan/phan

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k15.7k5](/packages/elgg-elgg)[webfactory/slimdump

slimdump is a little tool to help you creating dumps of large MySQL-databases.

188124.8k1](/packages/webfactory-slimdump)[worksome/foggy

Foggy is a tool for making database dumps with some data removed/changed.

26571.7k1](/packages/worksome-foggy)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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