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
12adb390
Unverified
Commit
12adb390
authored
Feb 26, 2020
by
Stas
Committed by
GitHub
Feb 26, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1972 from divine/refactor_connection_tests
[refactor] tests
parents
22a9e3be
cf6326ec
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
36 additions
and
76 deletions
+36
-76
AuthTest.php
tests/AuthTest.php
+1
-1
ConnectionTest.php
tests/ConnectionTest.php
+15
-34
EmbeddedRelationsTest.php
tests/EmbeddedRelationsTest.php
+1
-24
ModelTest.php
tests/ModelTest.php
+14
-12
QueryBuilderTest.php
tests/QueryBuilderTest.php
+0
-1
QueueTest.php
tests/QueueTest.php
+2
-1
RelationsTest.php
tests/RelationsTest.php
+3
-3
No files found.
tests/AuthTest.php
View file @
12adb390
...
...
@@ -15,7 +15,7 @@ class AuthTest extends TestCase
public
function
testAuthAttempt
()
{
$user
=
User
::
create
([
User
::
create
([
'name'
=>
'John Doe'
,
'email'
=>
'john@doe.com'
,
'password'
=>
Hash
::
make
(
'foobar'
),
...
...
tests/ConnectionTest.php
View file @
12adb390
...
...
@@ -2,13 +2,19 @@
declare
(
strict_types
=
1
);
use
Illuminate\Support\Facades\DB
;
use
Jenssegers\Mongodb\Collection
;
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Query\Builder
;
use
Jenssegers\Mongodb\Schema\Builder
as
SchemaBuilder
;
use
MongoDB\Client
;
use
MongoDB\Database
;
class
ConnectionTest
extends
TestCase
{
public
function
testConnection
()
{
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
\Jenssegers\Mongodb\
Connection
::
class
,
$connection
);
$this
->
assertInstanceOf
(
Connection
::
class
,
$connection
);
}
public
function
testReconnect
()
...
...
@@ -26,54 +32,29 @@ class ConnectionTest extends TestCase
public
function
testDb
()
{
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
\MongoDB\Database
::
class
,
$connection
->
getMongoDB
());
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
\MongoDB\Client
::
class
,
$connection
->
getMongoClient
());
$this
->
assertInstanceOf
(
Database
::
class
,
$connection
->
getMongoDB
());
$this
->
assertInstanceOf
(
Client
::
class
,
$connection
->
getMongoClient
());
}
public
function
testDsnDb
()
{
$connection
=
DB
::
connection
(
'dsn_mongodb_db'
);
$this
->
assertInstanceOf
(
\MongoDB\Database
::
class
,
$connection
->
getMongoDB
());
$connection
=
DB
::
connection
(
'dsn_mongodb_db'
);
$this
->
assertInstanceOf
(
\MongoDB\Client
::
class
,
$connection
->
getMongoClient
());
$this
->
assertInstanceOf
(
Database
::
class
,
$connection
->
getMongoDB
());
$this
->
assertInstanceOf
(
Client
::
class
,
$connection
->
getMongoClient
());
}
public
function
testCollection
()
{
$collection
=
DB
::
connection
(
'mongodb'
)
->
getCollection
(
'unittest'
);
$this
->
assertInstanceOf
(
Jenssegers\Mongodb\
Collection
::
class
,
$collection
);
$this
->
assertInstanceOf
(
Collection
::
class
,
$collection
);
$collection
=
DB
::
connection
(
'mongodb'
)
->
collection
(
'unittests'
);
$this
->
assertInstanceOf
(
Jenssegers\Mongodb\Query\
Builder
::
class
,
$collection
);
$this
->
assertInstanceOf
(
Builder
::
class
,
$collection
);
$collection
=
DB
::
connection
(
'mongodb'
)
->
table
(
'unittests'
);
$this
->
assertInstanceOf
(
Jenssegers\Mongodb\Query\
Builder
::
class
,
$collection
);
$this
->
assertInstanceOf
(
Builder
::
class
,
$collection
);
}
// public function testDynamic()
// {
// $dbs = DB::connection('mongodb')->listCollections();
// $this->assertIsArray($dbs);
// }
// public function testMultipleConnections()
// {
// global $app;
// # Add fake host
// $db = $app['config']['database.connections']['mongodb'];
// $db['host'] = array($db['host'], '1.2.3.4');
// $connection = new Connection($db);
// $mongoclient = $connection->getMongoClient();
// $hosts = $mongoclient->getHosts();
// $this->assertCount(1, $hosts);
// }
public
function
testQueryLog
()
{
DB
::
enableQueryLog
();
...
...
@@ -99,7 +80,7 @@ class ConnectionTest extends TestCase
public
function
testSchemaBuilder
()
{
$schema
=
DB
::
connection
(
'mongodb'
)
->
getSchemaBuilder
();
$this
->
assertInstanceOf
(
\Jenssegers\Mongodb\Schema\
Builder
::
class
,
$schema
);
$this
->
assertInstanceOf
(
Schema
Builder
::
class
,
$schema
);
}
public
function
testDriverName
()
...
...
tests/EmbeddedRelationsTest.php
View file @
12adb390
...
...
@@ -42,7 +42,7 @@ class EmbeddedRelationsTest extends TestCase
$address
->
unsetEventDispatcher
();
$this
->
assertNotNull
(
$user
->
addresses
);
$this
->
assertInstanceOf
(
\Illuminate\Database\Eloquent\
Collection
::
class
,
$user
->
addresses
);
$this
->
assertInstanceOf
(
Collection
::
class
,
$user
->
addresses
);
$this
->
assertEquals
([
'London'
],
$user
->
addresses
->
pluck
(
'city'
)
->
all
());
$this
->
assertInstanceOf
(
DateTime
::
class
,
$address
->
created_at
);
$this
->
assertInstanceOf
(
DateTime
::
class
,
$address
->
updated_at
);
...
...
@@ -103,29 +103,6 @@ class EmbeddedRelationsTest extends TestCase
$this
->
assertEquals
([
'London'
,
'Manhattan'
,
'Bruxelles'
],
$freshUser
->
addresses
->
pluck
(
'city'
)
->
all
());
}
// public function testEmbedsManySaveModel()
// {
// $user = User::create(['name' => 'John Doe']);
// $address = new Address(['city' => 'London']);
// $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class));
// $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
// $events->shouldReceive('until')->once()->with('eloquent.creating: ' . get_class($address), $address)->andReturn(true);
// $events->shouldReceive('dispatch')->once()->with('eloquent.created: ' . get_class($address), $address);
// $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address);
// $address->save();
// $address->setEventDispatcher($events = Mockery::mock(\Illuminate\Events\Dispatcher::class));
// $events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
// $events->shouldReceive('until')->once()->with('eloquent.updating: ' . get_class($address), $address)->andReturn(true);
// $events->shouldReceive('dispatch')->once()->with('eloquent.updated: ' . get_class($address), $address);
// $events->shouldReceive('dispatch')->once()->with('eloquent.saved: ' . get_class($address), $address);
// $address->city = 'Paris';
// $address->save();
// }
public
function
testEmbedsToArray
()
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
...
...
tests/ModelTest.php
View file @
12adb390
...
...
@@ -2,8 +2,10 @@
declare
(
strict_types
=
1
);
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Collection
as
EloquentCollection
;
use
Illuminate\Database\Eloquent\ModelNotFoundException
;
use
Jenssegers\Mongodb\Collection
;
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Eloquent\Model
;
use
MongoDB\BSON\ObjectID
;
use
MongoDB\BSON\UTCDateTime
;
...
...
@@ -22,7 +24,7 @@ class ModelTest extends TestCase
{
$user
=
new
User
;
$this
->
assertInstanceOf
(
Model
::
class
,
$user
);
$this
->
assertInstanceOf
(
\Jenssegers\Mongodb\
Connection
::
class
,
$user
->
getConnection
());
$this
->
assertInstanceOf
(
Connection
::
class
,
$user
->
getConnection
());
$this
->
assertFalse
(
$user
->
exists
);
$this
->
assertEquals
(
'users'
,
$user
->
getTable
());
$this
->
assertEquals
(
'_id'
,
$user
->
getKeyName
());
...
...
@@ -196,7 +198,7 @@ class ModelTest extends TestCase
$users
=
User
::
get
();
$this
->
assertCount
(
2
,
$users
);
$this
->
assertInstanceOf
(
Collection
::
class
,
$users
);
$this
->
assertInstanceOf
(
Eloquent
Collection
::
class
,
$users
);
$this
->
assertInstanceOf
(
Model
::
class
,
$users
[
0
]);
}
...
...
@@ -216,7 +218,7 @@ class ModelTest extends TestCase
public
function
testNoDocument
()
:
void
{
$items
=
Item
::
where
(
'name'
,
'nothing'
)
->
get
();
$this
->
assertInstanceOf
(
Collection
::
class
,
$items
);
$this
->
assertInstanceOf
(
Eloquent
Collection
::
class
,
$items
);
$this
->
assertEquals
(
0
,
$items
->
count
());
$item
=
Item
::
where
(
'name'
,
'nothing'
)
->
first
();
...
...
@@ -436,11 +438,11 @@ class ModelTest extends TestCase
public
function
testCarbonDateMockingWorks
()
{
$fakeDate
=
\Carbon\
Carbon
::
createFromDate
(
2000
,
01
,
01
);
$fakeDate
=
Carbon
::
createFromDate
(
2000
,
01
,
01
);
Carbon
::
setTestNow
(
$fakeDate
);
$item
=
Item
::
create
([
'name'
=>
'sword'
]);
$this
->
assertLessThan
(
1
,
$fakeDate
->
diffInSeconds
(
$item
->
created_at
));
}
...
...
@@ -487,24 +489,24 @@ class ModelTest extends TestCase
User
::
create
([
'name'
=>
'Jane Doe'
,
'age'
=>
35
]);
User
::
create
([
'name'
=>
'Harry Hoe'
,
'age'
=>
15
]);
$users
=
User
::
raw
(
function
(
\Jenssegers\Mongodb\
Collection
$collection
)
{
$users
=
User
::
raw
(
function
(
Collection
$collection
)
{
return
$collection
->
find
([
'age'
=>
35
]);
});
$this
->
assertInstanceOf
(
Collection
::
class
,
$users
);
$this
->
assertInstanceOf
(
Eloquent
Collection
::
class
,
$users
);
$this
->
assertInstanceOf
(
Model
::
class
,
$users
[
0
]);
$user
=
User
::
raw
(
function
(
\Jenssegers\Mongodb\
Collection
$collection
)
{
$user
=
User
::
raw
(
function
(
Collection
$collection
)
{
return
$collection
->
findOne
([
'age'
=>
35
]);
});
$this
->
assertInstanceOf
(
Model
::
class
,
$user
);
$count
=
User
::
raw
(
function
(
\Jenssegers\Mongodb\
Collection
$collection
)
{
$count
=
User
::
raw
(
function
(
Collection
$collection
)
{
return
$collection
->
count
();
});
$this
->
assertEquals
(
3
,
$count
);
$result
=
User
::
raw
(
function
(
\Jenssegers\Mongodb\
Collection
$collection
)
{
$result
=
User
::
raw
(
function
(
Collection
$collection
)
{
return
$collection
->
insertOne
([
'name'
=>
'Yvonne Yoe'
,
'age'
=>
35
]);
});
$this
->
assertNotNull
(
$result
);
...
...
@@ -566,7 +568,7 @@ class ModelTest extends TestCase
User
::
create
([
'name'
=>
'spoon'
,
'tags'
=>
[
'round'
,
'bowl'
]]);
$count
=
0
;
User
::
chunkById
(
2
,
function
(
\Illuminate\Database\Eloquent\
Collection
$items
)
use
(
&
$count
)
{
User
::
chunkById
(
2
,
function
(
Eloquent
Collection
$items
)
use
(
&
$count
)
{
$count
+=
count
(
$items
);
});
...
...
tests/QueryBuilderTest.php
View file @
12adb390
...
...
@@ -151,7 +151,6 @@ class QueryBuilderTest extends TestCase
]);
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'John Doe'
)
->
update
([
'age'
=>
100
]);
$users
=
DB
::
collection
(
'users'
)
->
get
();
$john
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'John Doe'
)
->
first
();
$jane
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'Jane Doe'
)
->
first
();
...
...
tests/QueueTest.php
View file @
12adb390
<?php
declare
(
strict_types
=
1
);
use
Carbon\Carbon
;
use
Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider
;
class
QueueTest
extends
TestCase
...
...
@@ -43,7 +44,7 @@ class QueueTest extends TestCase
$this
->
assertNotNull
(
$id
);
// Expire the test job
$expiry
=
\Carbon\
Carbon
::
now
()
->
subSeconds
(
Config
::
get
(
'queue.connections.database.expire'
))
->
getTimestamp
();
$expiry
=
Carbon
::
now
()
->
subSeconds
(
Config
::
get
(
'queue.connections.database.expire'
))
->
getTimestamp
();
Queue
::
getDatabase
()
->
table
(
Config
::
get
(
'queue.connections.database.table'
))
->
where
(
'_id'
,
$id
)
...
...
tests/RelationsTest.php
View file @
12adb390
...
...
@@ -296,10 +296,10 @@ class RelationsTest extends TestCase
public
function
testBelongsToManyAttachEloquentCollection
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
User
::
create
([
'name'
=>
'John Doe'
]);
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
]);
$client2
=
Client
::
create
([
'name'
=>
'Test 2'
]);
$collection
=
new
\Illuminate\Database\Eloquent\
Collection
([
$client1
,
$client2
]);
$collection
=
new
Collection
([
$client1
,
$client2
]);
$user
=
User
::
where
(
'name'
,
'='
,
'John Doe'
)
->
first
();
$user
->
clients
()
->
attach
(
$collection
);
...
...
@@ -467,7 +467,7 @@ class RelationsTest extends TestCase
],
]);
$
address
=
$
client
->
addresses
()
->
create
([
$client
->
addresses
()
->
create
([
'data'
=>
[
'address_id'
=>
1432
,
'city'
=>
'Paris'
,
...
...
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