2017 © Pedro Peláez
 

library populator

Database fake data populator for PHP

image

lulco/populator

Database fake data populator for PHP

  • Wednesday, December 27, 2017
  • by lulco
  • Repository
  • 1 Watchers
  • 0 Stars
  • 92 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 15 % Grown

The README.md

Populator

Allows populate fake data to your database, (*1)

PHP unit PHPStan level PHP static analysis SensioLabsInsight Latest Stable Version Total Downloads PHP 7 supported, (*2)

The best feature of this library is AutomaticPopulatorCommand which populates data based on full database structure. It analyses database table tree and creates items for each table - leaves first., (*3)

// file bin/command.php

$database = new Populator\Database\Database('db_name', 'mysql:dbname=db_name;host=db_host', 'db_user', 'db_password');
$populator = new Populator\Command\AutomaticPopulatorCommand($database, ['phoenix_log', 'phinxlog', 'migration_log', 'versions', 'api_logs', 'api_tokens'], true, $columnNameAndTypeCallbacks);

$application = new Application();
$application->add($populator);
$application->run();

Run:, (*4)

php bin/command.php populator:populate
````

With this setup, AutomaticPopulatorCommand will create 5 items in all leaf-tables, than 25 for 2nd level, and 125 for all next levels. It can be changed by parameters `$countBase` and `$maxCountPerTable` of AutomaticPopulatorCommand.  



You can also use AutomaticPopulator which allows you to create fake data for one table based on its structure or column names.

Create file e.g. `bin/command.php` as shown below (or add PopulatorCommand to existing Symfony console application):

```php
// file bin/command.php

$application = new Symfony\Component\Console\Application();
$populator = new Populator\Command\PopulatorCommand();
$populator->addDatabase(new Populator\Database\Database('db_name', 'mysql:dbname=db_name;host=db_host', 'db_user', 'db_password'));

$table1Populator = new Populator\Populator\AutomaticPopulator('table_1', 50);
$populator->addPopulator($table1Populator);

$application->add($populator);
$application->run();

This setup will populate 50 fake rows for database table with name table_1 after executing this command: ``` php bin/command.php populator:populate ````, (*5)

The Versions

27/12 2017

dev-master

9999999-dev

Database fake data populator for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

database php fake data