PHPackages                             unclecheese/mock-dataobjects - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. unclecheese/mock-dataobjects

ActiveSilverstripe-module[Testing &amp; Quality](/categories/testing)

unclecheese/mock-dataobjects
============================

Allows DataObjects to self-populate intelligently using fake data

1.1.0(8y ago)183.7k8[5 issues](https://github.com/unclecheese/silverstripe-mock-dataobjects/issues)[4 PRs](https://github.com/unclecheese/silverstripe-mock-dataobjects/pulls)BSD-3-ClausePHP

Since Nov 8Pushed 5y ago6 watchersCompare

[ Source](https://github.com/unclecheese/silverstripe-mock-dataobjects)[ Packagist](https://packagist.org/packages/unclecheese/mock-dataobjects)[ RSS](/packages/unclecheese-mock-dataobjects/feed)WikiDiscussions master Synced 2d ago

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

Mock DataObjects for SilverStripe
=================================

[](#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)

Installation via Composer is highly recommended, as this module has external dependencies.

```
composer require unclecheese/mock-dataobjects:dev-master

```

Example
-------

[](#example)

```
class StaffMember extends DataObject {

	private static $db = array (
		'FirstName' => 'Varchar(255)',
		'LastName' => 'Varchar(255)',
		'EmailAddress' => 'Varchar(255)',
		'Address' => 'Varchar(255)',
		'City' => 'Varchar(255)',
		'PostalCode' => 'Varchar(255)',
		'Country' => 'Varchar(255)',
		'Company' => 'Varchar(255)',
		'Website' => 'Varchar(255)',
		'PhoneNumber' => 'Varchar(255)',
	);

	private static $has_one = array (
		'Photo' => 'Image',
		'StaffHolder' => 'StaffHolder',
	);
}
```

```
$staff = new StaffMember();
$staff->fill();
```

Result:

[![Screenshot](https://camo.githubusercontent.com/ec58753339adadbbd8c07dea3ac0768a633735bd46c4da576c47f5e0883b15d1/687474703a2f2f692e6375626575706c6f61642e636f6d2f62764d7634322e706e67)](https://camo.githubusercontent.com/ec58753339adadbbd8c07dea3ac0768a633735bd46c4da576c47f5e0883b15d1/687474703a2f2f692e6375626575706c6f61642e636f6d2f62764d7634322e706e67)

Implementation
--------------

[](#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

[](#from-the-cms)

#### Adding mock children to a parent page:

[](#adding-mock-children-to-a-parent-page)

Right click on the parent page and choose "Add mock children."

[![Screenshot](https://camo.githubusercontent.com/c57fc3cc7a0c4202db48119383c7e7b81619cdabfd0075e9928385af7f0096f6/687474703a2f2f692e6375626575706c6f61642e636f6d2f4631324744662e706e67)](https://camo.githubusercontent.com/c57fc3cc7a0c4202db48119383c7e7b81619cdabfd0075e9928385af7f0096f6/687474703a2f2f692e6375626575706c6f61642e636f6d2f4631324744662e706e67)

Choose options, and create

[![Screenshot](https://camo.githubusercontent.com/83ffdd388cd9fdc0e5a15902d7a735b116520393bc26975971f110c9301f7bd5/687474703a2f2f692e6375626575706c6f61642e636f6d2f66304a615a572e706e67)](https://camo.githubusercontent.com/83ffdd388cd9fdc0e5a15902d7a735b116520393bc26975971f110c9301f7bd5/687474703a2f2f692e6375626575706c6f61642e636f6d2f66304a615a572e706e67)

#### Adding items to a grid

[](#adding-items-to-a-grid)

Just click on "add mock data" and set your options.

[![Screenshot](https://camo.githubusercontent.com/1d2a67865fcc979582df72e5bbd803e32a4ed11c54d0ef15e51681a0637b7ab4/687474703a2f2f692e6375626575706c6f61642e636f6d2f4d4b304c4d6a2e706e67)](https://camo.githubusercontent.com/1d2a67865fcc979582df72e5bbd803e32a4ed11c54d0ef15e51681a0637b7ab4/687474703a2f2f692e6375626575706c6f61642e636f6d2f4d4b304c4d6a2e706e67)

#### Populating existing records

[](#populating-existing-records)

Click on "fill with mock data"

[![Screenshot](https://camo.githubusercontent.com/7e1b61033a8365edfa5e1f2f30d032ecede578e577247bb4022ac6bd88e18c70/687474703a2f2f692e6375626575706c6f61642e636f6d2f5a4b6e5566612e706e67)](https://camo.githubusercontent.com/7e1b61033a8365edfa5e1f2f30d032ecede578e577247bb4022ac6bd88e18c70/687474703a2f2f692e6375626575706c6f61642e636f6d2f5a4b6e5566612e706e67)

### In the execution pipeline

[](#in-the-execution-pipeline)

```
$myDataObject->fill();
```

As demonstrated above, the -&gt;fill() method populates a DataObject with mock data. There are a few options you can pass to this method.

```
$myDataObject->fill(array(
	 'only_empty' => true, // only fill in empty fields
	 'include_relations' => true, // Include has_many and many_many relations
	 'relation_create_limit' => 5, // If no existing records for many_many or has_one relations, limit creation
	 'download_images' => false, // Don't download images from the web. Use existing.
));
```

### From the command line

[](#from-the-command-line)

Create 50 new records. Use existing files for file relationships.

```
mockdata generate Product -count 50 --no-downloads

```

Populate existing records with new data.

```
mockdata populate Product

```

Add new records to the has\_many relation on a given page.

```
mockdata generate StaffMember -parent-field StaffPageID -parent "our-staff"

```

Localisation
------------

[](#localisation)

Mock data values are localised to the current locale as defined by `i18n::get_locale()`.

```
i18n::set_locale('en_US');
$staff = new StaffMember();
$staff->fill();
echo $staff->PhoneNumber; // (102) 806-3915

i18n::set_locale('fr_FR');
$staff = new StaffMember();
$staff->fill();
echo $staff->PhoneNumber; // +33 8 17 54 64 62
```

Field name hooks
----------------

[](#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.

```
en:
  MockDataObject:
    FIRSTNAME: "Firstname, FirstName"
    LASTNAME: "Surname, LastName, Lastname"
    FULLNAME: "FullName"
    CITY: "City, Town"
    STATE: "State"
    ADDRESS: "Address, Address1, Address2"
    POSTCODE: "Zip, Zipcode, ZipCode"
    COUNTRYCODE: "Country, CountryCode"
    PHONENUMBER: "Phone, PhoneNumber, Fax, Cell, Mobile, Telephone, Phonenumber"
    EMAIL: "Email, EmailAddress"
    COMPANY: "Company, CompanyName, Organization"
    URL: "URL, Website, URI"
    LATITUDE: "Latitude, Lat"
    LONGITUDE: "Longitude, Lon"

```

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:

```
fr:
  MockDataObject:
    FIRSTNAME: "Prenom"
    LASTNAME: "NomDeFamille, Nom"
    CITY: "Ville"

```

Model-independent data generation
---------------------------------

[](#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 `$Fake` method to access the fake data generator.

```
$Fake.Words
$Fake.Paragraphs(2,5)
$Fake.Image.SetWidth(100)

What we can do for you

    $Fake.Number $Fake.Words

Contact Us
$Fake.Company
$Fake.FullName
$Fake.Address
$Fake.Address
$Fake.City, $Fake.State $Fake.PostalCode
$Fake.PhoneNumber
$Fake.Email

Find us on a map!

$Fake.Latitude, $Fake.Longitude
```

Cleaning up
-----------

[](#cleaning-up)

Records of all mockdata creation are stored in the `MockDataLog` table, which maps a record ID to a class name. You can clean this table using the task `dev/tasks/MockDataTask cleanup `. 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
---------------

[](#troubleshooting)

Just ring Uncle Cheese.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~279 days

Recently: every ~256 days

Total

6

Last Release

3222d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/654636?v=4)[Aaron Carlino](/maintainers/unclecheese)[@unclecheese](https://github.com/unclecheese)

---

Top Contributors

[![dhensby](https://avatars.githubusercontent.com/u/563596?v=4)](https://github.com/dhensby "dhensby (2 commits)")[![jonom](https://avatars.githubusercontent.com/u/1079425?v=4)](https://github.com/jonom "jonom (2 commits)")[![dospuntocero](https://avatars.githubusercontent.com/u/123972?v=4)](https://github.com/dospuntocero "dospuntocero (1 commits)")[![unclecheese](https://avatars.githubusercontent.com/u/654636?v=4)](https://github.com/unclecheese "unclecheese (1 commits)")

---

Tags

silverstripecontentfakeseedingdataobject

### Embed Badge

![Health badge](/badges/unclecheese-mock-dataobjects/health.svg)

```
[![Health](https://phpackages.com/badges/unclecheese-mock-dataobjects/health.svg)](https://phpackages.com/packages/unclecheese-mock-dataobjects)
```

###  Alternatives

[silverstripe/userforms

UserForms enables CMS users to create dynamic forms via a drag and drop interface and without getting involved in any PHP code

1371.1M85](/packages/silverstripe-userforms)[silverstripe/cms

The SilverStripe Content Management System

5253.6M1.4k](/packages/silverstripe-cms)[symbiote/silverstripe-advancedworkflow

Adds configurable workflow support to the CMS, with a GUI for creating custom workflow definitions.

46302.4k9](/packages/symbiote-silverstripe-advancedworkflow)[dnadesign/silverstripe-elemental

Elemental pagetype and collection of Elements

1101.1M307](/packages/dnadesign-silverstripe-elemental)[silverstripe/frameworktest

Aids core and module developers in testing their code against a set of sample data and behaviour.

17315.0k37](/packages/silverstripe-frameworktest)[silverstripe/admin

SilverStripe admin interface

262.8M381](/packages/silverstripe-admin)

PHPackages © 2026

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