-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yii2 faker integration #1743
Yii2 faker integration #1743
Conversation
Example: #template
<?php
use yii\helpers\Security;
return [
'name' => 'firstName',
'phone' => 'phoneNumber',
'city' => 'city',
'password' => function ($fixture, $faker, $index) {
$fixture['password'] = Security::generatePasswordHash('password_' . $index);
return $fixture;
},
'auth_key' => function ($fixture, $faker, $index) {
$fixture['auth_key'] = Security::generateRandomKey();
return $fixture;
},
]; in english language: <?php
return [
[
'name' => 'Ashlynn',
'phone' => '+80(9)6646157065',
'city' => 'South Alda',
'password' => '$2y$13$skQAkV9R4jT7hIHLxbokG.Sa69zUDD72z7l.HRfwpaI88j0If0/D.',
'auth_key' => 'Vnl2xrBsbeZtyFaW5Io1JOa1kNY3SLmc',
],
[
'name' => 'Mason',
'phone' => '(136)568-9489',
'city' => 'Port Michelle',
'password' => '$2y$13$W17HXn.BvIc.u6/epVNpPOiDS9M6XrtKO2PoTFf/uvWAVB/V6UA06',
'auth_key' => 'EOuFgd9T107KbAjX57NTs5h8JgsImmen',
],
[
'name' => 'Saige',
'phone' => '1-786-316-4966x37346',
'city' => 'Sammietown',
'password' => '$2y$13$HYyIIMjF1yZIS/25qHtsPOXjZFV719HGjPmlAEbysBBNYH8LcXcw.',
'auth_key' => 'YwiSvLdUNeImPAmGBtuY4f_0tJErKj4Z',
],
]; in russian <?php
return [
[
'name' => 'Валериан',
'phone' => '+7 (922) 186-3304',
'city' => 'Луховицы',
'password' => '$2y$13$Oajf8L1aSZer2hs5.42eLOMUsF1BZHLVoZyRyx3i2cg6qHiG0ztfO',
'auth_key' => '060yversO629mK-ucq6thrE2kWwmY5k9',
],
[
'name' => 'Богдан',
'phone' => '+7 (922) 592-2549',
'city' => 'Дорохово',
'password' => '$2y$13$bEr2n/eiPOpDCUkVjgw11.WAG0YRORuawKDCk1LQTA9sVRyeaoqam',
'auth_key' => 'eBMDswP0ICk7pzCOn-nDKSF4UvFAdVV_',
],
[
'name' => 'Яков',
'phone' => '(812) 603-97-06',
'city' => 'Шаховская',
'password' => '$2y$13$mTFyq23q47SWKVtL20KpJuiS2/gRluyHPUEUjs8w7mCX.xS/3BPxy',
'auth_key' => 'jBukRMkxefGOEyz2dKt3wgPu1wcSZlZ7',
],
]; |
* This command manage fixtures creations based on given template. | ||
* | ||
* Fixtures are one of the important paths in unit testing. To speed up developers | ||
* work this fixtures can be generated automatically, based on prepared template. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this -> these
Overall looks fine except minor code style issues. Haven't actually tried it though. |
Fixed. Also added check for filename when generating. |
@yiisoft/core-developers need additional review. |
* generate fixtures template files, according to the given format: | ||
* | ||
* ~~~ | ||
* #users.php file under $templatePath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use //
for inline comments. #
is never used in any other core code.
@qiangxue how can i specify input value as array? for example i want to |
This is not supported in 2.0. You need to split the input string by yourself. |
Ok, but i think it should be added. |
What syntax would you propose to support array input? |
Fixed. Generation confirmation message added. Ready for review. |
as always something1,something2,something3. I dont think that user input will always contain |
Also, @qiangxue i wanted to support "*" as for all fixtures generating, but on my Ubuntu 13.10 basic application template |
Done, ready for review. |
Travis failed, not sure if it is my issue, because some problems with db. |
That's not your issue. Just travis glitches. |
should this PR be adjusted according new changes of supporting input array options? |
Yes, please. Thanks. |
/** | ||
* type of fixture generating | ||
*/ | ||
const GENERATE_ALL = 'all_fixtures'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't quite like all_fixtures
. Perhaps just use all
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was thinking about the same all
, sounds good, but is not it a little bit confusing? what all
can user think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the command can be configured using fixture
as the key, which will override the default fixture
command.
Then all
makes sense: yii fixture/generate all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will do changes. change docs also about fixture
alias and not faker
for the command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. There's no need to have both fixture
and faker
commands in the same app. This only causes confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we can do it. If you configure it via controllerMap
, it will take precedence when resolving route.
Also, I suggest we rename FakerController
to be FixtureController
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but if we do so, user will no be able to load his fixtures to db? what are you thinking about fixture:db
and fixture:faker
aliases? But since faker controller is extended from fixtures he also can load to db, true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I suggest we rename FakerController to be FixtureController.
its already so, or what do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... since faker controller is extended from fixtures he also can load to db,
Yes, faker controller has all the features of fixture controller. I don't see problem replacing the default fixture controller with faker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its already so, or what do you mean?
Forget about it. I didn't read carefully.
Done, ready for review. |
Thank you very much! |
Good, in the extensions docs there was written that i also should ask you for sub-split and add some changes to the |
Faker integration for Yii2. Ready for review. Sorry for big number of commits, but almost all of them about
README.md
, because of it is very important to have good docs.Related with this PR - #1527