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
ce2f58f0
Commit
ce2f58f0
authored
Feb 04, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2312 from Ragazzo/faker_controller_improved
Faker controller improved
parents
9669b321
3d6529ef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
24 deletions
+26
-24
FixtureController.php
extensions/faker/FixtureController.php
+20
-19
README.md
extensions/faker/README.md
+6
-5
No files found.
extensions/faker/FixtureController.php
View file @
ce2f58f0
...
@@ -69,7 +69,7 @@ use yii\helpers\FileHelper;
...
@@ -69,7 +69,7 @@ use yii\helpers\FileHelper;
* ~~~
* ~~~
*
*
* In the code above "users" is template name, after this command run, new file named same as template
* In the code above "users" is template name, after this command run, new file named same as template
* will be created under the `$fixturePath` folder.
* will be created under the `$fixture
Data
Path` folder.
* You can generate fixtures for all templates by specifying keyword "all"
* You can generate fixtures for all templates by specifying keyword "all"
*
*
* ~~~
* ~~~
...
@@ -77,7 +77,7 @@ use yii\helpers\FileHelper;
...
@@ -77,7 +77,7 @@ use yii\helpers\FileHelper;
* ~~~
* ~~~
*
*
* This command will generate fixtures for all template files that are stored under $templatePath and
* This command will generate fixtures for all template files that are stored under $templatePath and
* store fixtures under
$fixturePath
with file names same as templates names.
* store fixtures under
`$fixtureDataPath`
with file names same as templates names.
*
*
* You can specify how many fixtures per file you need by the second parameter. In the code below we generate
* You can specify how many fixtures per file you need by the second parameter. In the code below we generate
* all fixtures and in each file there will be 3 rows (fixtures).
* all fixtures and in each file there will be 3 rows (fixtures).
...
@@ -95,8 +95,8 @@ use yii\helpers\FileHelper;
...
@@ -95,8 +95,8 @@ use yii\helpers\FileHelper;
* //read templates from the other path
* //read templates from the other path
* yii fixture/generate all --templatePath=@app/path/to/my/custom/templates
* yii fixture/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.
* //generate fixtures into other folders
* yii fixture/generate all --fixturePath=@tests/unit/fixtures/subfolder1/subfolder2/subfolder3
* yii fixture/generate all --fixture
Data
Path=@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);
* You also can create your own data providers for custom tables fields, see Faker library guide for more info (https://github.com/fzaninotto/Faker);
...
@@ -148,24 +148,24 @@ class FixtureController extends \yii\console\controllers\FixtureController
...
@@ -148,24 +148,24 @@ class FixtureController extends \yii\console\controllers\FixtureController
*/
*/
public
$defaultAction
=
'generate'
;
public
$defaultAction
=
'generate'
;
/**
/**
* Alias to the template path, where all tables templates are stored.
* @var string Alias to the template path, where all tables templates are stored.
* @var string
*/
*/
public
$templatePath
=
'@tests/unit/templates/fixtures'
;
public
$templatePath
=
'@tests/unit/templates/fixtures'
;
/**
/**
* Language to use when generating fixtures data.
* @var string Alias to the fixture data path, where data files should be written.
* @var string
*/
public
$fixtureDataPath
=
'@tests/unit/fixtures/data'
;
/**
* @var string Language to use when generating fixtures data.
*/
*/
public
$language
;
public
$language
;
/**
/**
* Additional data providers that can be created by user and will be added to the Faker generator.
*
@var array
Additional data providers that can be created by user and will be added to the Faker generator.
* More info in [Faker](https://github.com/fzaninotto/Faker.) library docs.
* More info in [Faker](https://github.com/fzaninotto/Faker.) library docs.
* @var array
*/
*/
public
$providers
=
[];
public
$providers
=
[];
/**
/**
* Faker generator instance
* @var \Faker\Generator Faker generator instance
* @var \Faker\Generator
*/
*/
private
$_generator
;
private
$_generator
;
...
@@ -177,7 +177,7 @@ class FixtureController extends \yii\console\controllers\FixtureController
...
@@ -177,7 +177,7 @@ class FixtureController extends \yii\console\controllers\FixtureController
public
function
globalOptions
()
public
function
globalOptions
()
{
{
return
array_merge
(
parent
::
globalOptions
(),
[
return
array_merge
(
parent
::
globalOptions
(),
[
'templatePath'
,
'language'
'templatePath'
,
'language'
,
'fixtureDataPath'
]);
]);
}
}
...
@@ -201,7 +201,7 @@ class FixtureController extends \yii\console\controllers\FixtureController
...
@@ -201,7 +201,7 @@ class FixtureController extends \yii\console\controllers\FixtureController
public
function
actionGenerate
(
array
$file
,
$times
=
2
)
public
function
actionGenerate
(
array
$file
,
$times
=
2
)
{
{
$templatePath
=
Yii
::
getAlias
(
$this
->
templatePath
);
$templatePath
=
Yii
::
getAlias
(
$this
->
templatePath
);
$fixture
Path
=
Yii
::
getAlias
(
$this
->
fixture
Path
);
$fixture
DataPath
=
Yii
::
getAlias
(
$this
->
fixtureData
Path
);
if
(
$this
->
needToGenerateAll
(
$file
[
0
]))
{
if
(
$this
->
needToGenerateAll
(
$file
[
0
]))
{
$files
=
FileHelper
::
findFiles
(
$templatePath
,
[
'only'
=>
[
'*.php'
]]);
$files
=
FileHelper
::
findFiles
(
$templatePath
,
[
'only'
=>
[
'*.php'
]]);
...
@@ -233,9 +233,10 @@ class FixtureController extends \yii\console\controllers\FixtureController
...
@@ -233,9 +233,10 @@ class FixtureController extends \yii\console\controllers\FixtureController
}
}
$content
=
$this
->
exportFixtures
(
$fixtures
);
$content
=
$this
->
exportFixtures
(
$fixtures
);
$filePath
=
realpath
(
$fixturePath
.
'/'
.
$fixtureFileName
);
FileHelper
::
createDirectory
(
$fixtureDataPath
);
file_put_contents
(
$filePath
,
$content
);
file_put_contents
(
$fixtureDataPath
.
'/'
.
$fixtureFileName
,
$content
);
$this
->
stdout
(
"Fixture file was generated under:
$filePath
\n
"
,
Console
::
FG_GREEN
);
$this
->
stdout
(
"Fixture file was generated under:
$fixtureDataPath
\n
"
,
Console
::
FG_GREEN
);
}
}
}
}
...
@@ -357,9 +358,9 @@ class FixtureController extends \yii\console\controllers\FixtureController
...
@@ -357,9 +358,9 @@ class FixtureController extends \yii\console\controllers\FixtureController
public
function
confirmGeneration
(
$files
)
public
function
confirmGeneration
(
$files
)
{
{
$this
->
stdout
(
"Fixtures will be generated under the path:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
"Fixtures will be generated under the path:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
realpath
(
Yii
::
getAlias
(
$this
->
fixturePath
)
)
.
"
\n\n
"
,
Console
::
FG_GREEN
);
$this
->
stdout
(
"
\t
"
.
Yii
::
getAlias
(
$this
->
fixtureDataPath
)
.
"
\n\n
"
,
Console
::
FG_GREEN
);
$this
->
stdout
(
"Templates will be taken from path:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
"Templates will be taken from path:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
realpath
(
Yii
::
getAlias
(
$this
->
templatePath
)
)
.
"
\n\n
"
,
Console
::
FG_GREEN
);
$this
->
stdout
(
"
\t
"
.
Yii
::
getAlias
(
$this
->
templatePath
)
.
"
\n\n
"
,
Console
::
FG_GREEN
);
foreach
(
$files
as
$index
=>
$fileName
)
{
foreach
(
$files
as
$index
=>
$fileName
)
{
$this
->
stdout
(
" "
.
(
$index
+
1
)
.
". "
.
basename
(
$fileName
)
.
"
\n
"
,
Console
::
FG_GREEN
);
$this
->
stdout
(
" "
.
(
$index
+
1
)
.
". "
.
basename
(
$fileName
)
.
"
\n
"
,
Console
::
FG_GREEN
);
...
...
extensions/faker/README.md
View file @
ce2f58f0
...
@@ -95,13 +95,14 @@ php yii fixture/generate users
...
@@ -95,13 +95,14 @@ php yii fixture/generate users
//also a short version of this command ("generate" action is default)
//also a short version of this command ("generate" action is default)
php
yii
fixture
users
php
yii
fixture
users
//to generate
fixtures for several tab
les, use "," as a separator, for example:
//to generate
several fixtures data fi
les, use "," as a separator, for example:
php
yii
fixture
users
,
profile
,
some_other_
tabl
e
php
yii
fixture
users
,
profile
,
some_other_
nam
e
```
```
In the code above "users" is template name, after this command run, new file named same as template
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.
will be created under the fixtures path (by default
```@tests/unit/fixtures```
) folder.
You can generate fixtures for all templates by specifying keyword
```all```
.
You can generate fixtures for all templates by specifying keyword
```all```
. You dont need to worry about if data file
directory already created or not, if not - it will be created by these command.
```
php
```
php
php
yii
fixture
/
generate
all
php
yii
fixture
/
generate
all
...
@@ -124,8 +125,8 @@ php yii fixture/generate users 5 --language='ru_RU'
...
@@ -124,8 +125,8 @@ php yii fixture/generate users 5 --language='ru_RU'
//read templates from the other path
//read templates from the other path
php
yii
fixture
/
generate
all
--
templatePath
=
'@app/path/to/my/custom/templates'
php
yii
fixture
/
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
.
//generate fixtures into other
directory
.
php
yii
fixture
/
generate
all
--
fixture
Path
=
'@tests/unit/fixtures/subfolder1/subfolder2/subfolder3
'
php
yii
fixture
/
generate
all
--
fixture
DataPath
=
'@tests/acceptance/fixtures/data
'
```
```
You also can create your own data providers for custom tables fields, see
[
Faker
](
(https://github.com/fzaninotto/Faker
)
) library guide for more info;
You also can create your own data providers for custom tables fields, see
[
Faker
](
(https://github.com/fzaninotto/Faker
)
) library guide for more info;
...
...
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