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
d9cd1a85
Commit
d9cd1a85
authored
Aug 17, 2014
by
Mark
Committed by
Qiang Xue
Aug 20, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added append option to fixture controller
parent
85466f17
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
9 deletions
+28
-9
FixtureController.php
framework/console/controllers/FixtureController.php
+28
-9
No files found.
framework/console/controllers/FixtureController.php
View file @
d9cd1a85
...
...
@@ -49,6 +49,11 @@ class FixtureController extends Controller
*/
public
$namespace
=
'tests\unit\fixtures'
;
/**
* @var bool whether to clean fixtures storage before apply or load them
* in the end of already existed fixtures
*/
public
$append
=
false
;
/**
* @var array global fixtures that should be applied when loading and unloading. By default it is set to `InitDbFixture`
* that disables and enables integrity check, so your data can be safely loaded.
*/
...
...
@@ -63,7 +68,7 @@ class FixtureController extends Controller
public
function
options
(
$actionId
)
{
return
array_merge
(
parent
::
options
(
$actionId
),
[
'namespace'
,
'globalFixtures'
'namespace'
,
'globalFixtures'
,
'append'
]);
}
...
...
@@ -78,14 +83,17 @@ class FixtureController extends Controller
*/
public
function
actionLoad
(
array
$fixtures
,
array
$except
=
[])
{
$foundFixtures
=
$this
->
findFixtures
(
$fixtures
);
if
(
!
$this
->
needToApplyAll
(
$fixtures
[
0
]))
{
$foundFixtures
=
$this
->
findFixtures
(
$fixtures
);
$notFoundFixtures
=
array_diff
(
$fixtures
,
$foundFixtures
);
if
(
$notFoundFixtures
)
{
$this
->
notifyNotFound
(
$notFoundFixtures
);
}
}
else
{
$foundFixtures
=
$this
->
findFixtures
();
}
if
(
!
$foundFixtures
)
{
...
...
@@ -107,7 +115,11 @@ class FixtureController extends Controller
}
$fixturesObjects
=
$this
->
createFixtures
(
$fixtures
);
$this
->
unloadFixtures
(
$fixturesObjects
);
if
(
!
$this
->
append
)
{
$this
->
unloadFixtures
(
$fixturesObjects
);
}
$this
->
loadFixtures
(
$fixturesObjects
);
$this
->
notifyLoaded
(
$fixtures
);
}
...
...
@@ -122,14 +134,15 @@ class FixtureController extends Controller
*/
public
function
actionUnload
(
array
$fixtures
,
array
$except
=
[])
{
$foundFixtures
=
$this
->
findFixtures
(
$fixtures
);
if
(
!
$this
->
needToApplyAll
(
$fixtures
[
0
]))
{
$foundFixtures
=
$this
->
findFixtures
(
$fixtures
);
$notFoundFixtures
=
array_diff
(
$fixtures
,
$foundFixtures
);
if
(
$notFoundFixtures
)
{
$this
->
notifyNotFound
(
$notFoundFixtures
);
}
}
else
{
$foundFixtures
=
$this
->
findFixtures
();
}
if
(
!
$foundFixtures
)
{
...
...
@@ -265,16 +278,22 @@ class FixtureController extends Controller
}
/**
* @param array $fixtures
* Finds fixtures to be loaded, for example "User", if no fixtures were specified then all of them
* will be searching by suffix "Fixture.php".
* @param array $fixtures fixtures to be loaded
* @return array Array of found fixtures. These may differ from input parameter as not all fixtures may exists.
*/
private
function
findFixtures
(
array
$fixtures
)
private
function
findFixtures
(
array
$fixtures
=
[]
)
{
$fixturesPath
=
$this
->
getFixturePath
();
$filesToSearch
=
[
'*Fixture.php'
];
if
(
!
$this
->
needToApplyAll
(
$fixtures
[
0
]))
{
$findAll
=
(
$fixtures
==
[]);
if
(
!
$findAll
)
{
$filesToSearch
=
[];
foreach
(
$fixtures
as
$fileName
)
{
$filesToSearch
[]
=
$fileName
.
'Fixture.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