PHP code example of anahkiasen / fakable

1. Go to this page and download the library: Download anahkiasen/fakable 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/ */

    

anahkiasen / fakable example snippets


use Fakable\FakableModel;

class MyModel extends Eloquent
{
  use FakableModel;
}

class User extends Eloquent
{
  /**
   * The fakable attributes
   *
   * @var array
   */
  protected $fakables = array(
    'nationality' => 'countryCode',
    'timzeone'    => ['numberBetween', [1, 415]],
  );
}

> User::fake()->toArray();
array(
  'id'          => 28,
  'name'        => 'Tempore ipsa aut dolorum sit quod.',
  'slug'        => 'tempore-ipsa-aut-dolorum-sit-quod',
  'age'         => 23,
  'biography'   => 'Culpa debitis dolorem quidem eius. Quis et voluptatibus est. Quia nulla rerum expedita magnam.',
  'email'       => '[email protected]',
  'website'     => 'http://www.weissnat.com/',
  'address'     => '91274 Schmitt Light Suite 378',
  'country'     => 'Sudan',
  'city'        => 'North Twila',
  'private'     => false,
  'nationality' => 'RU'
)

User::fakeMultiple(array(
  'name' => 'foobar',
), 5, 10);

User::count() // 7

User::fakable()

User::fakable()
  ->setPool(10, 20) // Will generate 10 to 20 entries
  ->setPoolFromModel('Discussion', 2) // Will generate 2 users for every discussion
  ->setSaved(false) // Won't save anything to the database
  ->fakeModel() // Generated a single fake model, that's what ::fake() calls
  ->fakeMultiple() // Generate multiple models from the pool set previously

User::fakable()->fakeMultiple(array(
  'gender' => 'Male',
));

Fakable\Fakable::$baseFixture = app_path().'/tests/fixtures/fakable.yml';

User::fakable()->setFixture(__DIR__.'/fixtures/user.json')->fakeModel()

protected $fakables = array(
  'discussions' => [],
);

protected $fakables = array(
  'discussions' => [10, 20],
);

class Image extends Eloquent
{
  protected $fakables = array(
    'illustrable' => [
      'relationType' => 'MorphTo',
      'forModels'    => ['User', 'Discussion']
    ],
  );
}

class Image extends Eloquent
{
  protected $fakables = array(
    'illustrable' => [
      'foreignKey'   => 'imageable',
      'relationType' => 'MorphTo',
      'forModels'    => ['User', 'Discussion']
    ],
  );
}