PHP code example of esit / fakertoolbox

1. Go to this page and download the library: Download esit/fakertoolbox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

esit / fakertoolbox example snippets


$GLOBALS['TL_DCA']['tl_member']['fields']['firstname']['eval']['fakerMethod'] = 'firstName';

$GLOBALS['TL_DCA']['tl_member']['fields']['id']['eval']['fakerMethod']      = 'numberBetween';
$GLOBALS['TL_DCA']['tl_member']['fields']['id']['eval']['fakerParameter']   = [1, 9999];

$GLOBALS['TL_DCA']['tl_member']['fields']['id']['eval']['fakerMethod']      = 'firstName';
$GLOBALS['TL_DCA']['tl_member']['fields']['id']['eval']['fakerOptional']    = [0.6, ''];

$GLOBALS['TL_DCA']['tl_member']['fields']['id']['eval']['fakerMethod']      = 'numberBetween';
$GLOBALS['TL_DCA']['tl_member']['fields']['id']['eval']['fakerParameter']   = [1, 3];
$GLOBALS['TL_DCA']['tl_member']['fields']['id']['eval']['fakerUnique']      = true;

$GLOBALS['TL_DCA']['tl_member']['fields']['groups']['eval']['fakerMethod']      = 'numberBetween';
$GLOBALS['TL_DCA']['tl_member']['fields']['groups']['eval']['fakerParameter']   = [1, 10];
$GLOBALS['TL_DCA']['tl_member']['fields']['groups']['eval']['fakerSerial']      = [1,5]; // Anzahl der serialisierten Datensätze: [min., max.]

$factory = \Contao\System::getContainer()->get('esit_fakertoolbox.services.factories.fakerfactory');

$faker = $factory->getFaker('tl_member');

$id = $faker->id;

$row = $faker->getRow();

$rows = $faker->getRows(5);

$factory    = \Contao\System::getContainer()->get('esit_fakertoolbox.services.factories.fakerfactory');
$faker      = $factory->getFaker('tl_member');
$faker->addProvider(\Esit\Fakertoolbox\Classes\Provider\Internet::class);

$GLOBALS['TL_DCA']['tl_member']['fields']['website']['eval']['fakerMethod']     = 'internetAddress';
$GLOBALS['TL_DCA']['tl_member']['fields']['website']['eval']['fakerParameter']  = [['https://', 'http://']]; // kann entfallen, da diese Protokolle der Standardfall sind.
$GLOBALS['TL_DCA']['tl_member']['fields']['website']['eval']['fakerOptional']   = [0.9, '']; // 10% chance of getting emtpy string

$GLOBALS['TL_DCA']['tl_member']['fields']['id']['eval']['fakerMethod']               = 'numberBetween';
$GLOBALS['TL_DCA']['tl_member']['fields']['id']['eval']['fakerParameter']            = [1, 9999];
$GLOBALS['TL_DCA']['tl_member']['fields']['tstamp']['eval']['fakerMethod']           = 'unixTime';
$GLOBALS['TL_DCA']['tl_member']['fields']['firstname']['eval']['fakerMethod']        = 'firstName';
$GLOBALS['TL_DCA']['tl_member']['fields']['lastname']['eval']['fakerMethod']         = 'lastName';
$GLOBALS['TL_DCA']['tl_member']['fields']['dateOfBirth']['eval']['fakerMethod']      = 'unixTime';
$GLOBALS['TL_DCA']['tl_member']['fields']['company']['eval']['fakerMethod']          = 'company';
$GLOBALS['TL_DCA']['tl_member']['fields']['street']['eval']['fakerMethod']           = 'streetAddress';
$GLOBALS['TL_DCA']['tl_member']['fields']['postal']['eval']['fakerMethod']           = 'postcode';
$GLOBALS['TL_DCA']['tl_member']['fields']['city']['eval']['fakerMethod']             = 'city';
$GLOBALS['TL_DCA']['tl_member']['fields']['state']['eval']['fakerMethod']            = 'state';
$GLOBALS['TL_DCA']['tl_member']['fields']['country']['eval']['fakerMethod']          = 'country';
$GLOBALS['TL_DCA']['tl_member']['fields']['phone']['eval']['fakerMethod']            = 'phoneNumber';
$GLOBALS['TL_DCA']['tl_member']['fields']['mobile']['eval']['fakerMethod']           = 'phoneNumber';
$GLOBALS['TL_DCA']['tl_member']['fields']['mobile']['eval']['fakerOptional']         = [0.4, ''];
$GLOBALS['TL_DCA']['tl_member']['fields']['fax']['eval']['fakerMethod']              = 'phoneNumber';
$GLOBALS['TL_DCA']['tl_member']['fields']['fax']['eval']['fakerOptional']            = [0.2, ''];
$GLOBALS['TL_DCA']['tl_member']['fields']['email']['eval']['fakerMethod']            = 'email';
$GLOBALS['TL_DCA']['tl_member']['fields']['language']['eval']['fakerMethod']         = 'languageCode';
$GLOBALS['TL_DCA']['tl_member']['fields']['login']['eval']['fakerMethod']            = 'unixTime';
$GLOBALS['TL_DCA']['tl_member']['fields']['username']['eval']['fakerMethod']         = 'userName';
$GLOBALS['TL_DCA']['tl_member']['fields']['disable']['eval']['fakerMethod']          = 'boolean';
$GLOBALS['TL_DCA']['tl_member']['fields']['disable']['eval']['fakerParameter']       = [80]; // chance of getting true
$GLOBALS['TL_DCA']['tl_member']['fields']['start']['eval']['fakerMethod']            = 'unixTime';
$GLOBALS['TL_DCA']['tl_member']['fields']['stop']['eval']['fakerMethod']             = 'unixTime';
$GLOBALS['TL_DCA']['tl_member']['fields']['dateAdded']['eval']['fakerMethod']        = 'unixTime';
$GLOBALS['TL_DCA']['tl_member']['fields']['lastLogin']['eval']['fakerMethod']        = 'unixTime';
$GLOBALS['TL_DCA']['tl_member']['fields']['currentLogin']['eval']['fakerMethod']     = 'unixTime';
$GLOBALS['TL_DCA']['tl_member']['fields']['loginAttempts']['eval']['fakerMethod']    = 'numberBetween';
$GLOBALS['TL_DCA']['tl_member']['fields']['loginAttempts']['eval']['fakerParameter'] = [0, 3];
$GLOBALS['TL_DCA']['tl_member']['fields']['loginAttempts']['eval']['fakerOptional']  = [0.9, 0]; // 10% chance of 0
$GLOBALS['TL_DCA']['tl_member']['fields']['locked']['eval']['fakerMethod']           = 'unixTime';

// serialisierte Daten
$GLOBALS['TL_DCA']['tl_member']['fields']['groups']['eval']['fakerMethod']           = 'numberBetween';
$GLOBALS['TL_DCA']['tl_member']['fields']['groups']['eval']['fakerParameter']        = [1, 10];
$GLOBALS['TL_DCA']['tl_member']['fields']['groups']['eval']['fakerSerial']           = [1,5]; // Anzahl der serialisierten Datensätze: [min., max.]

// internetAddressProvider
$GLOBALS['TL_DCA']['tl_member']['fields']['website']['eval']['fakerMethod']          = 'internetAddress';
$GLOBALS['TL_DCA']['tl_member']['fields']['website']['eval']['fakerParameter']       = [['https://', 'http://']];
$GLOBALS['TL_DCA']['tl_member']['fields']['website']['eval']['fakerOptional']        = [0.9, '']; // 10% chance of getting emtpy string
$GLOBALS['TL_DCA']['tl_member']['fields']['website']['eval']['fakerSerial']          = [1,5];

$factory    = \Contao\System::getContainer()->get('esit_fakertoolbox.services.factories.fakerfactory');
$faker      = $factory->getFaker('tl_member');
$testData   = $faker->getRows(50);