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
9b5f3fab
Commit
9b5f3fab
authored
Dec 06, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extension "mongo" renamed into "mongodb"
parent
7fcc38da
Hide whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
147 additions
and
149 deletions
+147
-149
ActiveQuery.php
extensions/mongodb/ActiveQuery.php
+1
-1
ActiveRecord.php
extensions/mongodb/ActiveRecord.php
+4
-4
ActiveRelation.php
extensions/mongodb/ActiveRelation.php
+1
-1
Collection.php
extensions/mongodb/Collection.php
+1
-1
Connection.php
extensions/mongodb/Connection.php
+6
-6
Database.php
extensions/mongodb/Database.php
+6
-6
Exception.php
extensions/mongodb/Exception.php
+1
-1
LICENSE.md
extensions/mongodb/LICENSE.md
+0
-0
Query.php
extensions/mongodb/Query.php
+10
-10
README.md
extensions/mongodb/README.md
+8
-8
composer.json
extensions/mongodb/composer.json
+3
-3
ActiveQuery.php
extensions/mongodb/file/ActiveQuery.php
+3
-3
ActiveRecord.php
extensions/mongodb/file/ActiveRecord.php
+2
-2
ActiveRelation.php
extensions/mongodb/file/ActiveRelation.php
+1
-1
Collection.php
extensions/mongodb/file/Collection.php
+6
-6
Query.php
extensions/mongodb/file/Query.php
+5
-7
ActiveRecord.php
tests/unit/data/ar/mongodb/ActiveRecord.php
+2
-2
Customer.php
tests/unit/data/ar/mongodb/Customer.php
+1
-1
CustomerOrder.php
tests/unit/data/ar/mongodb/CustomerOrder.php
+1
-1
ActiveRecord.php
tests/unit/data/ar/mongodb/file/ActiveRecord.php
+2
-2
CustomerFile.php
tests/unit/data/ar/mongodb/file/CustomerFile.php
+1
-1
config.php
tests/unit/data/config.php
+1
-1
ActiveDataProviderTest.php
tests/unit/extensions/mongodb/ActiveDataProviderTest.php
+5
-5
ActiveRecordTest.php
tests/unit/extensions/mongodb/ActiveRecordTest.php
+5
-5
ActiveRelationTest.php
tests/unit/extensions/mongodb/ActiveRelationTest.php
+5
-5
CollectionTest.php
tests/unit/extensions/mongodb/CollectionTest.php
+4
-4
ConnectionTest.php
tests/unit/extensions/mongodb/ConnectionTest.php
+13
-13
DatabaseTest.php
tests/unit/extensions/mongodb/DatabaseTest.php
+4
-4
MongoDbTestCase.php
tests/unit/extensions/mongodb/MongoDbTestCase.php
+25
-25
QueryRunTest.php
tests/unit/extensions/mongodb/QueryRunTest.php
+3
-3
QueryTest.php
tests/unit/extensions/mongodb/QueryTest.php
+3
-3
ActiveRecordTest.php
tests/unit/extensions/mongodb/file/ActiveRecordTest.php
+6
-6
CollectionTest.php
tests/unit/extensions/mongodb/file/CollectionTest.php
+4
-4
QueryTest.php
tests/unit/extensions/mongodb/file/QueryTest.php
+4
-4
No files found.
extensions/mongo/ActiveQuery.php
→
extensions/mongo
db
/ActiveQuery.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo
;
namespace
yii\mongo
db
;
use
yii\db\ActiveQueryInterface
;
use
yii\db\ActiveQueryInterface
;
use
yii\db\ActiveQueryTrait
;
use
yii\db\ActiveQueryTrait
;
...
...
extensions/mongo/ActiveRecord.php
→
extensions/mongo
db
/ActiveRecord.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo
;
namespace
yii\mongo
db
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidParamException
;
use
yii\base\InvalidParamException
;
...
@@ -25,13 +25,13 @@ abstract class ActiveRecord extends BaseActiveRecord
...
@@ -25,13 +25,13 @@ abstract class ActiveRecord extends BaseActiveRecord
{
{
/**
/**
* Returns the Mongo connection used by this AR class.
* Returns the Mongo connection used by this AR class.
* By default, the "mongo" application component is used as the Mongo connection.
* By default, the "mongo
db
" application component is used as the Mongo connection.
* You may override this method if you want to use a different database connection.
* You may override this method if you want to use a different database connection.
* @return Connection the database connection used by this AR class.
* @return Connection the database connection used by this AR class.
*/
*/
public
static
function
getDb
()
public
static
function
getDb
()
{
{
return
\Yii
::
$app
->
getComponent
(
'mongo'
);
return
\Yii
::
$app
->
getComponent
(
'mongo
db
'
);
}
}
/**
/**
...
@@ -174,7 +174,7 @@ abstract class ActiveRecord extends BaseActiveRecord
...
@@ -174,7 +174,7 @@ abstract class ActiveRecord extends BaseActiveRecord
*/
*/
public
function
attributes
()
public
function
attributes
()
{
{
throw
new
InvalidConfigException
(
'The attributes() method of mongo ActiveRecord has to be implemented by child classes.'
);
throw
new
InvalidConfigException
(
'The attributes() method of mongo
db
ActiveRecord has to be implemented by child classes.'
);
}
}
/**
/**
...
...
extensions/mongo/ActiveRelation.php
→
extensions/mongo
db
/ActiveRelation.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo
;
namespace
yii\mongo
db
;
use
yii\db\ActiveRelationInterface
;
use
yii\db\ActiveRelationInterface
;
use
yii\db\ActiveRelationTrait
;
use
yii\db\ActiveRelationTrait
;
...
...
extensions/mongo/Collection.php
→
extensions/mongo
db
/Collection.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo
;
namespace
yii\mongo
db
;
use
yii\base\InvalidParamException
;
use
yii\base\InvalidParamException
;
use
yii\base\Object
;
use
yii\base\Object
;
...
...
extensions/mongo/Connection.php
→
extensions/mongo
db
/Connection.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo
;
namespace
yii\mongo
db
;
use
yii\base\Component
;
use
yii\base\Component
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
...
@@ -23,7 +23,7 @@ use Yii;
...
@@ -23,7 +23,7 @@ use Yii;
* the DB connection:
* the DB connection:
*
*
* ~~~
* ~~~
* $connection = new \yii\mongo\Connection([
* $connection = new \yii\mongo
db
\Connection([
* 'dsn' => $dsn,
* 'dsn' => $dsn,
* ]);
* ]);
* $connection->open();
* $connection->open();
...
@@ -55,8 +55,8 @@ use Yii;
...
@@ -55,8 +55,8 @@ use Yii;
* ~~~
* ~~~
* [
* [
* 'components' => [
* 'components' => [
* 'mongo' => [
* 'mongo
db
' => [
* 'class' => '\yii\mongo\Connection',
* 'class' => '\yii\mongo
db
\Connection',
* 'dsn' => 'mongodb://developer:password@localhost:27017/mydatabase',
* 'dsn' => 'mongodb://developer:password@localhost:27017/mydatabase',
* ],
* ],
* ],
* ],
...
@@ -102,7 +102,7 @@ class Connection extends Component
...
@@ -102,7 +102,7 @@ class Connection extends Component
*/
*/
public
$defaultDatabaseName
;
public
$defaultDatabaseName
;
/**
/**
* @var \MongoClient
m
ongo client instance.
* @var \MongoClient
M
ongo client instance.
*/
*/
public
$mongoClient
;
public
$mongoClient
;
/**
/**
...
@@ -156,7 +156,7 @@ class Connection extends Component
...
@@ -156,7 +156,7 @@ class Connection extends Component
{
{
$this
->
open
();
$this
->
open
();
return
Yii
::
createObject
([
return
Yii
::
createObject
([
'class'
=>
'yii\mongo\Database'
,
'class'
=>
'yii\mongo
db
\Database'
,
'mongoDb'
=>
$this
->
mongoClient
->
selectDB
(
$name
)
'mongoDb'
=>
$this
->
mongoClient
->
selectDB
(
$name
)
]);
]);
}
}
...
...
extensions/mongo/Database.php
→
extensions/mongo
db
/Database.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo
;
namespace
yii\mongo
db
;
use
yii\base\Object
;
use
yii\base\Object
;
use
Yii
;
use
Yii
;
...
@@ -46,7 +46,7 @@ class Database extends Object
...
@@ -46,7 +46,7 @@ class Database extends Object
* Returns the Mongo collection with the given name.
* Returns the Mongo collection with the given name.
* @param string $name collection name
* @param string $name collection name
* @param boolean $refresh whether to reload the collection instance even if it is found in the cache.
* @param boolean $refresh whether to reload the collection instance even if it is found in the cache.
* @return Collection
m
ongo collection instance.
* @return Collection
M
ongo collection instance.
*/
*/
public
function
getCollection
(
$name
,
$refresh
=
false
)
public
function
getCollection
(
$name
,
$refresh
=
false
)
{
{
...
@@ -60,7 +60,7 @@ class Database extends Object
...
@@ -60,7 +60,7 @@ class Database extends Object
* Returns Mongo GridFS collection with given prefix.
* Returns Mongo GridFS collection with given prefix.
* @param string $prefix collection prefix.
* @param string $prefix collection prefix.
* @param boolean $refresh whether to reload the collection instance even if it is found in the cache.
* @param boolean $refresh whether to reload the collection instance even if it is found in the cache.
* @return file\Collection
m
ongo GridFS collection.
* @return file\Collection
M
ongo GridFS collection.
*/
*/
public
function
getFileCollection
(
$prefix
=
'fs'
,
$refresh
=
false
)
public
function
getFileCollection
(
$prefix
=
'fs'
,
$refresh
=
false
)
{
{
...
@@ -78,7 +78,7 @@ class Database extends Object
...
@@ -78,7 +78,7 @@ class Database extends Object
protected
function
selectCollection
(
$name
)
protected
function
selectCollection
(
$name
)
{
{
return
Yii
::
createObject
([
return
Yii
::
createObject
([
'class'
=>
'yii\mongo\Collection'
,
'class'
=>
'yii\mongo
db
\Collection'
,
'mongoCollection'
=>
$this
->
mongoDb
->
selectCollection
(
$name
)
'mongoCollection'
=>
$this
->
mongoDb
->
selectCollection
(
$name
)
]);
]);
}
}
...
@@ -91,7 +91,7 @@ class Database extends Object
...
@@ -91,7 +91,7 @@ class Database extends Object
protected
function
selectFileCollection
(
$prefix
)
protected
function
selectFileCollection
(
$prefix
)
{
{
return
Yii
::
createObject
([
return
Yii
::
createObject
([
'class'
=>
'yii\mongo\file\Collection'
,
'class'
=>
'yii\mongo
db
\file\Collection'
,
'mongoCollection'
=>
$this
->
mongoDb
->
getGridFS
(
$prefix
)
'mongoCollection'
=>
$this
->
mongoDb
->
getGridFS
(
$prefix
)
]);
]);
}
}
...
@@ -103,7 +103,7 @@ class Database extends Object
...
@@ -103,7 +103,7 @@ class Database extends Object
* you need to create collection with the specific options.
* you need to create collection with the specific options.
* @param string $name name of the collection
* @param string $name name of the collection
* @param array $options collection options in format: "name" => "value"
* @param array $options collection options in format: "name" => "value"
* @return \MongoCollection new
m
ongo collection instance.
* @return \MongoCollection new
M
ongo collection instance.
* @throws Exception on failure.
* @throws Exception on failure.
*/
*/
public
function
createCollection
(
$name
,
$options
=
[])
public
function
createCollection
(
$name
,
$options
=
[])
...
...
extensions/mongo/Exception.php
→
extensions/mongo
db
/Exception.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo
;
namespace
yii\mongo
db
;
/**
/**
* Exception represents an exception that is caused by some Mongo-related operations.
* Exception represents an exception that is caused by some Mongo-related operations.
...
...
extensions/mongo/LICENSE.md
→
extensions/mongo
db
/LICENSE.md
View file @
9b5f3fab
File moved
extensions/mongo/Query.php
→
extensions/mongo
db
/Query.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo
;
namespace
yii\mongo
db
;
use
yii\base\Component
;
use
yii\base\Component
;
use
yii\db\QueryInterface
;
use
yii\db\QueryInterface
;
...
@@ -60,7 +60,7 @@ class Query extends Component implements QueryInterface
...
@@ -60,7 +60,7 @@ class Query extends Component implements QueryInterface
public
function
getCollection
(
$db
=
null
)
public
function
getCollection
(
$db
=
null
)
{
{
if
(
$db
===
null
)
{
if
(
$db
===
null
)
{
$db
=
Yii
::
$app
->
getComponent
(
'mongo'
);
$db
=
Yii
::
$app
->
getComponent
(
'mongo
db
'
);
}
}
return
$db
->
getCollection
(
$this
->
from
);
return
$db
->
getCollection
(
$this
->
from
);
}
}
...
@@ -180,7 +180,7 @@ class Query extends Component implements QueryInterface
...
@@ -180,7 +180,7 @@ class Query extends Component implements QueryInterface
/**
/**
* Executes the query and returns all results as an array.
* Executes the query and returns all results as an array.
* @param Connection $db the Mongo connection used to execute the query.
* @param Connection $db the Mongo connection used to execute the query.
* If this parameter is not given, the `mongo` application component will be used.
* If this parameter is not given, the `mongo
db
` application component will be used.
* @return array the query results. If the query results in nothing, an empty array will be returned.
* @return array the query results. If the query results in nothing, an empty array will be returned.
*/
*/
public
function
all
(
$db
=
null
)
public
function
all
(
$db
=
null
)
...
@@ -192,7 +192,7 @@ class Query extends Component implements QueryInterface
...
@@ -192,7 +192,7 @@ class Query extends Component implements QueryInterface
/**
/**
* Executes the query and returns a single row of result.
* Executes the query and returns a single row of result.
* @param Connection $db the Mongo connection used to execute the query.
* @param Connection $db the Mongo connection used to execute the query.
* If this parameter is not given, the `mongo` application component will be used.
* If this parameter is not given, the `mongo
db
` application component will be used.
* @return array|boolean the first row (in terms of an array) of the query result. False is returned if the query
* @return array|boolean the first row (in terms of an array) of the query result. False is returned if the query
* results in nothing.
* results in nothing.
*/
*/
...
@@ -206,7 +206,7 @@ class Query extends Component implements QueryInterface
...
@@ -206,7 +206,7 @@ class Query extends Component implements QueryInterface
* Returns the number of records.
* Returns the number of records.
* @param string $q kept to match [[QueryInterface]], its value is ignored.
* @param string $q kept to match [[QueryInterface]], its value is ignored.
* @param Connection $db the Mongo connection used to execute the query.
* @param Connection $db the Mongo connection used to execute the query.
* If this parameter is not given, the `mongo` application component will be used.
* If this parameter is not given, the `mongo
db
` application component will be used.
* @return integer number of records
* @return integer number of records
* @throws Exception on failure.
* @throws Exception on failure.
*/
*/
...
@@ -229,7 +229,7 @@ class Query extends Component implements QueryInterface
...
@@ -229,7 +229,7 @@ class Query extends Component implements QueryInterface
/**
/**
* Returns a value indicating whether the query result contains any row of data.
* Returns a value indicating whether the query result contains any row of data.
* @param Connection $db the Mongo connection used to execute the query.
* @param Connection $db the Mongo connection used to execute the query.
* If this parameter is not given, the `mongo` application component will be used.
* If this parameter is not given, the `mongo
db
` application component will be used.
* @return boolean whether the query result contains any row of data.
* @return boolean whether the query result contains any row of data.
*/
*/
public
function
exists
(
$db
=
null
)
public
function
exists
(
$db
=
null
)
...
@@ -242,7 +242,7 @@ class Query extends Component implements QueryInterface
...
@@ -242,7 +242,7 @@ class Query extends Component implements QueryInterface
* @param string $q the column name.
* @param string $q the column name.
* Make sure you properly quote column names in the expression.
* Make sure you properly quote column names in the expression.
* @param Connection $db the Mongo connection used to execute the query.
* @param Connection $db the Mongo connection used to execute the query.
* If this parameter is not given, the `mongo` application component will be used.
* If this parameter is not given, the `mongo
db
` application component will be used.
* @return integer the sum of the specified column values
* @return integer the sum of the specified column values
*/
*/
public
function
sum
(
$q
,
$db
=
null
)
public
function
sum
(
$q
,
$db
=
null
)
...
@@ -255,7 +255,7 @@ class Query extends Component implements QueryInterface
...
@@ -255,7 +255,7 @@ class Query extends Component implements QueryInterface
* @param string $q the column name.
* @param string $q the column name.
* Make sure you properly quote column names in the expression.
* Make sure you properly quote column names in the expression.
* @param Connection $db the Mongo connection used to execute the query.
* @param Connection $db the Mongo connection used to execute the query.
* If this parameter is not given, the `mongo` application component will be used.
* If this parameter is not given, the `mongo
db
` application component will be used.
* @return integer the average of the specified column values.
* @return integer the average of the specified column values.
*/
*/
public
function
average
(
$q
,
$db
=
null
)
public
function
average
(
$q
,
$db
=
null
)
...
@@ -281,7 +281,7 @@ class Query extends Component implements QueryInterface
...
@@ -281,7 +281,7 @@ class Query extends Component implements QueryInterface
* @param string $q the column name.
* @param string $q the column name.
* Make sure you properly quote column names in the expression.
* Make sure you properly quote column names in the expression.
* @param Connection $db the Mongo connection used to execute the query.
* @param Connection $db the Mongo connection used to execute the query.
* If this parameter is not given, the `mongo` application component will be used.
* If this parameter is not given, the `mongo
db
` application component will be used.
* @return integer the maximum of the specified column values.
* @return integer the maximum of the specified column values.
*/
*/
public
function
max
(
$q
,
$db
=
null
)
public
function
max
(
$q
,
$db
=
null
)
...
@@ -323,7 +323,7 @@ class Query extends Component implements QueryInterface
...
@@ -323,7 +323,7 @@ class Query extends Component implements QueryInterface
* Returns a list of distinct values for the given column across a collection.
* Returns a list of distinct values for the given column across a collection.
* @param string $q column to use.
* @param string $q column to use.
* @param Connection $db the Mongo connection used to execute the query.
* @param Connection $db the Mongo connection used to execute the query.
* If this parameter is not given, the `mongo` application component will be used.
* If this parameter is not given, the `mongo
db
` application component will be used.
* @return array array of distinct values
* @return array array of distinct values
*/
*/
public
function
distinct
(
$q
,
$db
=
null
)
public
function
distinct
(
$q
,
$db
=
null
)
...
...
extensions/mongo/README.md
→
extensions/mongo
db
/README.md
View file @
9b5f3fab
...
@@ -21,12 +21,12 @@ The preferred way to install this extension is through [composer](http://getcomp
...
@@ -21,12 +21,12 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run
Either run
```
```
php composer.phar require yiisoft/yii2-mongo "*"
php composer.phar require yiisoft/yii2-mongo
db
"*"
```
```
or add
or add
```
```
"yiisoft/yii2-mongo": "*"
"yiisoft/yii2-mongo
db
": "*"
```
```
to the require section of your composer.json.
to the require section of your composer.json.
...
@@ -47,8 +47,8 @@ To use this extension, simply add the following code in your application configu
...
@@ -47,8 +47,8 @@ To use this extension, simply add the following code in your application configu
return
[
return
[
//....
//....
'components'
=>
[
'components'
=>
[
'mongo'
=>
[
'mongo
db
'
=>
[
'class'
=>
'\yii\mongo\Connection'
,
'class'
=>
'\yii\mongo
db
\Connection'
,
'dsn'
=>
'mongodb://developer:password@localhost:27017/mydatabase'
,
'dsn'
=>
'mongodb://developer:password@localhost:27017/mydatabase'
,
],
],
],
],
...
@@ -56,11 +56,11 @@ return [
...
@@ -56,11 +56,11 @@ return [
```
```
This extension provides ActiveRecord solution similar ot the
[
[\yii\db\ActiveRecord
]
].
This extension provides ActiveRecord solution similar ot the
[
[\yii\db\ActiveRecord
]
].
To declare an ActiveRecord class you need to extend
[
[\yii\mongo\ActiveRecord
]
] and
To declare an ActiveRecord class you need to extend
[
[\yii\mongo
db
\ActiveRecord
]
] and
implement the
`collectionName`
and 'attributes' methods:
implement the
`collectionName`
and 'attributes' methods:
```
php
```
php
use
yii\mongo\ActiveRecord
;
use
yii\mongo
db
\ActiveRecord
;
class
Customer
extends
ActiveRecord
class
Customer
extends
ActiveRecord
{
{
...
@@ -82,11 +82,11 @@ class Customer extends ActiveRecord
...
@@ -82,11 +82,11 @@ class Customer extends ActiveRecord
}
}
```
```
You can use
[
[\yii\data\ActiveDataProvider
]
] with the
[
[\yii\mongo
\Query
]
] and
[
[\yii\mongo
\ActiveQuery
]
]:
You can use
[
[\yii\data\ActiveDataProvider
]
] with the
[
[\yii\mongo
db\Query
]
] and
[
[\yii\mongodb
\ActiveQuery
]
]:
```
php
```
php
use
yii\data\ActiveDataProvider
;
use
yii\data\ActiveDataProvider
;
use
yii\mongo\Query
;
use
yii\mongo
db
\Query
;
$query
=
new
Query
;
$query
=
new
Query
;
$query
->
from
(
'customer'
)
->
where
([
'status'
=>
2
]);
$query
->
from
(
'customer'
)
->
where
([
'status'
=>
2
]);
...
...
extensions/mongo/composer.json
→
extensions/mongo
db
/composer.json
View file @
9b5f3fab
{
{
"name"
:
"yiisoft/yii2-mongo"
,
"name"
:
"yiisoft/yii2-mongo
db
"
,
"description"
:
"MongoDb extension for the Yii framework"
,
"description"
:
"MongoDb extension for the Yii framework"
,
"keywords"
:
[
"yii"
,
"mongo"
,
"mongodb"
,
"active-record"
],
"keywords"
:
[
"yii"
,
"mongo"
,
"mongodb"
,
"active-record"
],
"type"
:
"yii2-extension"
,
"type"
:
"yii2-extension"
,
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
"ext-mongo"
:
">=1.3.0"
"ext-mongo"
:
">=1.3.0"
},
},
"autoload"
:
{
"autoload"
:
{
"psr-0"
:
{
"yii
\\
mongo
\\
"
:
""
}
"psr-0"
:
{
"yii
\\
mongo
db
\\
"
:
""
}
},
},
"target-dir"
:
"yii/mongo"
"target-dir"
:
"yii/mongo
db
"
}
}
extensions/mongo/file/ActiveQuery.php
→
extensions/mongo
db
/file/ActiveQuery.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo\file
;
namespace
yii\mongo
db
\file
;
use
yii\db\ActiveQueryInterface
;
use
yii\db\ActiveQueryInterface
;
use
yii\db\ActiveQueryTrait
;
use
yii\db\ActiveQueryTrait
;
...
@@ -38,7 +38,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
...
@@ -38,7 +38,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
/**
/**
* Executes query and returns all results as an array.
* Executes query and returns all results as an array.
* @param \yii\mongo\Connection $db the Mongo connection used to execute the query.
* @param \yii\mongo
db
\Connection $db the Mongo connection used to execute the query.
* If null, the Mongo connection returned by [[modelClass]] will be used.
* If null, the Mongo connection returned by [[modelClass]] will be used.
* @return array the query results. If the query results in nothing, an empty array will be returned.
* @return array the query results. If the query results in nothing, an empty array will be returned.
*/
*/
...
@@ -59,7 +59,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
...
@@ -59,7 +59,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
/**
/**
* Executes query and returns a single row of result.
* Executes query and returns a single row of result.
* @param \yii\mongo\Connection $db the Mongo connection used to execute the query.
* @param \yii\mongo
db
\Connection $db the Mongo connection used to execute the query.
* If null, the Mongo connection returned by [[modelClass]] will be used.
* If null, the Mongo connection returned by [[modelClass]] will be used.
* @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]],
* @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]],
* the query result may be either an array or an ActiveRecord object. Null will be returned
* the query result may be either an array or an ActiveRecord object. Null will be returned
...
...
extensions/mongo/file/ActiveRecord.php
→
extensions/mongo
db
/file/ActiveRecord.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo\file
;
namespace
yii\mongo
db
\file
;
use
yii\base\InvalidParamException
;
use
yii\base\InvalidParamException
;
use
yii\db\StaleObjectException
;
use
yii\db\StaleObjectException
;
...
@@ -48,7 +48,7 @@ use yii\web\UploadedFile;
...
@@ -48,7 +48,7 @@ use yii\web\UploadedFile;
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
abstract
class
ActiveRecord
extends
\yii\mongo\ActiveRecord
abstract
class
ActiveRecord
extends
\yii\mongo
db
\ActiveRecord
{
{
/**
/**
* Creates an [[ActiveQuery]] instance.
* Creates an [[ActiveQuery]] instance.
...
...
extensions/mongo/file/ActiveRelation.php
→
extensions/mongo
db
/file/ActiveRelation.php
View file @
9b5f3fab
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo\file
;
namespace
yii\mongo
db
\file
;
use
yii\db\ActiveRelationInterface
;
use
yii\db\ActiveRelationInterface
;
use
yii\db\ActiveRelationTrait
;
use
yii\db\ActiveRelationTrait
;
...
...
extensions/mongo/file/Collection.php
→
extensions/mongo
db
/file/Collection.php
View file @
9b5f3fab
...
@@ -5,9 +5,9 @@
...
@@ -5,9 +5,9 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo\file
;
namespace
yii\mongo
db
\file
;
use
yii\mongo\Exception
;
use
yii\mongo
db
\Exception
;
use
Yii
;
use
Yii
;
/**
/**
...
@@ -23,27 +23,27 @@ use Yii;
...
@@ -23,27 +23,27 @@ use Yii;
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
Collection
extends
\yii\mongo\Collection
class
Collection
extends
\yii\mongo
db
\Collection
{
{
/**
/**
* @var \MongoGridFS Mongo GridFS collection instance.
* @var \MongoGridFS Mongo GridFS collection instance.
*/
*/
public
$mongoCollection
;
public
$mongoCollection
;
/**
/**
* @var \yii\mongo\Collection file chunks Mongo collection.
* @var \yii\mongo
db
\Collection file chunks Mongo collection.
*/
*/
private
$_chunkCollection
;
private
$_chunkCollection
;
/**
/**
* Returns the Mongo collection for the file chunks.
* Returns the Mongo collection for the file chunks.
* @param boolean $refresh whether to reload the collection instance even if it is found in the cache.
* @param boolean $refresh whether to reload the collection instance even if it is found in the cache.
* @return \yii\mongo\Collection mongo collection instance.
* @return \yii\mongo
db
\Collection mongo collection instance.
*/
*/
public
function
getChunkCollection
(
$refresh
=
false
)
public
function
getChunkCollection
(
$refresh
=
false
)
{
{
if
(
$refresh
||
!
is_object
(
$this
->
_chunkCollection
))
{
if
(
$refresh
||
!
is_object
(
$this
->
_chunkCollection
))
{
$this
->
_chunkCollection
=
Yii
::
createObject
([
$this
->
_chunkCollection
=
Yii
::
createObject
([
'class'
=>
'yii\mongo\Collection'
,
'class'
=>
'yii\mongo
db
\Collection'
,
'mongoCollection'
=>
$this
->
mongoCollection
->
chunks
'mongoCollection'
=>
$this
->
mongoCollection
->
chunks
]);
]);
}
}
...
...
extensions/mongo/file/Query.php
→
extensions/mongo
db
/file/Query.php
View file @
9b5f3fab
...
@@ -5,33 +5,31 @@
...
@@ -5,33 +5,31 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\mongo\file
;
namespace
yii\mongo
db
\file
;
use
Yii
;
use
Yii
;
use
yii\helpers\Json
;
use
yii\mongo\Exception
;
/**
/**
* Query represents Mongo "find" operation for GridFS collection.
* Query represents Mongo "find" operation for GridFS collection.
*
*
* Query behaves exactly as regular [[\yii\mongo\Query]].
* Query behaves exactly as regular [[\yii\mongo
db
\Query]].
* Found files will be represented as arrays of file document attributes with
* Found files will be represented as arrays of file document attributes with
* additional 'file' key, which stores [[\MongoGridFSFile]] instance.
* additional 'file' key, which stores [[\MongoGridFSFile]] instance.
*
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
Query
extends
\yii\mongo\Query
class
Query
extends
\yii\mongo
db
\Query
{
{
/**
/**
* Returns the Mongo collection for this query.
* Returns the Mongo collection for this query.
* @param \yii\mongo\Connection $db Mongo connection.
* @param \yii\mongo
db
\Connection $db Mongo connection.
* @return Collection collection instance.
* @return Collection collection instance.
*/
*/
public
function
getCollection
(
$db
=
null
)
public
function
getCollection
(
$db
=
null
)
{
{
if
(
$db
===
null
)
{
if
(
$db
===
null
)
{
$db
=
Yii
::
$app
->
getComponent
(
'mongo'
);
$db
=
Yii
::
$app
->
getComponent
(
'mongo
db
'
);
}
}
return
$db
->
getFileCollection
(
$this
->
from
);
return
$db
->
getFileCollection
(
$this
->
from
);
}
}
...
...
tests/unit/data/ar/mongo/ActiveRecord.php
→
tests/unit/data/ar/mongo
db
/ActiveRecord.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\data\ar\mongo
;
namespace
yiiunit\data\ar\mongo
db
;
/**
/**
* Test Mongo ActiveRecord
* Test Mongo ActiveRecord
*/
*/
class
ActiveRecord
extends
\yii\mongo\ActiveRecord
class
ActiveRecord
extends
\yii\mongo
db
\ActiveRecord
{
{
public
static
$db
;
public
static
$db
;
...
...
tests/unit/data/ar/mongo/Customer.php
→
tests/unit/data/ar/mongo
db
/Customer.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\data\ar\mongo
;
namespace
yiiunit\data\ar\mongo
db
;
class
Customer
extends
ActiveRecord
class
Customer
extends
ActiveRecord
{
{
...
...
tests/unit/data/ar/mongo/CustomerOrder.php
→
tests/unit/data/ar/mongo
db
/CustomerOrder.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\data\ar\mongo
;
namespace
yiiunit\data\ar\mongo
db
;
class
CustomerOrder
extends
ActiveRecord
class
CustomerOrder
extends
ActiveRecord
...
...
tests/unit/data/ar/mongo/file/ActiveRecord.php
→
tests/unit/data/ar/mongo
db
/file/ActiveRecord.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\data\ar\mongo\file
;
namespace
yiiunit\data\ar\mongo
db
\file
;
/**
/**
* Test Mongo ActiveRecord
* Test Mongo ActiveRecord
*/
*/
class
ActiveRecord
extends
\yii\mongo\file\ActiveRecord
class
ActiveRecord
extends
\yii\mongo
db
\file\ActiveRecord
{
{
public
static
$db
;
public
static
$db
;
...
...
tests/unit/data/ar/mongo/file/CustomerFile.php
→
tests/unit/data/ar/mongo
db
/file/CustomerFile.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\data\ar\mongo\file
;
namespace
yiiunit\data\ar\mongo
db
\file
;
class
CustomerFile
extends
ActiveRecord
class
CustomerFile
extends
ActiveRecord
{
{
...
...
tests/unit/data/config.php
View file @
9b5f3fab
...
@@ -52,7 +52,7 @@ return [
...
@@ -52,7 +52,7 @@ return [
'fixture'
=>
__DIR__
.
'/sphinx/source.sql'
,
'fixture'
=>
__DIR__
.
'/sphinx/source.sql'
,
],
],
],
],
'mongo'
=>
[
'mongo
db
'
=>
[
'dsn'
=>
'mongodb://travis:test@localhost:27017'
,
'dsn'
=>
'mongodb://travis:test@localhost:27017'
,
'defaultDatabaseName'
=>
'yii2test'
,
'defaultDatabaseName'
=>
'yii2test'
,
'options'
=>
[],
'options'
=>
[],
...
...
tests/unit/extensions/mongo/ActiveDataProviderTest.php
→
tests/unit/extensions/mongo
db
/ActiveDataProviderTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo
;
namespace
yiiunit\extensions\mongo
db
;
use
yii\data\ActiveDataProvider
;
use
yii\data\ActiveDataProvider
;
use
yii\mongo\Query
;
use
yii\mongo
db
\Query
;
use
yiiunit\data\ar\mongo\ActiveRecord
;
use
yiiunit\data\ar\mongo
db
\ActiveRecord
;
use
yiiunit\data\ar\mongo\Customer
;
use
yiiunit\data\ar\mongo
db
\Customer
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
ActiveDataProviderTest
extends
MongoTestCase
class
ActiveDataProviderTest
extends
Mongo
Db
TestCase
{
{
protected
function
setUp
()
protected
function
setUp
()
{
{
...
...
tests/unit/extensions/mongo/ActiveRecordTest.php
→
tests/unit/extensions/mongo
db
/ActiveRecordTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo
;
namespace
yiiunit\extensions\mongo
db
;
use
yii\mongo\ActiveQuery
;
use
yii\mongo
db
\ActiveQuery
;
use
yiiunit\data\ar\mongo\ActiveRecord
;
use
yiiunit\data\ar\mongo
db
\ActiveRecord
;
use
yiiunit\data\ar\mongo\Customer
;
use
yiiunit\data\ar\mongo
db
\Customer
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
ActiveRecordTest
extends
MongoTestCase
class
ActiveRecordTest
extends
Mongo
Db
TestCase
{
{
/**
/**
* @var array[] list of test rows.
* @var array[] list of test rows.
...
...
tests/unit/extensions/mongo/ActiveRelationTest.php
→
tests/unit/extensions/mongo
db
/ActiveRelationTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo
;
namespace
yiiunit\extensions\mongo
db
;
use
yiiunit\data\ar\mongo\ActiveRecord
;
use
yiiunit\data\ar\mongo
db
\ActiveRecord
;
use
yiiunit\data\ar\mongo\Customer
;
use
yiiunit\data\ar\mongo
db
\Customer
;
use
yiiunit\data\ar\mongo\CustomerOrder
;
use
yiiunit\data\ar\mongo
db
\CustomerOrder
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
ActiveRelationTest
extends
MongoTestCase
class
ActiveRelationTest
extends
Mongo
Db
TestCase
{
{
protected
function
setUp
()
protected
function
setUp
()
{
{
...
...
tests/unit/extensions/mongo/CollectionTest.php
→
tests/unit/extensions/mongo
db
/CollectionTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo
;
namespace
yiiunit\extensions\mongo
db
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
CollectionTest
extends
MongoTestCase
class
CollectionTest
extends
Mongo
Db
TestCase
{
{
protected
function
tearDown
()
protected
function
tearDown
()
{
{
...
@@ -21,7 +21,7 @@ class CollectionTest extends MongoTestCase
...
@@ -21,7 +21,7 @@ class CollectionTest extends MongoTestCase
$collectionName
=
'customer'
;
$collectionName
=
'customer'
;
$collection
=
$this
->
getConnection
()
->
getCollection
(
$collectionName
);
$collection
=
$this
->
getConnection
()
->
getCollection
(
$collectionName
);
$this
->
assertEquals
(
$collectionName
,
$collection
->
getName
());
$this
->
assertEquals
(
$collectionName
,
$collection
->
getName
());
$this
->
assertEquals
(
$this
->
mongoConfig
[
'defaultDatabaseName'
]
.
'.'
.
$collectionName
,
$collection
->
getFullName
());
$this
->
assertEquals
(
$this
->
mongo
Db
Config
[
'defaultDatabaseName'
]
.
'.'
.
$collectionName
,
$collection
->
getFullName
());
}
}
public
function
testFind
()
public
function
testFind
()
...
@@ -264,7 +264,7 @@ class CollectionTest extends MongoTestCase
...
@@ -264,7 +264,7 @@ class CollectionTest extends MongoTestCase
$indexInfo
=
$collection
->
mongoCollection
->
getIndexInfo
();
$indexInfo
=
$collection
->
mongoCollection
->
getIndexInfo
();
$this
->
assertEquals
(
1
,
count
(
$indexInfo
));
$this
->
assertEquals
(
1
,
count
(
$indexInfo
));
$this
->
setExpectedException
(
'\yii\mongo\Exception'
);
$this
->
setExpectedException
(
'\yii\mongo
db
\Exception'
);
$collection
->
dropIndex
(
'name'
);
$collection
->
dropIndex
(
'name'
);
}
}
...
...
tests/unit/extensions/mongo/ConnectionTest.php
→
tests/unit/extensions/mongo
db
/ConnectionTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo
;
namespace
yiiunit\extensions\mongo
db
;
use
yii\mongo\Collection
;
use
yii\mongo
db
\Collection
;
use
yii\mongo\file\Collection
as
FileCollection
;
use
yii\mongo
db
\file\Collection
as
FileCollection
;
use
yii\mongo\Connection
;
use
yii\mongo
db
\Connection
;
use
yii\mongo\Database
;
use
yii\mongo
db
\Database
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
ConnectionTest
extends
MongoTestCase
class
ConnectionTest
extends
Mongo
Db
TestCase
{
{
public
function
testConstruct
()
public
function
testConstruct
()
{
{
$connection
=
$this
->
getConnection
(
false
);
$connection
=
$this
->
getConnection
(
false
);
$params
=
$this
->
mongoConfig
;
$params
=
$this
->
mongo
Db
Config
;
$connection
->
open
();
$connection
->
open
();
...
@@ -41,7 +41,7 @@ class ConnectionTest extends MongoTestCase
...
@@ -41,7 +41,7 @@ class ConnectionTest extends MongoTestCase
$connection
=
new
Connection
;
$connection
=
new
Connection
;
$connection
->
dsn
=
'unknown::memory:'
;
$connection
->
dsn
=
'unknown::memory:'
;
$this
->
setExpectedException
(
'yii\mongo\Exception'
);
$this
->
setExpectedException
(
'yii\mongo
db
\Exception'
);
$connection
->
open
();
$connection
->
open
();
}
}
...
@@ -66,19 +66,19 @@ class ConnectionTest extends MongoTestCase
...
@@ -66,19 +66,19 @@ class ConnectionTest extends MongoTestCase
public
function
testGetDefaultDatabase
()
public
function
testGetDefaultDatabase
()
{
{
$connection
=
new
Connection
();
$connection
=
new
Connection
();
$connection
->
dsn
=
$this
->
mongoConfig
[
'dsn'
];
$connection
->
dsn
=
$this
->
mongo
Db
Config
[
'dsn'
];
$connection
->
defaultDatabaseName
=
$this
->
mongoConfig
[
'defaultDatabaseName'
];
$connection
->
defaultDatabaseName
=
$this
->
mongo
Db
Config
[
'defaultDatabaseName'
];
$database
=
$connection
->
getDatabase
();
$database
=
$connection
->
getDatabase
();
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to get default database!'
);
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to get default database!'
);
$connection
=
new
Connection
();
$connection
=
new
Connection
();
$connection
->
dsn
=
$this
->
mongoConfig
[
'dsn'
];
$connection
->
dsn
=
$this
->
mongo
Db
Config
[
'dsn'
];
$connection
->
options
=
[
'db'
=>
$this
->
mongoConfig
[
'defaultDatabaseName'
]];
$connection
->
options
=
[
'db'
=>
$this
->
mongo
Db
Config
[
'defaultDatabaseName'
]];
$database
=
$connection
->
getDatabase
();
$database
=
$connection
->
getDatabase
();
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to determine default database from options!'
);
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to determine default database from options!'
);
$connection
=
new
Connection
();
$connection
=
new
Connection
();
$connection
->
dsn
=
$this
->
mongo
Config
[
'dsn'
]
.
'/'
.
$this
->
mongo
Config
[
'defaultDatabaseName'
];
$connection
->
dsn
=
$this
->
mongo
DbConfig
[
'dsn'
]
.
'/'
.
$this
->
mongoDb
Config
[
'defaultDatabaseName'
];
$database
=
$connection
->
getDatabase
();
$database
=
$connection
->
getDatabase
();
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to determine default database from dsn!'
);
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to determine default database from dsn!'
);
}
}
...
...
tests/unit/extensions/mongo/DatabaseTest.php
→
tests/unit/extensions/mongo
db
/DatabaseTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo
;
namespace
yiiunit\extensions\mongo
db
;
use
yii\mongo\Collection
;
use
yii\mongo
db
\Collection
;
use
yii\mongo\file\Collection
as
FileCollection
;
use
yii\mongo
db
\file\Collection
as
FileCollection
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
DatabaseTest
extends
MongoTestCase
class
DatabaseTest
extends
Mongo
Db
TestCase
{
{
protected
function
tearDown
()
protected
function
tearDown
()
{
{
...
...
tests/unit/extensions/mongo
/Mongo
TestCase.php
→
tests/unit/extensions/mongo
db/MongoDb
TestCase.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo
;
namespace
yiiunit\extensions\mongo
db
;
use
yii\helpers\FileHelper
;
use
yii\helpers\FileHelper
;
use
yii\mongo\Connection
;
use
yii\mongo
db
\Connection
;
use
Yii
;
use
Yii
;
use
yii\mongo\Exception
;
use
yii\mongo
db
\Exception
;
use
yiiunit\TestCase
;
use
yiiunit\TestCase
;
class
MongoTestCase
extends
TestCase
class
Mongo
Db
TestCase
extends
TestCase
{
{
/**
/**
* @var array Mongo connection configuration.
* @var array Mongo connection configuration.
*/
*/
protected
$mongoConfig
=
[
protected
$mongo
Db
Config
=
[
'dsn'
=>
'mongodb://localhost:27017'
,
'dsn'
=>
'mongodb://localhost:27017'
,
'defaultDatabaseName'
=>
'yii2test'
,
'defaultDatabaseName'
=>
'yii2test'
,
'options'
=>
[],
'options'
=>
[],
...
@@ -21,7 +21,7 @@ class MongoTestCase extends TestCase
...
@@ -21,7 +21,7 @@ class MongoTestCase extends TestCase
/**
/**
* @var Connection Mongo connection instance.
* @var Connection Mongo connection instance.
*/
*/
protected
$mongo
;
protected
$mongo
db
;
public
static
function
setUpBeforeClass
()
public
static
function
setUpBeforeClass
()
{
{
...
@@ -34,9 +34,9 @@ class MongoTestCase extends TestCase
...
@@ -34,9 +34,9 @@ class MongoTestCase extends TestCase
if
(
!
extension_loaded
(
'mongo'
))
{
if
(
!
extension_loaded
(
'mongo'
))
{
$this
->
markTestSkipped
(
'mongo extension required.'
);
$this
->
markTestSkipped
(
'mongo extension required.'
);
}
}
$config
=
$this
->
getParam
(
'mongo'
);
$config
=
$this
->
getParam
(
'mongo
db
'
);
if
(
!
empty
(
$config
))
{
if
(
!
empty
(
$config
))
{
$this
->
mongoConfig
=
$config
;
$this
->
mongo
Db
Config
=
$config
;
}
}
$this
->
mockApplication
();
$this
->
mockApplication
();
static
::
loadClassMap
();
static
::
loadClassMap
();
...
@@ -44,8 +44,8 @@ class MongoTestCase extends TestCase
...
@@ -44,8 +44,8 @@ class MongoTestCase extends TestCase
protected
function
tearDown
()
protected
function
tearDown
()
{
{
if
(
$this
->
mongo
)
{
if
(
$this
->
mongo
db
)
{
$this
->
mongo
->
close
();
$this
->
mongo
db
->
close
();
}
}
$this
->
destroyApplication
();
$this
->
destroyApplication
();
}
}
...
@@ -56,8 +56,8 @@ class MongoTestCase extends TestCase
...
@@ -56,8 +56,8 @@ class MongoTestCase extends TestCase
*/
*/
protected
static
function
loadClassMap
()
protected
static
function
loadClassMap
()
{
{
$baseNameSpace
=
'yii/mongo'
;
$baseNameSpace
=
'yii/mongo
db
'
;
$basePath
=
realpath
(
__DIR__
.
'/../../../../extensions/mongo'
);
$basePath
=
realpath
(
__DIR__
.
'/../../../../extensions/mongo
db
'
);
$files
=
FileHelper
::
findFiles
(
$basePath
);
$files
=
FileHelper
::
findFiles
(
$basePath
);
foreach
(
$files
as
$file
)
{
foreach
(
$files
as
$file
)
{
$classRelativePath
=
str_replace
(
$basePath
,
''
,
$file
);
$classRelativePath
=
str_replace
(
$basePath
,
''
,
$file
);
...
@@ -69,23 +69,23 @@ class MongoTestCase extends TestCase
...
@@ -69,23 +69,23 @@ class MongoTestCase extends TestCase
/**
/**
* @param boolean $reset whether to clean up the test database
* @param boolean $reset whether to clean up the test database
* @param boolean $open whether to open test database
* @param boolean $open whether to open test database
* @return \yii\mongo\Connection
* @return \yii\mongo
db
\Connection
*/
*/
public
function
getConnection
(
$reset
=
false
,
$open
=
true
)
public
function
getConnection
(
$reset
=
false
,
$open
=
true
)
{
{
if
(
!
$reset
&&
$this
->
mongo
)
{
if
(
!
$reset
&&
$this
->
mongo
db
)
{
return
$this
->
mongo
;
return
$this
->
mongo
db
;
}
}
$db
=
new
Connection
;
$db
=
new
Connection
;
$db
->
dsn
=
$this
->
mongoConfig
[
'dsn'
];
$db
->
dsn
=
$this
->
mongo
Db
Config
[
'dsn'
];
$db
->
defaultDatabaseName
=
$this
->
mongoConfig
[
'defaultDatabaseName'
];
$db
->
defaultDatabaseName
=
$this
->
mongo
Db
Config
[
'defaultDatabaseName'
];
if
(
isset
(
$this
->
mongoConfig
[
'options'
]))
{
if
(
isset
(
$this
->
mongo
Db
Config
[
'options'
]))
{
$db
->
options
=
$this
->
mongoConfig
[
'options'
];
$db
->
options
=
$this
->
mongo
Db
Config
[
'options'
];
}
}
if
(
$open
)
{
if
(
$open
)
{
$db
->
open
();
$db
->
open
();
}
}
$this
->
mongo
=
$db
;
$this
->
mongo
db
=
$db
;
return
$db
;
return
$db
;
}
}
...
@@ -95,9 +95,9 @@ class MongoTestCase extends TestCase
...
@@ -95,9 +95,9 @@ class MongoTestCase extends TestCase
*/
*/
protected
function
dropCollection
(
$name
)
protected
function
dropCollection
(
$name
)
{
{
if
(
$this
->
mongo
)
{
if
(
$this
->
mongo
db
)
{
try
{
try
{
$this
->
mongo
->
getCollection
(
$name
)
->
drop
();
$this
->
mongo
db
->
getCollection
(
$name
)
->
drop
();
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
// shut down exception
// shut down exception
}
}
...
@@ -110,9 +110,9 @@ class MongoTestCase extends TestCase
...
@@ -110,9 +110,9 @@ class MongoTestCase extends TestCase
*/
*/
protected
function
dropFileCollection
(
$name
=
'fs'
)
protected
function
dropFileCollection
(
$name
=
'fs'
)
{
{
if
(
$this
->
mongo
)
{
if
(
$this
->
mongo
db
)
{
try
{
try
{
$this
->
mongo
->
getFileCollection
(
$name
)
->
drop
();
$this
->
mongo
db
->
getFileCollection
(
$name
)
->
drop
();
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
// shut down exception
// shut down exception
}
}
...
@@ -121,7 +121,7 @@ class MongoTestCase extends TestCase
...
@@ -121,7 +121,7 @@ class MongoTestCase extends TestCase
/**
/**
* Finds all records in collection.
* Finds all records in collection.
* @param \yii\mongo\Collection $collection
* @param \yii\mongo
db
\Collection $collection
* @param array $condition
* @param array $condition
* @param array $fields
* @param array $fields
* @return array rows
* @return array rows
...
...
tests/unit/extensions/mongo/QueryRunTest.php
→
tests/unit/extensions/mongo
db
/QueryRunTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo
;
namespace
yiiunit\extensions\mongo
db
;
use
yii\mongo\Query
;
use
yii\mongo
db
\Query
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
QueryRunTest
extends
MongoTestCase
class
QueryRunTest
extends
Mongo
Db
TestCase
{
{
protected
function
setUp
()
protected
function
setUp
()
{
{
...
...
tests/unit/extensions/mongo/QueryTest.php
→
tests/unit/extensions/mongo
db
/QueryTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo
;
namespace
yiiunit\extensions\mongo
db
;
use
yii\mongo\Query
;
use
yii\mongo
db
\Query
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
QueryTest
extends
MongoTestCase
class
QueryTest
extends
Mongo
Db
TestCase
{
{
public
function
testSelect
()
public
function
testSelect
()
{
{
...
...
tests/unit/extensions/mongo/file/ActiveRecordTest.php
→
tests/unit/extensions/mongo
db
/file/ActiveRecordTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo\file
;
namespace
yiiunit\extensions\mongo
db
\file
;
use
Yii
;
use
Yii
;
use
yii\helpers\FileHelper
;
use
yii\helpers\FileHelper
;
use
yiiunit\extensions\mongo
\Mongo
TestCase
;
use
yiiunit\extensions\mongo
db\MongoDb
TestCase
;
use
yii\mongo\file\ActiveQuery
;
use
yii\mongo
db
\file\ActiveQuery
;
use
yiiunit\data\ar\mongo\file\ActiveRecord
;
use
yiiunit\data\ar\mongo
db
\file\ActiveRecord
;
use
yiiunit\data\ar\mongo\file\CustomerFile
;
use
yiiunit\data\ar\mongo
db
\file\CustomerFile
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
ActiveRecordTest
extends
MongoTestCase
class
ActiveRecordTest
extends
Mongo
Db
TestCase
{
{
/**
/**
* @var array[] list of test rows.
* @var array[] list of test rows.
...
...
tests/unit/extensions/mongo/file/CollectionTest.php
→
tests/unit/extensions/mongo
db
/file/CollectionTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo\file
;
namespace
yiiunit\extensions\mongo
db
\file
;
use
yiiunit\extensions\mongo
\Mongo
TestCase
;
use
yiiunit\extensions\mongo
db\MongoDb
TestCase
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
CollectionTest
extends
MongoTestCase
class
CollectionTest
extends
Mongo
Db
TestCase
{
{
protected
function
tearDown
()
protected
function
tearDown
()
{
{
...
@@ -21,7 +21,7 @@ class CollectionTest extends MongoTestCase
...
@@ -21,7 +21,7 @@ class CollectionTest extends MongoTestCase
{
{
$collection
=
$this
->
getConnection
()
->
getFileCollection
();
$collection
=
$this
->
getConnection
()
->
getFileCollection
();
$chunkCollection
=
$collection
->
getChunkCollection
();
$chunkCollection
=
$collection
->
getChunkCollection
();
$this
->
assertTrue
(
$chunkCollection
instanceof
\yii\mongo\Collection
);
$this
->
assertTrue
(
$chunkCollection
instanceof
\yii\mongo
db
\Collection
);
$this
->
assertTrue
(
$chunkCollection
->
mongoCollection
instanceof
\MongoCollection
);
$this
->
assertTrue
(
$chunkCollection
->
mongoCollection
instanceof
\MongoCollection
);
}
}
...
...
tests/unit/extensions/mongo/file/QueryTest.php
→
tests/unit/extensions/mongo
db
/file/QueryTest.php
View file @
9b5f3fab
<?php
<?php
namespace
yiiunit\extensions\mongo\file
;
namespace
yiiunit\extensions\mongo
db
\file
;
use
yii\mongo\file\Query
;
use
yii\mongo
db
\file\Query
;
use
yiiunit\extensions\mongo
\Mongo
TestCase
;
use
yiiunit\extensions\mongo
db\MongoDb
TestCase
;
/**
/**
* @group mongo
* @group mongo
*/
*/
class
QueryTest
extends
MongoTestCase
class
QueryTest
extends
Mongo
Db
TestCase
{
{
protected
function
setUp
()
protected
function
setUp
()
{
{
...
...
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