Download the PHP package feffel/felfactory without Composer
On this page you can find all versions of the php package feffel/felfactory. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package felfactory
felfactory
felfactory is a library that generates objects full of fake data for you. Whether you need to randomize test data, bootstrap your database, fill-in your persistence to stress test it, or anonymize data taken from a production service.
Powered by Faker's data generators.
Table of Contents
- Installation
- Basic Usage
- Configuration
- Model Definitions
- How it works
- Contributing
- License
Installation
via composer
Basic Usage
Pass a class name to your factory instance, it will create and fill properties with the appropriate type of data.
Configuration
Configuration uses enviornment variables, add these to your environment or add a .env
file to your root project dir.
Variable | Default | Description |
---|---|---|
FACTORY_MAX_NEST_LEVEL | 3 | The maximum allowed level of object nesting, any objects found after this level will be ignored and set to null |
FACTORY_CIRCLE_TOLERANCE | 1 | Circular references tolerance, default 1 does not allow the generation of any circular or self refrencing objects |
FACTORY_PHP_FILE | null | Php file path for model definitions |
FACTORY_YAML_FILE | null | Yaml file path for model definitions |
Model Definitions
You can provide model definitions to customize the generation of a model, the definition does not have to contain all of the properties, the factory will still guess the missing properties.
- Generate accepts a faker generator property [eg: firstName, lastName, phoneNumber, ...]
- Value accepts any php value and passes it down to property [eg: "string value", 15, null, ...]
- ObjectOf accepts a FQCN and generates an object of this type [eg: namespace\models\Person , Person::class, ...]
- ManyOf accepts any of the previous definitions as it's first parameter and generates an array of it bound by the inclusive range provided by it's second and third parameter.
Annotation definition
Php defintion
How it works
The factory does not use the class's original constructor, nor the provided setters if any. All of the initiation process is handled by reflections.
The factory looks for the @var
annotation on a property to determine it's type, if a definition is found for the property it will be used, otherwise it will be guessed based on type and name of the property.
Objects
If a property is found to be an object it will trigger another factory call to generate it, and the name will be ignored. Interfaces and abstract types will not be generated automatically and will be set to null.
Scalar types and Non-annotated properties
Scalar types will be guessed based on the name of the property first, if it doesn't match any of the supported data generators, it's generated based on type.
Contributing
Please see CODE_OF_CONDUCT for details.
Credits
- felfel
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of felfactory with dependencies
doctrine/annotations Version ^1.6
doctrine/lexer Version ^1.0
fzaninotto/faker Version ^1.8
mustangostang/spyc Version ^0.6.2
symfony/dotenv Version ^4.3