Download the PHP package unclecheese/mock-dataobjects without Composer
On this page you can find all versions of the php package unclecheese/mock-dataobjects. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download unclecheese/mock-dataobjects
More information about unclecheese/mock-dataobjects
Files in unclecheese/mock-dataobjects
Package mock-dataobjects
Short Description Allows DataObjects to self-populate intelligently using fake data
License BSD-3-Clause
Informations about the package mock-dataobjects
Mock DataObjects for SilverStripe
This module provides intelligent content generation functionality to all DataObjects. The object introspects its fields and assigns an example value based on the field type and the name of the field. It also provides a command line utility for generating mock data programatically as well as various UI features in the CMS to support the creating and populating DataObjects.
Installation
Installation via Composer is highly recommended, as this module has external dependencies.
Example
Result:
Implementation
You can use the features of the MockDataObjects module in many ways, including executable code, a command-line interface, and from within the CMS.
From the CMS
Adding mock children to a parent page:
Right click on the parent page and choose "Add mock children."
Choose options, and create
Adding items to a grid
Just click on "add mock data" and set your options.
Populating existing records
Click on "fill with mock data"
In the execution pipeline
As demonstrated above, the ->fill() method populates a DataObject with mock data. There are a few options you can pass to this method.
From the command line
Create 50 new records. Use existing files for file relationships.
Populate existing records with new data.
Add new records to the has_many relation on a given page.
Localisation
Mock data values are localised to the current locale as defined by .
Field name hooks
For generic database fields, such as Varchar, the mock data generator is informed by the field name in order to create more realistic data. These hooks are defined in the language file.
A comma-separated list of possible field names are mapped to an entity, so that a field named "EmailAddress" or "Email" creates a fake email address, and "Phone" or "Telephone" creates a fake phone number.
An example language file for French might look like this:
Model-independent data generation
Sometimes it is useful to generate mock data before the model has been created, such as when frontend development is happening before backend development. For that purpose, every DataObject comes with a method to access the fake data generator.
Cleaning up
Records of all mockdata creation are stored in the table, which maps a record ID to a class name. You can clean this table using the task . To clear all mock data, leave the class name argument null.
Be very careful about converting mock data records into authentic records, as this task will clean them up without knowing that you have populated them with valid data!
Troubleshooting
Just ring Uncle Cheese.
All versions of mock-dataobjects with dependencies
silverstripe/cms Version ~3.1
fzaninotto/faker Version 1.1.*@dev