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
3cc7fcb5
Commit
3cc7fcb5
authored
Jan 20, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored fixture.
parent
5c3bd6ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
7 deletions
+42
-7
ActiveFixture.php
framework/test/ActiveFixture.php
+4
-7
BaseActiveFixture.php
framework/test/BaseActiveFixture.php
+38
-0
No files found.
framework/test/ActiveFixture.php
View file @
3cc7fcb5
...
...
@@ -100,16 +100,13 @@ class ActiveFixture extends BaseActiveFixture
*/
protected
function
getData
()
{
if
(
$this
->
dataFile
===
false
)
{
return
[];
}
if
(
$this
->
dataFile
!==
null
)
{
$dataFile
=
Yii
::
getAlias
(
$this
->
dataFile
);
}
else
{
if
(
$this
->
dataFile
===
null
)
{
$class
=
new
\ReflectionClass
(
$this
);
$dataFile
=
dirname
(
$class
->
getFileName
())
.
'/data/'
.
$this
->
getTableSchema
()
->
fullName
.
'.php'
;
return
is_file
(
$dataFile
)
?
require
(
$dataFile
)
:
[];
}
else
{
return
parent
::
getData
();
}
return
is_file
(
$dataFile
)
?
require
(
$dataFile
)
:
[];
}
/**
...
...
framework/test/BaseActiveFixture.php
View file @
3cc7fcb5
...
...
@@ -31,6 +31,11 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
*/
public
$data
=
[];
/**
* @var string|boolean the file path or path alias of the data file that contains the fixture data
* to be returned by [[getData()]]. You can set this property to be false to prevent loading any data.
*/
public
$dataFile
;
/**
* @var \yii\db\ActiveRecord[] the loaded AR models
*/
private
$_models
=
[];
...
...
@@ -66,4 +71,37 @@ abstract class BaseActiveFixture extends DbFixture implements \IteratorAggregate
}
return
$this
->
_models
[
$name
]
=
$modelClass
::
find
(
$keys
);
}
/**
* Loads the fixture.
*
* The default implementation simply stores the data returned by [[getData()]] in [[data]].
* You should usually override this method by putting the data into the underlying database.
*/
public
function
load
()
{
$this
->
data
=
$this
->
getData
();
}
/**
* Returns the fixture data.
*
* The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
* The file should return the data array that will be stored in [[data]] after inserting into the database.
*
* @return array the data to be put into the database
* @throws InvalidConfigException if the specified data file does not exist.
*/
protected
function
getData
()
{
if
(
$this
->
dataFile
===
false
||
$this
->
dataFile
===
null
)
{
return
[];
}
$dataFile
=
Yii
::
getAlias
(
$this
->
dataFile
);
if
(
is_file
(
$dataFile
))
{
return
require
(
$dataFile
);
}
else
{
throw
new
InvalidConfigException
(
"Fixture data file does not exist:
{
$this
->
dataFile
}
"
);
}
}
}
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