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
c5bd2702
Commit
c5bd2702
authored
Jan 03, 2014
by
Mark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed command signature, docs improved.
parent
02bfea4f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
26 deletions
+26
-26
FixtureController.php
extensions/yii/faker/FixtureController.php
+15
-15
README.md
extensions/yii/faker/README.md
+11
-11
No files found.
extensions/yii/faker/FixtureController.php
View file @
c5bd2702
...
...
@@ -23,7 +23,7 @@ use yii\helpers\Console;
*
* ~~~
* 'controllerMap' => [
* 'f
aker
' => [
* 'f
ixture
' => [
* 'class' => 'yii\faker\FixtureController',
* ],
* ],
...
...
@@ -57,13 +57,13 @@ use yii\helpers\Console;
* After you prepared needed templates for tables you can simply generate your fixtures via command
*
* ~~~
* php yii f
aker
/generate users
* php yii f
ixture
/generate users
*
* //also a short version of this command (generate action is default)
* php yii f
aker
users
* php yii f
ixture
users
*
* //to generate fixtures for several tables, use "," as a separator, for example:
* php yii f
aker
users,profile
* php yii f
ixture
users,profile
* ~~~
*
* In the code above "users" is template name, after this command run, new file named same as template
...
...
@@ -71,7 +71,7 @@ use yii\helpers\Console;
* You can generate fixtures for all templates by specifying keyword "all_fixtures"
*
* ~~~
* php yii f
aker/generate all_fixtures
* php yii f
ixture/generate all
* ~~~
*
* This command will generate fixtures for all template files that are stored under $templatePath and
...
...
@@ -81,20 +81,20 @@ use yii\helpers\Console;
* all fixtures and in each file there will be 3 rows (fixtures).
*
* ~~~
* php yii f
aker/generate all_fixtures
3
* php yii f
ixture/generate all
3
* ~~~
*
* You can specify different options of this command:
*
* ~~~
* //generate fixtures in russian languge
* php yii f
aker
/generate users 5 --language='ru_RU'
* php yii f
ixture
/generate users 5 --language='ru_RU'
*
* //read templates from the other path
* php yii f
aker/generate all_fixtures
--templatePath='@app/path/to/my/custom/templates'
* php yii f
ixture/generate all
--templatePath='@app/path/to/my/custom/templates'
*
* //generate fixtures into other folders, but be sure that this folders exists or you will get notice about that.
* php yii f
aker/generate all_fixtures
--fixturesPath='@tests/unit/fixtures/subfolder1/subfolder2/subfolder3'
* php yii f
ixture/generate all
--fixturesPath='@tests/unit/fixtures/subfolder1/subfolder2/subfolder3'
* ~~~
*
* You also can create your own data providers for custom tables fields, see Faker library guide for more info (https://github.com/fzaninotto/Faker);
...
...
@@ -121,7 +121,7 @@ use yii\helpers\Console;
*
* ~~~
* 'controllerMap' => [
* 'f
aker
' => [
* 'f
ixture
' => [
* 'class' => 'yii\faker\FixtureController',
* 'providers' => [
* 'app\tests\unit\faker\providers\Book',
...
...
@@ -140,7 +140,7 @@ class FixtureController extends \yii\console\controllers\FixtureController
/**
* type of fixture generating
*/
const
GENERATE_ALL
=
'all
_fixtures
'
;
const
GENERATE_ALL
=
'all'
;
/**
* @var string controller default action ID.
...
...
@@ -197,19 +197,19 @@ class FixtureController extends \yii\console\controllers\FixtureController
/**
* Generates fixtures and fill them with Faker data.
* @param string $file filename for the table template. You can generate all fixtures for all tables
* by specifiyng keyword "all
_fixtures
" as filename.
* by specifiyng keyword "all" as filename.
* @param integer $times how much fixtures do you want per table
*/
public
function
actionGenerate
(
$file
,
$times
=
2
)
public
function
actionGenerate
(
array
$file
,
$times
=
2
)
{
$templatePath
=
Yii
::
getAlias
(
$this
->
templatePath
);
$fixturesPath
=
Yii
::
getAlias
(
$this
->
fixturesPath
);
if
(
$this
->
needToGenerateAll
(
$file
))
{
if
(
$this
->
needToGenerateAll
(
$file
[
0
]
))
{
$files
=
FileHelper
::
findFiles
(
$templatePath
,
[
'only'
=>
[
'.php'
]]);
}
else
{
foreach
(
explode
(
','
,
$file
)
as
$fileName
)
{
foreach
(
$file
as
$fileName
)
{
$filesToSearch
[]
=
$fileName
.
'.php'
;
}
$files
=
FileHelper
::
findFiles
(
$templatePath
,
[
'only'
=>
$filesToSearch
]);
...
...
extensions/yii/faker/README.md
View file @
c5bd2702
...
...
@@ -29,7 +29,7 @@ To use this extension, simply add the following code in your application config
```
php
'controllerMap'
=>
[
'f
aker
'
=>
[
'f
ixture
'
=>
[
'class'
=>
'yii\faker\FixtureController'
,
],
],
...
...
@@ -88,21 +88,21 @@ After you prepared needed templates for tables you can simply generate your fixt
```
php
//generate fixtures for the users table based on users fixture template
php
yii
f
aker
/
generate
users
php
yii
f
ixture
/
generate
users
//also a short version of this command ("generate" action is default)
php
yii
f
aker
users
php
yii
f
ixture
users
//to generate fixtures for several tables, use "," as a separator, for example:
php
yii
f
aker
users
,
profile
,
some_other_table
php
yii
f
ixture
users
,
profile
,
some_other_table
```
In the code above "users" is template name, after this command run, new file named same as template
will be created under the fixtures path (by default
```@tests/unit/fixtures```
) folder.
You can generate fixtures for all templates by specifying keyword
```all
_fixtures
```
.
You can generate fixtures for all templates by specifying keyword
```all```
.
```
php
php
yii
f
aker
/
generate
all_fixtures
php
yii
f
ixture
/
generate
all_fixtures
```
This command will generate fixtures for all template files that are stored under template path and
...
...
@@ -111,19 +111,19 @@ You can specify how many fixtures per file you need by the second parameter. In
all fixtures and in each file there will be 3 rows (fixtures).
```
php
php
yii
f
aker
/
generate
all_fixtures
3
php
yii
f
ixture
/
generate
all
3
```
You can specify different options of this command:
```
php
//generate fixtures in russian language
php
yii
f
aker
/
generate
users
5
--
language
=
'ru_RU'
php
yii
f
ixture
/
generate
users
5
--
language
=
'ru_RU'
//read templates from the other path
php
yii
f
aker
/
generate
all_fixtures
--
templatePath
=
'@app/path/to/my/custom/templates'
php
yii
f
ixture
/
generate
all
--
templatePath
=
'@app/path/to/my/custom/templates'
//generate fixtures into other folders, but be sure that this folders exists or you will get notice about that.
php
yii
f
aker
/
generate
all_fixtures
--
fixturesPath
=
'@tests/unit/fixtures/subfolder1/subfolder2/subfolder3'
php
yii
f
ixture
/
generate
all
--
fixturesPath
=
'@tests/unit/fixtures/subfolder1/subfolder2/subfolder3'
```
You also can create your own data providers for custom tables fields, see
[
Faker
](
(https://github.com/fzaninotto/Faker
)
) library guide for more info;
...
...
@@ -150,7 +150,7 @@ You can use it by adding it to the ```$providers``` property of the current comm
```
php
'controllerMap'
=>
[
'f
aker
'
=>
[
'f
ixture
'
=>
[
'class'
=>
'yii\faker\FixtureController'
,
'providers'
=>
[
'app\tests\unit\faker\providers\Book'
,
...
...
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