Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
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
sinan
laravel-mongodb
Commits
23bc58de
Commit
23bc58de
authored
Jul 27, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweak tests to make less database connections
parent
e8027c71
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
31 deletions
+32
-31
Connection.php
src/Jenssegers/Mongodb/Connection.php
+1
-1
CacheTest.php
tests/CacheTest.php
+4
-6
ConnectionTest.php
tests/ConnectionTest.php
+21
-13
ModelQueryTest.php
tests/ModelQueryTest.php
+1
-2
ModelTest.php
tests/ModelTest.php
+2
-4
QueryTest.php
tests/QueryTest.php
+2
-4
app.php
tests/app.php
+1
-1
No files found.
src/Jenssegers/Mongodb/Connection.php
View file @
23bc58de
...
...
@@ -126,7 +126,7 @@ class Connection extends \Illuminate\Database\Connection {
*/
public
function
__call
(
$method
,
$parameters
)
{
return
call_user_func_array
(
array
(
$this
->
connection
,
$method
),
$parameters
);
return
call_user_func_array
(
array
(
$this
->
db
,
$method
),
$parameters
);
}
}
\ No newline at end of file
tests/CacheTest.php
View file @
23bc58de
<?php
require_once
(
'vendor/autoload.php'
);
require_once
(
'models/User.php'
);
require_once
(
'tests/app.php'
);
use
Jenssegers\Mongodb\Facades\DB
;
class
CacheTest
extends
PHPUnit_Framework_TestCase
{
protected
$app
;
public
function
setUp
()
{
include
(
'tests/app.php'
);
$this
->
app
=
$app
;
// test data
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'age'
=>
35
,
'title'
=>
'admin'
));
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'age'
=>
33
,
'title'
=>
'admin'
));
...
...
@@ -37,8 +33,10 @@ class CacheTest extends PHPUnit_Framework_TestCase {
$users
=
User
::
where
(
'age'
,
'>'
,
10
)
->
remember
(
10
,
'db.users'
)
->
get
();
$this
->
assertEquals
(
3
,
count
(
$users
));
global
$app
;
# get from cache driver
$cache
=
$
this
->
app
[
'cache'
];
$cache
=
$app
[
'cache'
];
$users
=
$cache
->
get
(
'db.users'
);
$this
->
assertEquals
(
3
,
count
(
$users
));
}
...
...
tests/ConnectionTest.php
View file @
23bc58de
<?php
require_once
(
'vendor/autoload.php'
);
require_once
(
'tests/app.php'
);
use
Jenssegers\Mongodb\Facades\DB
;
use
Jenssegers\Mongodb\Connection
;
class
ConnectionTest
extends
PHPUnit_Framework_TestCase
{
p
rivate
$connection
;
p
ublic
function
setUp
()
{}
public
function
setUp
()
{
include
(
'tests/app.php'
);
$this
->
connection
=
new
Connection
(
$app
[
'config'
][
'database.connections'
][
'mongodb'
]);
}
public
function
tearDown
()
{}
public
function
te
arDow
n
()
public
function
te
stConnectio
n
()
{
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Connection'
,
$connection
);
$c1
=
DB
::
connection
(
'mongodb'
);
$c2
=
DB
::
connection
(
'mongodb'
);
$this
->
assertEquals
(
$c1
,
$c2
);
$c1
=
DB
::
connection
(
'mongodb'
);
$c2
=
DB
::
reconnect
(
'mongodb'
);
$this
->
assertNotEquals
(
$c1
,
$c2
);
}
public
function
testDb
()
{
$
db
=
$this
->
connection
->
getDb
(
);
$this
->
assertInstanceOf
(
'MongoDB'
,
$
db
);
$
connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
'MongoDB'
,
$
connection
->
getDb
()
);
}
public
function
testCollection
()
{
$collection
=
$this
->
connection
->
getCollection
(
'unittest'
);
$collection
=
DB
::
connection
(
'mongodb'
)
->
getCollection
(
'unittest'
);
$this
->
assertInstanceOf
(
'MongoCollection'
,
$collection
);
$collection
=
$this
->
connection
->
collection
(
'unittests'
);
$collection
=
DB
::
connection
(
'mongodb'
)
->
collection
(
'unittests'
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Builder'
,
$collection
);
$collection
=
$this
->
connection
->
table
(
'unittests'
);
$collection
=
DB
::
connection
(
'mongodb'
)
->
table
(
'unittests'
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Builder'
,
$collection
);
}
public
function
testDynamic
()
{
$dbs
=
$this
->
connection
->
listDB
s
();
$dbs
=
DB
::
connection
(
'mongodb'
)
->
listCollection
s
();
$this
->
assertTrue
(
is_array
(
$dbs
));
}
...
...
tests/ModelQueryTest.php
View file @
23bc58de
<?php
require_once
(
'vendor/autoload.php'
);
require_once
(
'models/User.php'
);
require_once
(
'tests/app.php'
);
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Model
;
...
...
@@ -10,8 +11,6 @@ class ModelQueryTest extends PHPUnit_Framework_TestCase {
public
function
setUp
()
{
include
(
'tests/app.php'
);
// test data
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'age'
=>
35
,
'title'
=>
'admin'
));
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'age'
=>
33
,
'title'
=>
'admin'
));
...
...
tests/ModelTest.php
View file @
23bc58de
...
...
@@ -3,6 +3,7 @@ require_once('vendor/autoload.php');
require_once
(
'models/User.php'
);
require_once
(
'models/Soft.php'
);
require_once
(
'models/Book.php'
);
require_once
(
'tests/app.php'
);
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Model
;
...
...
@@ -10,10 +11,7 @@ use Jenssegers\Mongodb\DatabaseManager;
class
ModelTest
extends
PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
include
(
'tests/app.php'
);
}
public
function
setUp
()
{}
public
function
tearDown
()
{
...
...
tests/QueryTest.php
View file @
23bc58de
<?php
require_once
(
'vendor/autoload.php'
);
require_once
(
'tests/app.php'
);
use
Jenssegers\Mongodb\Facades\DB
;
class
QueryTest
extends
PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
include
(
'tests/app.php'
);
}
public
function
setUp
()
{}
public
function
tearDown
()
{
...
...
tests/app.php
View file @
23bc58de
...
...
@@ -27,5 +27,5 @@ $app['config']['database.connections']['mongodb'] = array(
$app
[
'mongodb'
]
=
new
DatabaseManager
(
$app
);
# Static setup
Model
::
setConnectionResolver
(
new
DatabaseManager
(
$app
)
);
Model
::
setConnectionResolver
(
$app
[
'mongodb'
]
);
DB
::
setFacadeApplication
(
$app
);
\ 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