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
1bf1a34f
Commit
1bf1a34f
authored
Jan 02, 2014
by
Mark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new docs added
parent
34b03428
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
README.md
extensions/yii/faker/README.md
+26
-4
No files found.
extensions/yii/faker/README.md
View file @
1bf1a34f
...
...
@@ -40,7 +40,7 @@ To start using this command you need to be familiar (read guide) for the [Faker]
generate fixtures template files, according to the given format:
```
php
#users.php file under template path (by default @tests/unit/
fixtures/templat
es)
#users.php file under template path (by default @tests/unit/
templates/fixtur
es)
return
[
[
'table_column0'
=>
'faker_formatter'
,
...
...
@@ -48,6 +48,8 @@ return [
'table_columnN'
=>
'other_faker_formatter'
'table_columnN+1'
=>
function
(
$fixture
,
$faker
,
$index
)
{
//set needed fixture fields based on different conditions
$fixture
[
'
body
]
=
$faker
->
sentence
(
7
,
true
);
#generate sentence exact with 7 words.
return
$fixture
;
}
],
...
...
@@ -56,12 +58,32 @@ return [
If you use callback as a attribute value, then it will be called as shown with three parameters:
*
$fixture
- current fixture array.
*
$faker
- faker generator instance
*
$index
- current fixture index. For example if user need to generate 3 fixtures for tbl_user, it will be 0..2.
*
```$fixture```
- current fixture array.
*
```$faker```
- faker generator instance
*
```$index```
- current fixture index. For example if user need to generate 3 fixtures for tbl_user, it will be 0..2.
After you set all needed fields in callback, you need to return $fixture array back from the callback.
Another example of valid 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
;
},
];
```
After you prepared needed templates for tables you can simply generate your fixtures via command
```
php
...
...
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