Reputation: 127
I am generating random data for project and for unit testing. So i want to use faker. But unable to how to use faker in yii2?
Upvotes: 1
Views: 275
Reputation: 1422
set this in your main config:
return [
'controllerMap' => [
'fixture' => [
'class' => 'yii\faker\FixtureController',
'templatePath' => '@common/tests/templates/fixtures',
'fixtureDataPath' => '@common/tests/fixtures/data',
],
// ...
],
// ...
];
use it like this:
$faker = Faker\Factory::create();
// generate data by accessing properties
echo $faker->name;
// 'Lucy Cechtelar';
echo $faker->address;
// "426 Jordy Lodge
// Cartwrightshire, SC 88120-6700"
echo $faker->text;
for more info check faker basic usage and yii2 guide
Upvotes: 1