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
c61ebcc5
Commit
c61ebcc5
authored
Nov 25, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mongo connection advanced.
parent
ae0f04be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
Connection.php
extensions/mongo/Connection.php
+11
-0
ConnectionTest.php
tests/unit/extensions/mongo/ConnectionTest.php
+26
-2
No files found.
extensions/mongo/Connection.php
View file @
c61ebcc5
...
...
@@ -15,6 +15,8 @@ use Yii;
/**
* Class Connection
*
* @property boolean $isActive Whether the Mongo connection is established. This property is read-only.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
...
...
@@ -50,6 +52,15 @@ class Connection extends Component
public
$dbName
;
/**
* Returns a value indicating whether the Mongo connection is established.
* @return boolean whether the Mongo connection is established
*/
public
function
getIsActive
()
{
return
is_object
(
$this
->
client
)
&&
$this
->
client
->
connected
;
}
/**
* Establishes a Mongo connection.
* It does nothing if a Mongo connection has already been established.
* @throws Exception if connection fails
...
...
tests/unit/extensions/mongo/ConnectionTest.php
View file @
c61ebcc5
...
...
@@ -3,6 +3,8 @@
namespace
yiiunit\extensions\mongo
;
use
yii\mongo\Connection
;
class
ConnectionTest
extends
MongoTestCase
{
public
function
testConstruct
()
...
...
@@ -13,7 +15,28 @@ class ConnectionTest extends MongoTestCase
$connection
->
open
();
$this
->
assertEquals
(
$params
[
'dsn'
],
$connection
->
dsn
);
//$this->assertEquals($params['username'], $connection->username);
//$this->assertEquals($params['password'], $connection->password);
$this
->
assertEquals
(
$params
[
'dbName'
],
$connection
->
dbName
);
$this
->
assertEquals
(
$params
[
'options'
],
$connection
->
options
);
}
public
function
testOpenClose
()
{
$connection
=
$this
->
getConnection
(
false
,
false
);
$this
->
assertFalse
(
$connection
->
isActive
);
$this
->
assertEquals
(
null
,
$connection
->
client
);
$connection
->
open
();
$this
->
assertTrue
(
$connection
->
isActive
);
$this
->
assertTrue
(
is_object
(
$connection
->
client
));
$connection
->
close
();
$this
->
assertFalse
(
$connection
->
isActive
);
$this
->
assertEquals
(
null
,
$connection
->
client
);
$connection
=
new
Connection
;
$connection
->
dsn
=
'unknown::memory:'
;
$this
->
setExpectedException
(
'yii\db\Exception'
);
$connection
->
open
();
}
}
\ 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