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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
4204f896
Commit
4204f896
authored
Jan 03, 2014
by
Mark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added prompt for the user, interface improved, multiply generation added
parent
467254a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
13 deletions
+39
-13
FixtureController.php
extensions/yii/faker/FixtureController.php
+32
-6
README.md
extensions/yii/faker/README.md
+7
-7
No files found.
extensions/yii/faker/FixtureController.php
View file @
4204f896
...
...
@@ -59,7 +59,7 @@ use yii\helpers\Console;
* ~~~
* php yii faker/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 faker users
* ~~~
*
...
...
@@ -84,13 +84,13 @@ use yii\helpers\Console;
* You can specify different options of this command:
*
* ~~~
*
#
generate fixtures in russian languge
*
//
generate fixtures in russian languge
* php yii faker/generate users 5 --language='ru_RU'
*
*
#
read templates from the other path
*
//
read templates from the other path
* php yii faker/generate all_fixtures --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, but be sure that this folders exists or you will get notice about that.
* php yii faker/generate all_fixtures --fixturesPath='@tests/unit/fixtures/subfolder1/subfolder2/subfolder3'
* ~~~
*
...
...
@@ -204,8 +204,12 @@ class FixtureController extends \yii\console\controllers\FixtureController
if
(
$this
->
needToGenerateAll
(
$file
))
{
$files
=
FileHelper
::
findFiles
(
$templatePath
,
[
'only'
=>
[
'.php'
]]);
}
else
{
$files
=
FileHelper
::
findFiles
(
$templatePath
,
[
'only'
=>
[
$file
.
'.php'
]]);
}
else
{
foreach
(
explode
(
','
,
$file
)
as
$fileName
)
{
$filesToSearch
[]
=
$fileName
.
'.php'
;
}
$files
=
FileHelper
::
findFiles
(
$templatePath
,
[
'only'
=>
$filesToSearch
]);
}
if
(
empty
(
$files
))
{
...
...
@@ -215,6 +219,10 @@ class FixtureController extends \yii\console\controllers\FixtureController
);
}
if
(
!
$this
->
confirmGeneration
(
$files
))
{
return
;
}
foreach
(
$files
as
$templateFile
)
{
$fixtureFileName
=
basename
(
$templateFile
);
$template
=
$this
->
getTemplate
(
$templateFile
);
...
...
@@ -340,4 +348,22 @@ class FixtureController extends \yii\console\controllers\FixtureController
return
$fixture
;
}
/**
* Prompts user with message if he confirm generation with given fixture templates files.
* @param array $files
* @return boolean
*/
public
function
confirmGeneration
(
$files
)
{
$this
->
stdout
(
"Fixtures will be generated under the path:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
realpath
(
Yii
::
getAlias
(
$this
->
fixturesPath
,
false
))
.
"
\n\n
"
,
Console
::
FG_GREEN
);
$this
->
stdout
(
"Templates will be taken from path:
\n
"
,
Console
::
FG_YELLOW
);
$this
->
stdout
(
realpath
(
Yii
::
getAlias
(
$this
->
templatePath
,
false
))
.
"
\n\n
"
,
Console
::
FG_GREEN
);
foreach
(
$files
as
$index
=>
$fileName
)
{
$this
->
stdout
(
" "
.
$index
+
1
.
". "
.
basename
(
$fileName
)
.
"
\n
"
,
Console
::
FG_GREEN
);
}
return
$this
->
confirm
(
'Generate above fixtures?'
);
}
}
extensions/yii/faker/README.md
View file @
4204f896
...
...
@@ -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/templates/fixtures)
//
users.php file under template path (by default @tests/unit/templates/fixtures)
return
[
[
'table_column0'
=>
'faker_formatter'
,
...
...
@@ -49,7 +49,7 @@ return [
'body'
=>
function
(
$fixture
,
$faker
,
$index
)
{
//set needed fixture fields based on different conditions
$fixture
[
'body'
]
=
$faker
->
sentence
(
7
,
true
);
#
generate sentence exact with 7 words.
$fixture
[
'body'
]
=
$faker
->
sentence
(
7
,
true
);
//
generate sentence exact with 7 words.
return
$fixture
;
}
],
...
...
@@ -87,10 +87,10 @@ return [
After you prepared needed templates for tables you can simply generate your fixtures via command
```
php
#
generate fixtures for the users table based on users fixture template
//
generate fixtures for the users table based on users fixture template
php
yii
faker
/
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
faker
users
```
...
...
@@ -113,13 +113,13 @@ php yii faker/generate all_fixtures 3
You can specify different options of this command:
```
php
#
generate fixtures in russian language
//
generate fixtures in russian language
php
yii
faker
/
generate
users
5
--
language
=
'ru_RU'
#
read templates from the other path
//
read templates from the other path
php
yii
faker
/
generate
all_fixtures
--
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, but be sure that this folders exists or you will get notice about that.
php
yii
faker
/
generate
all_fixtures
--
fixturesPath
=
'@tests/unit/fixtures/subfolder1/subfolder2/subfolder3'
```
...
...
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