Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
be8b03bc
Commit
be8b03bc
authored
Aug 07, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactoring. [skip ci]
parent
359ae98f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
25 deletions
+15
-25
FixtureController.php
extensions/faker/FixtureController.php
+15
-25
No files found.
extensions/faker/FixtureController.php
View file @
be8b03bc
...
@@ -33,27 +33,22 @@ use yii\helpers\VarDumper;
...
@@ -33,27 +33,22 @@ use yii\helpers\VarDumper;
* To start using this command you need to be familiar (read guide) for the Faker library and
* To start using this command you need to be familiar (read guide) for the Faker library and
* generate fixtures template files, according to the given format:
* generate fixtures template files, according to the given format:
*
*
* ~~~
* ```php
* #users.php file under $templatePath
* // users.php file under template path (by default @tests/unit/templates/fixtures)
*
* return [
* return [
* [
* 'name' => $faker->firstName,
* 'table_column0' => 'faker_formatter',
* 'phone' => $faker->phoneNumber,
* ...
* 'city' => $faker->city,
* 'table_columnN' => 'other_faker_formatter
* 'password' => Yii::$app->getSecurity()->generatePasswordHash('password_' . $index),
* 'table_columnN+1' => function ($fixture, $faker, $index) {
* 'auth_key' => Yii::$app->getSecurity()->generateRandomString(),
* //set needed fixture fields based on different conditions
* 'intro' => $faker->sentence(7, true), // generate a sentence with 7 words
* return $fixture;
* }
* ],
* ];
* ];
*
~~~
*
```
*
*
* If you use callback as a attribute value, then it will be called as shown with three parameters:
* If you use callback as a attribute value, then it will be called as shown with three parameters:
*
*
* - `$fixture` - current fixture array.
* - `$faker`: the Faker generator instance
* - `$faker` - faker generator instance
* - `$index`: the current fixture index. For example if user need to generate 3 fixtures for user table, it will be 0..2.
* - `$index` - current fixture index. For example if user need to generate 3 fixtures for user table, it will be 0..2
*
*
* After you set all needed fields in callback, you need to return $fixture array back from the callback.
* After you set all needed fields in callback, you need to return $fixture array back from the callback.
*
*
...
@@ -132,8 +127,6 @@ use yii\helpers\VarDumper;
...
@@ -132,8 +127,6 @@ use yii\helpers\VarDumper;
* ],
* ],
* ~~~
* ~~~
*
*
* @property \Faker\Generator $generator This property is read-only.
*
* @author Mark Jebri <mark.github@yandex.ru>
* @author Mark Jebri <mark.github@yandex.ru>
* @since 2.0.0
* @since 2.0.0
*/
*/
...
@@ -250,13 +243,10 @@ class FixtureController extends \yii\console\controllers\FixtureController
...
@@ -250,13 +243,10 @@ class FixtureController extends \yii\console\controllers\FixtureController
*/
*/
public
function
getGenerator
()
public
function
getGenerator
()
{
{
if
(
is_null
(
$this
->
_generator
))
{
if
(
$this
->
_generator
===
null
)
{
//replacing - on _ because Faker support only en_US format and not intl
$language
=
$this
->
language
===
null
?
Yii
::
$app
->
language
:
$this
->
language
;
$this
->
_generator
=
\Faker\Factory
::
create
(
str_replace
(
'-'
,
'_'
,
$language
));
$language
=
is_null
(
$this
->
language
)
?
str_replace
(
'-'
,
'_'
,
Yii
::
$app
->
language
)
:
$this
->
language
;
$this
->
_generator
=
\Faker\Factory
::
create
(
$language
);
}
}
return
$this
->
_generator
;
return
$this
->
_generator
;
}
}
...
@@ -311,7 +301,7 @@ class FixtureController extends \yii\console\controllers\FixtureController
...
@@ -311,7 +301,7 @@ class FixtureController extends \yii\console\controllers\FixtureController
public
function
generateFixture
(
$_template_
,
$index
)
public
function
generateFixture
(
$_template_
,
$index
)
{
{
// $faker and $index are exposed to the template file
// $faker and $index are exposed to the template file
$faker
=
$this
->
ge
nerator
;
$faker
=
$this
->
ge
tGenerator
()
;
return
require
(
$_template_
);
return
require
(
$_template_
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment