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
f82ecad6
Commit
f82ecad6
authored
Jan 21, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added doc.
parent
6ec427c9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
10 deletions
+28
-10
ActiveFixture.php
extensions/mongodb/ActiveFixture.php
+28
-10
No files found.
extensions/mongodb/ActiveFixture.php
View file @
f82ecad6
<?php
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\mongodb
;
namespace
yii\mongodb
;
use
Yii
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\test\BaseActiveFixture
;
class
ActiveFixture
extends
\yii\test\BaseActiveFixture
/**
* ActiveFixture represents a fixture backed up by a [[modelClass|MongoDB ActiveRecord class]] or a [[collectionName|MongoDB collection]].
*
* Either [[modelClass]] or [[collectionName]] must be set. You should also provide fixture data in the file
* specified by [[dataFile]] or overriding [[getData()]] if you want to use code to generate the fixture data.
*
* When the fixture is being loaded, it will first call [[resetCollection()]] to remove any existing data in the collection.
* It will then populate the table with the data returned by [[getData()]].
*
* After the fixture is loaded, you can access the loaded data via the [[data]] property. If you set [[modelClass]],
* you will also be able to retrieve an instance of [[modelClass]] with the populated data via [[getModel()]].
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
ActiveFixture
extends
BaseActiveFixture
{
{
/**
/**
* @var Connection|string the DB connection object or the application component ID of the DB connection.
* @var Connection|string the DB connection object or the application component ID of the DB connection.
...
@@ -55,6 +76,7 @@ class ActiveFixture extends \yii\test\BaseActiveFixture
...
@@ -55,6 +76,7 @@ class ActiveFixture extends \yii\test\BaseActiveFixture
if
(
$this
->
collectionName
)
{
if
(
$this
->
collectionName
)
{
return
$this
->
collectionName
;
return
$this
->
collectionName
;
}
else
{
}
else
{
/** @var ActiveRecord $modelClass */
$modelClass
=
$this
->
modelClass
;
$modelClass
=
$this
->
modelClass
;
return
$modelClass
::
collectionName
();
return
$modelClass
::
collectionName
();
}
}
...
@@ -74,16 +96,13 @@ class ActiveFixture extends \yii\test\BaseActiveFixture
...
@@ -74,16 +96,13 @@ class ActiveFixture extends \yii\test\BaseActiveFixture
*/
*/
protected
function
getData
()
protected
function
getData
()
{
{
if
(
$this
->
dataFile
===
false
)
{
if
(
$this
->
dataFile
===
null
)
{
return
[];
}
if
(
$this
->
dataFile
!==
null
)
{
$dataFile
=
Yii
::
getAlias
(
$this
->
dataFile
);
}
else
{
$class
=
new
\ReflectionClass
(
$this
);
$class
=
new
\ReflectionClass
(
$this
);
$dataFile
=
dirname
(
$class
->
getFileName
())
.
'/data/'
.
$this
->
getCollectionName
()
.
'.php'
;
$dataFile
=
dirname
(
$class
->
getFileName
())
.
'/data/'
.
$this
->
getCollectionName
()
.
'.php'
;
return
is_file
(
$dataFile
)
?
require
(
$dataFile
)
:
[];
}
else
{
return
parent
::
getData
();
}
}
return
is_file
(
$dataFile
)
?
require
(
$dataFile
)
:
[];
}
}
/**
/**
...
@@ -94,4 +113,4 @@ class ActiveFixture extends \yii\test\BaseActiveFixture
...
@@ -94,4 +113,4 @@ class ActiveFixture extends \yii\test\BaseActiveFixture
{
{
$this
->
getCollection
()
->
remove
();
$this
->
getCollection
()
->
remove
();
}
}
}
}
\ No newline at end of file
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