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
9cf8d7df
Commit
9cf8d7df
authored
Feb 04, 2014
by
Mark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
faker extension fixed
parent
9779e9c9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
19 deletions
+20
-19
FixtureController.php
extensions/faker/FixtureController.php
+20
-19
No files found.
extensions/faker/FixtureController.php
View file @
9cf8d7df
...
@@ -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
);
...
...
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