1. Go to this page and download the library: Download league/factory-muffin 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/ */
use League\FactoryMuffin\Faker\Facade as Faker;
$fm->define('MyModel')->setDefinitions([
'foo' => Faker::word(), // Set the foo attribute to a random word
'name' => Faker::firstNameMale(), // Set the name attribute to a random male first name
'email' => Faker::email(), // Set the email attribute to a random email address
'body' => Faker::text(), // Set the body attribute to a random string of text
'slogan' => Faker::sentence(), // Set the slogan attribute to a random sentence
]);
use League\FactoryMuffin\Faker\Facade as Faker;
$fm->define('MyModel')->setDefinitions([
'age' => Faker::numberBetween(20, 40),
]);
use League\FactoryMuffin\Faker\Facade as Faker;
$fm->define('MyModel')->addDefinition('name', Faker::unique()->firstNameFemale());
use League\FactoryMuffin\Faker\Facade as Faker;
$fm->define('MyModel')->addDefinition('profile_pic', Faker::optional()->imageUrl(400, 400));
# tests/TestUserModel.php
use League\FactoryMuffin\Faker\Facade as Faker;
class TestUserModel extends PHPUnit_Framework_TestCase
{
protected static $fm;
public static function setupBeforeClass()
{
// create a new factory muffin instance
static::$fm = new FactoryMuffin();
// you can customize the save/delete methods
// new FactoryMuffin(new ModelStore('save', 'delete'));
// load your model definitions
static::$fm->loadFactories(__DIR__.'/factories');
// you can optionally set the faker locale
Faker::setLocale('en_EN');
}
public function testSampleFactory()
{
$message = static::$fm->create('Message');
$this->assertInstanceOf('Message', $message);
$this->assertInstanceOf('User', $message->user);
}
public static function tearDownAfterClass()
{
static::$fm->deleteSaved();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.