PHPackages                             joshmoody/mock-data - 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. joshmoody/mock-data

ActiveLibrary[Testing &amp; Quality](/categories/testing)

joshmoody/mock-data
===================

Generate realistic test data.

1.0.0(4y ago)92432MITPHPPHP &gt;=7.2

Since Jun 11Pushed 4y ago1 watchersCompare

[ Source](https://github.com/joshmoody/mock-data)[ Packagist](https://packagist.org/packages/joshmoody/mock-data)[ Docs](https://github.com/joshmoody/mock-data)[ RSS](/packages/joshmoody-mock-data/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (4)Versions (8)Used By (0)

Mock Data Generator
===================

[](#mock-data-generator)

Generate realistic test data.

[![Source](https://camo.githubusercontent.com/25f2d67a335e50b5c0b8b10ff57d8169c42871b72a9662a32c0960fed826a84e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6a6f73686d6f6f64792f6d6f636b2d2d646174612d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/joshmoody/mock-data) [![Build Status](https://camo.githubusercontent.com/8a956d8944be15e2816339f70b64f16e7d38878b9eacad1c5cdcdaa5031f4f16/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a6f73686d6f6f64792f6d6f636b2d646174612e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/joshmoody/mock-data) [![Total Downloads](https://camo.githubusercontent.com/3345b7dd826311825e66765c6d28ae6d95d3377b649c651cc38fc3f40a69432e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f73686d6f6f64792f6d6f636b2d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/joshmoody/mock-data) [![Latest Stable Version](https://camo.githubusercontent.com/42ab23bd798ad7be5a8076696c8114730d535a7d7c9bd3e0250b6b4169b6efae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f6a6f73686d6f6f64792f6d6f636b2d646174612e7376673f6c6162656c3d76657273696f6e267374796c653d666c61742d737175617265)](https://packagist.org/packages/joshmoody/mock-data)

Why?
----

[](#why)

I work with very data-intensive applications. Sometimes I need large quantities of test data for building test cases and seeding web services, databases, online forms, etc. I wrote this library to assist with this.

With a simple loop, I can generate a database representing 100,000 people to use in my development and testing.

Base data sources included in this library
------------------------------------------

[](#base-data-sources-included-in-this-library)

- US City/County/State/Zip Database
- First/Last Names from US Census
- Common U.S. Street Names

Mock Data Generation
--------------------

[](#mock-data-generation)

Many different types of mock data can be generated with this library. From basic building blocks like numbers and dates to a Person with just about every attribute you need from a Date of Birth to Driver's License and Credit Card.

Data Realism
------------

[](#data-realism)

This library is designed to create very realistic-looking data.

- If generating a person:
    - If a state is specified:
        - The city will be a valid city in that state
        - The area code, zip, and county will be correct for that city
        - The SSN will be in a valid range for that state
    - The email address will contain some portion of their name
    - First/middle name will be appropriate for the selected gender
    - For credit card numbers:
        - The prefix and length will match the type of card generated (MasterCard, Visa, etc.)

Usage
-----

[](#usage)

```
$generator = new joshmoody\Mock\Generator();

$person = $generator->getPerson('AR');
print_r($person);
```

Example output:

```
joshmoody\Mock\Entities\Person Object
(
    [guid] => d36fb161-39a8-ca74-9564-e5f903b6bad1
    [unique_hash] => f7382ef385fccc215ac1f4cd3f975ad63898556f
    [name] => joshmoody\Mock\Entities\FullName Object
        (
            [first] => Leonard
            [middle] => Gordon
            [last] => Roberts
            [gender] => M
        )

    [company] => Martin Auto
    [address] => joshmoody\Mock\Entities\Address Object
        (
            [line_1] => 6496 6th Street
            [line_2] =>
            [city] => Fort Smith
            [zip] => 72903
            [county] => Sebastian
            [state] => joshmoody\Mock\Entities\State Object
                (
                    [code] => AR
                    [name] => Arkansas
                )

        )

    [address2] => joshmoody\Mock\Entities\Address Object
        (
            [line_1] => 4126 Berkshire Drive
            [line_2] => Suite 3352
            [city] => Fort Smith
            [zip] => 72903
            [county] => Sebastian
            [state] => joshmoody\Mock\Entities\State Object
                (
                    [code] => AR
                    [name] => Arkansas
                )

        )

    [internet] => joshmoody\Mock\Entities\Internet Object
        (
            [domain] => martinauto.com
            [username] => lroberts
            [email] => leonard@yahoo.com
            [url] => http://www.martinauto.com
            [ip] => 201.254.71.153
        )

    [phone] => stdClass Object
        (
            [home] => 479-123-0338
            [mobile] => 479-761-9748
            [work] => 479-551-3998
        )

    [ssn] => 429836996
    [dln] => joshmoody\Mock\Entities\DriverLicense Object
        (
            [number] => 927684836
            [state] => AR
            [expiration] => 06/2017
        )

    [credit_card] => joshmoody\Mock\Entities\CreditCard Object
        (
            [type] => American Express
            [number] => 347716769562193
            [expiration] => 03/2015
        )

    [bank_account] => joshmoody\Mock\Entities\BankAccount Object
        (
            [type] => Checking
            [name] => First National
            [account] => 935060029
            [routing] => 075938878
        )

    [dob] => DateTime Object
        (
            [date] => 1994-05-13 03:56:44.000000
            [timezone_type] => 3
            [timezone] => UTC
        )
)

```

Each type of data element above may be generated independently.

### Names

[](#names)

Get a full name (first, middle, last, gender).

> Why is gender is included as a property of the name? In the U.S., first and middle names are usually closely associated with gender.

```
$name = $generator->getFullName();

/*
joshmoody\Mock\Entities\FullName Object
(
    [first] => Laurie
    [middle] => Joyce
    [last] => Wilson
    [gender] => F
)
*/
```

Or get parts of a name:

```
$first = $generator->getFirstName('M'); // M=Male, F=Female, null = random.
/*
string(8) "Clarence"
*/

$middle = $generator->getMiddleName('M'); // M=Male, F=Female, null = random.
/*
string(4) "Dale"
*/

$last = $generator->getLastName();
/*
string(6) "Rogers"
*/
```

### Addresses

[](#addresses)

Get a full address with street, city, state, zip

```
$address = $generator->getAddress();

/*
joshmoody\Mock\Entities\Address Object
(
    [line_1] => 2835 Hamilton Street
    [line_2] =>
    [city] => Hyndman
    [zip] => 15545
    [county] => Bedford
    [state] => joshmoody\Mock\Entities\State Object
        (
            [code] => PA
            [name] => Pennsylvania
        )

)
*/
```

Or gets parts of an address:

```
$street = $generator->getStreet();
/*
string(15) "2162 9th Street"
*/

$apartment = $generator->getApartment();
/*
string(9) "Apt. 6677"
*/

$city = $generator->getCity('AR');
/*
string(8) "Little Rock"
*/

$state = $generator->getState();
/*
joshmoody\Mock\Entities\State Object
(
    [code] => AR
    [name] => Arkansas
)
*/

$zip = $generator->getZip('AR');
/*
string(5) "72201"
*/
```

### Phone Numbers

[](#phone-numbers)

```
$phone = $generator->getPhone([$state_code = false, $zip = false, $include_toll_free = false]);
/*
string(12) "908-519-1084"
*/
```

### Internet

[](#internet)

```
$internet = $generator->getInternet([$person_name = null, $company = null]);
/*
joshmoody\Mock\Entities\Internet Object
(
    [domain] => martinez.us
    [username] => swilliams
    [email] => stacey.williams@gmail.com
    [url] => https://martinez.us
    [ip] => 157.116.10.90
)
*/

$domain = $generator->getDomain($domain = null);
/*
string(8) "dean.com"
*/

$username = $generator->getUsername([$person_name = null]);
/*
string(14) "pedro.thompson"
*/

$email = $generator->getEmail([$person_name = null, $domain = null]);
/*
string(20) "fred.harrison@me.com"
*/

$url = $generator->getUrl();
/*
string(19) "http://hernandez.us"
*/

$ip = $generator->getIp();
/*
string(13) "101.114.68.26"
*/
```

Random Data
-----------

[](#random-data)

In addition to realistic data generation, you can also use this library to easily pick a random value from an array.

```
$color = $generator->fromArray(['Red' , 'White', 'Blue']);
/*
string(3) "Red"
*/
```

Or get a boolean.

```
$bool = $generator->getBool(); // Returns bool(true) or bool(false);
/*
bool(false)
*/
```

Or get a string representation of a boolean. You define the return values for true/false

```
$yes_no = $generator->getBool('Yes', 'No'); // Returns string(Yes) or string(No)
/*
string(3) "Yes"
*/

$aye_nay = $generator->getBool('Aye', 'Nay'); // returns string(Aye) or string (Nay)
/*
 string(3) "Nay"
*/
```

Requirements
------------

[](#requirements)

- MySQL or SQlite
- PHP &gt;= 7.2 with SQlite PDO extension.

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

[](#installation)

Installation of this package is easy with Composer. If you aren't familiar with the Composer Dependency Manager for PHP, [you should read this first](https://getcomposer.org/doc/00-intro.md).

```
composer require joshmoody/mock-data

```

Zero Configuration Instructions
-------------------------------

[](#zero-configuration-instructions)

The package ships with a sqlite database containing all the data needed for generating random records.

```
$generator = new joshmoody\Mock\Generator();
```

Reloading Data
--------------

[](#reloading-data)

You can use the load script to regenerate the sqlite database at any time. This may be useful if modifying the source data to better fit your needs.

```
$ php bin/load.php
```

Acknowledgements
----------------

[](#acknowledgements)

The geographic and demographic source data used in this library was derived from several places, including:

-
-
- [https://www.census.gov/genealogy/www/data/1990surnames/names\_files.html](https://www.census.gov/genealogy/www/data/1990surnames/names_files.html)
- [http://www.livingplaces.com/streets/most-popular\_street\_names.html](http://www.livingplaces.com/streets/most-popular_street_names.html)

License and copyright
---------------------

[](#license-and-copyright)

Licensed under the MIT License. Copyright (c) 2013, Josh Moody. All rights reserved.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 96.7% 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 ~722 days

Total

5

Last Release

1650d ago

Major Versions

0.3.0 → 1.0.02021-12-23

PHP version history (2 changes)0.1.0PHP &gt;= 5.4

1.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/1cda8a02682a999e89bc2443c6c169b1dc9228cc4709d0b5fad642dc2a151141?d=identicon)[joshmoody](/maintainers/joshmoody)

---

Top Contributors

[![joshmoody](https://avatars.githubusercontent.com/u/1504862?v=4)](https://github.com/joshmoody "joshmoody (59 commits)")[![RickWong](https://avatars.githubusercontent.com/u/40102?v=4)](https://github.com/RickWong "RickWong (2 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/joshmoody-mock-data/health.svg)

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

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14228.7M341](/packages/dms-phpunit-arraysubset-asserts)[phpbenchmark/phpbenchmark

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

8011.5k2](/packages/phpbenchmark-phpbenchmark)

PHPackages © 2026

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