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
47398ff4
Unverified
Commit
47398ff4
authored
Sep 06, 2019
by
Jens Segers
Committed by
GitHub
Sep 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1814 from simonschaufi/code-cleanup
Code cleanup
parents
01ac069c
e821aec1
Show whitespace changes
Inline
Side-by-side
Showing
40 changed files
with
297 additions
and
196 deletions
+297
-196
DatabaseTokenRepository.php
src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
+1
-1
Builder.php
src/Jenssegers/Mongodb/Eloquent/Builder.php
+1
-2
EmbedsRelations.php
src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php
+6
-6
HybridRelations.php
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
+13
-15
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+20
-16
MongoQueue.php
src/Jenssegers/Mongodb/Queue/MongoQueue.php
+1
-1
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+2
-2
EmbedsOneOrMany.php
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
+1
-1
Blueprint.php
src/Jenssegers/Mongodb/Schema/Blueprint.php
+1
-1
DatabasePresenceVerifier.php
...enssegers/Mongodb/Validation/DatabasePresenceVerifier.php
+1
-1
CollectionTest.php
tests/CollectionTest.php
+1
-0
ConnectionTest.php
tests/ConnectionTest.php
+10
-7
DsnTest.php
tests/DsnTest.php
+1
-0
EmbeddedRelationsTest.php
tests/EmbeddedRelationsTest.php
+22
-18
GeospatialTest.php
tests/GeospatialTest.php
+1
-0
HybridRelationsTest.php
tests/HybridRelationsTest.php
+1
-0
ModelTest.php
tests/ModelTest.php
+52
-37
QueryBuilderTest.php
tests/QueryBuilderTest.php
+2
-0
QueryTest.php
tests/QueryTest.php
+19
-18
QueueTest.php
tests/QueueTest.php
+3
-2
RelationsTest.php
tests/RelationsTest.php
+21
-20
SchemaTest.php
tests/SchemaTest.php
+19
-18
SeederTest.php
tests/SeederTest.php
+3
-2
TestCase.php
tests/TestCase.php
+4
-1
ValidationTest.php
tests/ValidationTest.php
+3
-2
database.php
tests/config/database.php
+1
-1
Address.php
tests/models/Address.php
+3
-1
Book.php
tests/models/Book.php
+11
-2
Client.php
tests/models/Client.php
+7
-3
Group.php
tests/models/Group.php
+3
-1
Item.php
tests/models/Item.php
+10
-2
Location.php
tests/models/Location.php
+1
-0
MysqlBook.php
tests/models/MysqlBook.php
+7
-3
MysqlRole.php
tests/models/MysqlRole.php
+7
-3
MysqlUser.php
tests/models/MysqlUser.php
+10
-5
Photo.php
tests/models/Photo.php
+3
-1
Role.php
tests/models/Role.php
+4
-2
Scoped.php
tests/models/Scoped.php
+1
-0
Soft.php
tests/models/Soft.php
+6
-0
User.php
tests/models/User.php
+14
-1
No files found.
src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
View file @
47398ff4
...
...
@@ -27,7 +27,7 @@ class DatabaseTokenRepository extends BaseDatabaseTokenRepository
$date
=
$createdAt
->
toDateTime
();
$date
->
setTimezone
(
new
DateTimeZone
(
date_default_timezone_get
()));
$createdAt
=
$date
->
format
(
'Y-m-d H:i:s'
);
}
elseif
(
is_array
(
$createdAt
)
and
isset
(
$createdAt
[
'date'
]))
{
}
elseif
(
is_array
(
$createdAt
)
&&
isset
(
$createdAt
[
'date'
]))
{
$date
=
new
DateTime
(
$createdAt
[
'date'
],
new
DateTimeZone
(
isset
(
$createdAt
[
'timezone'
])
?
$createdAt
[
'timezone'
]
:
'UTC'
));
$date
->
setTimezone
(
new
DateTimeZone
(
date_default_timezone_get
()));
$createdAt
=
$date
->
format
(
'Y-m-d H:i:s'
);
...
...
src/Jenssegers/Mongodb/Eloquent/Builder.php
View file @
47398ff4
...
...
@@ -188,8 +188,7 @@ class Builder extends EloquentBuilder
*/
protected
function
addUpdatedAtColumn
(
array
$values
)
{
if
(
!
$this
->
model
->
usesTimestamps
()
||
is_null
(
$this
->
model
->
getUpdatedAtColumn
()))
{
if
(
!
$this
->
model
->
usesTimestamps
()
||
$this
->
model
->
getUpdatedAtColumn
()
===
null
)
{
return
$values
;
}
...
...
src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php
View file @
47398ff4
...
...
@@ -22,17 +22,17 @@ trait EmbedsRelations
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if
(
is_null
(
$relation
)
)
{
if
(
$relation
===
null
)
{
list
(,
$caller
)
=
debug_backtrace
(
false
);
$relation
=
$caller
[
'function'
];
}
if
(
is_null
(
$localKey
)
)
{
if
(
$localKey
===
null
)
{
$localKey
=
$relation
;
}
if
(
is_null
(
$foreignKey
)
)
{
if
(
$foreignKey
===
null
)
{
$foreignKey
=
Str
::
snake
(
class_basename
(
$this
));
}
...
...
@@ -57,17 +57,17 @@ trait EmbedsRelations
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if
(
is_null
(
$relation
)
)
{
if
(
$relation
===
null
)
{
list
(,
$caller
)
=
debug_backtrace
(
false
);
$relation
=
$caller
[
'function'
];
}
if
(
is_null
(
$localKey
)
)
{
if
(
$localKey
===
null
)
{
$localKey
=
$relation
;
}
if
(
is_null
(
$foreignKey
)
)
{
if
(
$foreignKey
===
null
)
{
$foreignKey
=
Str
::
snake
(
class_basename
(
$this
));
}
...
...
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
View file @
47398ff4
...
...
@@ -133,7 +133,7 @@ trait HybridRelations
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if
(
is_null
(
$relation
)
)
{
if
(
$relation
===
null
)
{
list
(
$current
,
$caller
)
=
debug_backtrace
(
false
,
2
);
$relation
=
$caller
[
'function'
];
...
...
@@ -147,7 +147,7 @@ trait HybridRelations
// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
if
(
is_null
(
$foreignKey
)
)
{
if
(
$foreignKey
===
null
)
{
$foreignKey
=
Str
::
snake
(
$relation
)
.
'_id'
;
}
...
...
@@ -177,7 +177,7 @@ trait HybridRelations
// If no name is provided, we will use the backtrace to get the function name
// since that is most likely the name of the polymorphic interface. We can
// use that to get both the class and foreign key that will be utilized.
if
(
is_null
(
$name
)
)
{
if
(
$name
===
null
)
{
list
(
$current
,
$caller
)
=
debug_backtrace
(
DEBUG_BACKTRACE_IGNORE_ARGS
,
2
);
$name
=
Str
::
snake
(
$caller
[
'function'
]);
...
...
@@ -188,7 +188,7 @@ trait HybridRelations
// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
// there are multiple types in the morph and we can't use single queries.
if
(
is_null
(
$class
=
$this
->
$type
)
)
{
if
(
(
$class
=
$this
->
$type
)
===
null
)
{
return
new
MorphTo
(
$this
->
newQuery
(),
$this
,
$id
,
null
,
$type
,
$name
);
...
...
@@ -197,7 +197,6 @@ trait HybridRelations
// If we are not eager loading the relationship we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
else
{
$class
=
$this
->
getActualClassNameForMorph
(
$class
);
$instance
=
new
$class
;
...
...
@@ -206,7 +205,6 @@ trait HybridRelations
$instance
->
newQuery
(),
$this
,
$id
,
$instance
->
getKeyName
(),
$type
,
$name
);
}
}
/**
* Define a many-to-many relationship.
...
...
@@ -232,7 +230,7 @@ trait HybridRelations
// If no relationship name was passed, we will pull backtraces to get the
// name of the calling function. We will use that function name as the
// title of this relation since that is a great convention to apply.
if
(
is_null
(
$relation
)
)
{
if
(
$relation
===
null
)
{
$relation
=
$this
->
guessBelongsToManyRelation
();
}
...
...
@@ -261,7 +259,7 @@ trait HybridRelations
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
if
(
is_null
(
$collection
)
)
{
if
(
$collection
===
null
)
{
$collection
=
$instance
->
getTable
();
}
...
...
@@ -303,8 +301,8 @@ trait HybridRelations
{
if
(
is_subclass_of
(
$this
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
new
Builder
(
$query
);
}
else
{
return
new
EloquentBuilder
(
$query
);
}
return
new
EloquentBuilder
(
$query
);
}
}
src/Jenssegers/Mongodb/Query/Builder.php
View file @
47398ff4
...
...
@@ -233,7 +233,7 @@ class Builder extends BaseBuilder
// If no columns have been specified for the select statement, we will set them
// here to either the passed columns, or the standard default of retrieving
// all of the columns on the table using the "wildcard" column character.
if
(
is_null
(
$this
->
columns
)
)
{
if
(
$this
->
columns
===
null
)
{
$this
->
columns
=
$columns
;
}
...
...
@@ -469,7 +469,7 @@ class Builder extends BaseBuilder
*/
public
function
exists
()
{
return
!
is_null
(
$this
->
first
())
;
return
$this
->
first
()
!==
null
;
}
/**
...
...
@@ -580,7 +580,7 @@ class Builder extends BaseBuilder
$result
=
$this
->
collection
->
insertOne
(
$values
);
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
if
(
is_null
(
$sequence
)
)
{
if
(
$sequence
===
null
)
{
$sequence
=
'_id'
;
}
...
...
@@ -652,7 +652,7 @@ class Builder extends BaseBuilder
*/
public
function
pluck
(
$column
,
$key
=
null
)
{
$results
=
$this
->
get
(
is_null
(
$key
)
?
[
$column
]
:
[
$column
,
$key
]);
$results
=
$this
->
get
(
$key
===
null
?
[
$column
]
:
[
$column
,
$key
]);
// Convert ObjectID's to strings
if
(
$key
==
'_id'
)
{
...
...
@@ -674,7 +674,7 @@ class Builder extends BaseBuilder
// If an ID is passed to the method, we will set the where clause to check
// the ID to allow developers to simply and quickly remove a single row
// from their database without manually specifying the where clauses.
if
(
!
is_null
(
$id
)
)
{
if
(
$id
!==
null
)
{
$this
->
where
(
'_id'
,
'='
,
$id
);
}
...
...
@@ -730,8 +730,10 @@ class Builder extends BaseBuilder
// Execute the closure on the mongodb collection
if
(
$expression
instanceof
Closure
)
{
return
call_user_func
(
$expression
,
$this
->
collection
);
}
// Create an expression for the given value
elseif
(
!
is_null
(
$expression
))
{
}
// Create an expression for the given value
if
(
$expression
!==
null
)
{
return
new
Expression
(
$expression
);
}
...
...
@@ -854,7 +856,9 @@ class Builder extends BaseBuilder
{
if
(
is_string
(
$id
)
&&
strlen
(
$id
)
===
24
&&
ctype_xdigit
(
$id
))
{
return
new
ObjectID
(
$id
);
}
elseif
(
is_string
(
$id
)
&&
strlen
(
$id
)
===
16
&&
preg_match
(
'~[^\x20-\x7E\t\r\n]~'
,
$id
)
>
0
)
{
}
if
(
is_string
(
$id
)
&&
strlen
(
$id
)
===
16
&&
preg_match
(
'~[^\x20-\x7E\t\r\n]~'
,
$id
)
>
0
)
{
return
new
Binary
(
$id
,
Binary
::
TYPE_UUID
);
}
...
...
@@ -1009,7 +1013,7 @@ class Builder extends BaseBuilder
$regex
=
'^'
.
$regex
;
}
if
(
!
Str
::
endsWith
(
$value
,
'%'
))
{
$regex
=
$regex
.
'$'
;
$regex
.=
'$'
;
}
$value
=
new
Regex
(
$regex
,
'i'
);
...
...
@@ -1121,7 +1125,8 @@ class Builder extends BaseBuilder
],
],
];
}
else
{
}
return
[
$column
=>
[
'$gte'
=>
$values
[
0
],
...
...
@@ -1129,7 +1134,6 @@ class Builder extends BaseBuilder
],
];
}
}
/**
* @param array $where
...
...
src/Jenssegers/Mongodb/Queue/MongoQueue.php
View file @
47398ff4
...
...
@@ -39,7 +39,7 @@ class MongoQueue extends DatabaseQueue
{
$queue
=
$this
->
getQueue
(
$queue
);
if
(
!
is_null
(
$this
->
retryAfter
)
)
{
if
(
$this
->
retryAfter
!==
null
)
{
$this
->
releaseJobsThatHaveBeenReservedTooLong
(
$queue
);
}
...
...
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
47398ff4
...
...
@@ -130,9 +130,9 @@ class EmbedsMany extends EmbedsOneOrMany
{
if
(
!
$this
->
contains
(
$model
))
{
return
$this
->
associateNew
(
$model
);
}
else
{
return
$this
->
associateExisting
(
$model
);
}
return
$this
->
associateExisting
(
$model
);
}
/**
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
View file @
47398ff4
...
...
@@ -279,7 +279,7 @@ abstract class EmbedsOneOrMany extends Relation
*/
protected
function
toModel
(
$attributes
=
[])
{
if
(
is_null
(
$attributes
)
)
{
if
(
$attributes
===
null
)
{
return
;
}
...
...
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
47398ff4
...
...
@@ -243,7 +243,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
*/
protected
function
fluent
(
$columns
=
null
)
{
if
(
is_null
(
$columns
)
)
{
if
(
$columns
===
null
)
{
return
$this
->
columns
;
}
elseif
(
is_string
(
$columns
))
{
return
$this
->
columns
=
[
$columns
];
...
...
src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php
View file @
47398ff4
...
...
@@ -19,7 +19,7 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe
{
$query
=
$this
->
table
(
$collection
)
->
where
(
$column
,
'regex'
,
"/
$value
/i"
);
if
(
!
is_null
(
$excludeId
)
&&
$excludeId
!=
'NULL'
)
{
if
(
$excludeId
!==
null
&&
$excludeId
!=
'NULL'
)
{
$query
->
where
(
$idColumn
?:
'id'
,
'<>'
,
$excludeId
);
}
...
...
tests/CollectionTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Collection
;
...
...
tests/ConnectionTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Support\Facades\DB
;
class
ConnectionTest
extends
TestCase
{
public
function
testConnection
()
{
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Connection'
,
$connection
);
$this
->
assertInstanceOf
(
\Jenssegers\Mongodb\Connection
::
class
,
$connection
);
}
public
function
testReconnect
()
...
...
@@ -23,22 +26,22 @@ class ConnectionTest extends TestCase
public
function
testDb
()
{
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
'MongoDB\Database'
,
$connection
->
getMongoDB
());
$this
->
assertInstanceOf
(
\MongoDB\Database
::
class
,
$connection
->
getMongoDB
());
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
'MongoDB\Client'
,
$connection
->
getMongoClient
());
$this
->
assertInstanceOf
(
\MongoDB\Client
::
class
,
$connection
->
getMongoClient
());
}
public
function
testCollection
()
{
$collection
=
DB
::
connection
(
'mongodb'
)
->
getCollection
(
'unittest'
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Collection'
,
$collection
);
$this
->
assertInstanceOf
(
Jenssegers\Mongodb\Collection
::
class
,
$collection
);
$collection
=
DB
::
connection
(
'mongodb'
)
->
collection
(
'unittests'
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Query\Builder'
,
$collection
);
$this
->
assertInstanceOf
(
Jenssegers\Mongodb\Query\Builder
::
class
,
$collection
);
$collection
=
DB
::
connection
(
'mongodb'
)
->
table
(
'unittests'
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Query\Builder'
,
$collection
);
$this
->
assertInstanceOf
(
Jenssegers\Mongodb\Query\Builder
::
class
,
$collection
);
}
// public function testDynamic()
...
...
@@ -87,7 +90,7 @@ class ConnectionTest extends TestCase
public
function
testSchemaBuilder
()
{
$schema
=
DB
::
connection
(
'mongodb'
)
->
getSchemaBuilder
();
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Schema\Builder'
,
$schema
);
$this
->
assertInstanceOf
(
\Jenssegers\Mongodb\Schema\Builder
::
class
,
$schema
);
}
public
function
testDriverName
()
...
...
tests/DsnTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
DsnTest
extends
TestCase
{
...
...
tests/EmbeddedRelationsTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
EmbeddedRelationsTest
extends
TestCase
{
...
...
@@ -20,7 +21,7 @@ class EmbeddedRelationsTest extends TestCase
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$address
=
new
Address
([
'city'
=>
'London'
]);
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$address
),
Mockery
::
any
());
$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
);
...
...
@@ -31,7 +32,7 @@ class EmbeddedRelationsTest extends TestCase
$address
->
unsetEventDispatcher
();
$this
->
assertNotNull
(
$user
->
addresses
);
$this
->
assertInstanceOf
(
'Illuminate\Database\Eloquent\Collection'
,
$user
->
addresses
);
$this
->
assertInstanceOf
(
\Illuminate\Database\Eloquent\Collection
::
class
,
$user
->
addresses
);
$this
->
assertEquals
([
'London'
],
$user
->
addresses
->
pluck
(
'city'
)
->
all
());
$this
->
assertInstanceOf
(
'DateTime'
,
$address
->
created_at
);
$this
->
assertInstanceOf
(
'DateTime'
,
$address
->
updated_at
);
...
...
@@ -39,14 +40,14 @@ class EmbeddedRelationsTest extends TestCase
$this
->
assertInternalType
(
'string'
,
$address
->
_id
);
$raw
=
$address
->
getAttributes
();
$this
->
assertInstanceOf
(
'MongoDB\BSON\ObjectID'
,
$raw
[
'_id'
]);
$this
->
assertInstanceOf
(
\MongoDB\BSON\ObjectID
::
class
,
$raw
[
'_id'
]);
$address
=
$user
->
addresses
()
->
save
(
new
Address
([
'city'
=>
'Paris'
]));
$user
=
User
::
find
(
$user
->
_id
);
$this
->
assertEquals
([
'London'
,
'Paris'
],
$user
->
addresses
->
pluck
(
'city'
)
->
all
());
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$address
),
Mockery
::
any
());
$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
);
...
...
@@ -91,7 +92,7 @@ class EmbeddedRelationsTest extends TestCase
// $user = User::create(['name' => 'John Doe']);
// $address = new Address(['city' => 'London']);
// $address->setEventDispatcher($events = Mockery::mock(
'Illuminate\Events\Dispatcher'
));
// $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);
...
...
@@ -99,7 +100,7 @@ class EmbeddedRelationsTest extends TestCase
// $address->save();
// $address->setEventDispatcher($events = Mockery::mock(
'Illuminate\Events\Dispatcher'
));
// $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);
...
...
@@ -180,7 +181,7 @@ class EmbeddedRelationsTest extends TestCase
$this
->
assertEquals
([
'Bruxelles'
],
$user
->
addresses
->
pluck
(
'city'
)
->
all
());
$raw
=
$address
->
getAttributes
();
$this
->
assertInstanceOf
(
'MongoDB\BSON\ObjectID'
,
$raw
[
'_id'
]);
$this
->
assertInstanceOf
(
\MongoDB\BSON\ObjectID
::
class
,
$raw
[
'_id'
]);
$freshUser
=
User
::
find
(
$user
->
id
);
$this
->
assertEquals
([
'Bruxelles'
],
$freshUser
->
addresses
->
pluck
(
'city'
)
->
all
());
...
...
@@ -190,7 +191,7 @@ class EmbeddedRelationsTest extends TestCase
$this
->
assertInternalType
(
'string'
,
$address
->
_id
);
$raw
=
$address
->
getAttributes
();
$this
->
assertInstanceOf
(
'MongoDB\BSON\ObjectID'
,
$raw
[
'_id'
]);
$this
->
assertInstanceOf
(
\MongoDB\BSON\ObjectID
::
class
,
$raw
[
'_id'
]);
}
public
function
testEmbedsManyCreateMany
()
...
...
@@ -212,7 +213,7 @@ class EmbeddedRelationsTest extends TestCase
$address
=
$user
->
addresses
->
first
();
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$address
),
Mockery
::
any
());
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.deleting: '
.
get_class
(
$address
),
Mockery
::
type
(
'Address'
))
->
andReturn
(
true
);
$events
->
shouldReceive
(
'dispatch'
)
->
once
()
->
with
(
'eloquent.deleted: '
.
get_class
(
$address
),
Mockery
::
type
(
'Address'
));
...
...
@@ -251,7 +252,7 @@ class EmbeddedRelationsTest extends TestCase
$address
=
$user
->
addresses
->
first
();
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$address
),
Mockery
::
any
());
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.deleting: '
.
get_class
(
$address
),
Mockery
::
type
(
'Address'
))
->
andReturn
(
true
);
$events
->
shouldReceive
(
'dispatch'
)
->
once
()
->
with
(
'eloquent.deleted: '
.
get_class
(
$address
),
Mockery
::
type
(
'Address'
));
...
...
@@ -300,7 +301,7 @@ class EmbeddedRelationsTest extends TestCase
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$address
=
new
Address
([
'city'
=>
'London'
]);
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$address
),
Mockery
::
any
());
$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
(
false
);
...
...
@@ -315,7 +316,7 @@ class EmbeddedRelationsTest extends TestCase
$address
=
new
Address
([
'city'
=>
'Paris'
]);
$address
->
exists
=
true
;
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$address
),
Mockery
::
any
());
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.saving: '
.
get_class
(
$address
),
$address
)
->
andReturn
(
false
);
...
...
@@ -329,7 +330,7 @@ class EmbeddedRelationsTest extends TestCase
$address
=
new
Address
([
'city'
=>
'New York'
]);
$user
->
addresses
()
->
save
(
$address
);
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$address
),
Mockery
::
any
());
$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
(
false
);
...
...
@@ -347,7 +348,7 @@ class EmbeddedRelationsTest extends TestCase
$address
=
$user
->
addresses
->
first
();
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$address
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$address
),
Mockery
::
any
());
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.deleting: '
.
get_class
(
$address
),
Mockery
::
mustBe
(
$address
))
->
andReturn
(
false
);
...
...
@@ -451,7 +452,7 @@ class EmbeddedRelationsTest extends TestCase
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$father
=
new
User
([
'name'
=>
'Mark Doe'
]);
$father
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$father
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$father
),
Mockery
::
any
());
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.saving: '
.
get_class
(
$father
),
$father
)
->
andReturn
(
true
);
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.creating: '
.
get_class
(
$father
),
$father
)
->
andReturn
(
true
);
...
...
@@ -471,7 +472,7 @@ class EmbeddedRelationsTest extends TestCase
$raw
=
$father
->
getAttributes
();
$this
->
assertInstanceOf
(
'MongoDB\BSON\ObjectID'
,
$raw
[
'_id'
]);
$father
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$father
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$father
),
Mockery
::
any
());
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.saving: '
.
get_class
(
$father
),
$father
)
->
andReturn
(
true
);
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.updating: '
.
get_class
(
$father
),
$father
)
->
andReturn
(
true
);
...
...
@@ -487,7 +488,7 @@ class EmbeddedRelationsTest extends TestCase
$father
=
new
User
([
'name'
=>
'Jim Doe'
]);
$father
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$father
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$father
),
Mockery
::
any
());
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.saving: '
.
get_class
(
$father
),
$father
)
->
andReturn
(
true
);
$events
->
shouldReceive
(
'until'
)
->
once
()
->
with
(
'eloquent.creating: '
.
get_class
(
$father
),
$father
)
->
andReturn
(
true
);
...
...
@@ -506,7 +507,7 @@ class EmbeddedRelationsTest extends TestCase
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$father
=
new
User
([
'name'
=>
'Mark Doe'
]);
$father
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
'Illuminate\Events\Dispatcher'
));
$father
->
setEventDispatcher
(
$events
=
Mockery
::
mock
(
\Illuminate\Events\Dispatcher
::
class
));
$events
->
shouldReceive
(
'dispatch'
)
->
with
(
'eloquent.retrieved: '
.
get_class
(
$father
),
Mockery
::
any
());
$events
->
shouldReceive
(
'until'
)
->
times
(
0
)
->
with
(
'eloquent.saving: '
.
get_class
(
$father
),
$father
);
...
...
@@ -534,6 +535,7 @@ class EmbeddedRelationsTest extends TestCase
public
function
testEmbedsManyToArray
()
{
/** @var User $user */
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
->
addresses
()
->
save
(
new
Address
([
'city'
=>
'New York'
]));
$user
->
addresses
()
->
save
(
new
Address
([
'city'
=>
'Paris'
]));
...
...
@@ -546,7 +548,9 @@ class EmbeddedRelationsTest extends TestCase
public
function
testEmbeddedSave
()
{
/** @var User $user */
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
/** @var \Address $address */
$address
=
$user
->
addresses
()
->
create
([
'city'
=>
'New York'
]);
$father
=
$user
->
father
()
->
create
([
'name'
=>
'Mark Doe'
]);
...
...
tests/GeospatialTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
GeospatialTest
extends
TestCase
{
...
...
tests/HybridRelationsTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
HybridRelationsTest
extends
TestCase
{
...
...
tests/ModelTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\ModelNotFoundException
;
use
Jenssegers\Mongodb\Eloquent\Model
;
use
MongoDB\BSON\ObjectID
;
use
MongoDB\BSON\UTCDateTime
;
...
...
@@ -16,17 +18,17 @@ class ModelTest extends TestCase
Item
::
truncate
();
}
public
function
testNewModel
()
public
function
testNewModel
()
:
void
{
$user
=
new
User
;
$this
->
assertInstanceOf
(
Model
::
class
,
$user
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Connection'
,
$user
->
getConnection
());
$this
->
assertInstanceOf
(
\Jenssegers\Mongodb\Connection
::
class
,
$user
->
getConnection
());
$this
->
assertFalse
(
$user
->
exists
);
$this
->
assertEquals
(
'users'
,
$user
->
getTable
());
$this
->
assertEquals
(
'_id'
,
$user
->
getKeyName
());
}
public
function
testInsert
()
public
function
testInsert
()
:
void
{
$user
=
new
User
;
$user
->
name
=
'John Doe'
;
...
...
@@ -51,7 +53,7 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
35
,
$user
->
age
);
}
public
function
testUpdate
()
public
function
testUpdate
()
:
void
{
$user
=
new
User
;
$user
->
name
=
'John Doe'
;
...
...
@@ -62,8 +64,8 @@ class ModelTest extends TestCase
$raw
=
$user
->
getAttributes
();
$this
->
assertInstanceOf
(
ObjectID
::
class
,
$raw
[
'_id'
]);
/** @var User $check */
$check
=
User
::
find
(
$user
->
_id
);
$check
->
age
=
36
;
$check
->
save
();
...
...
@@ -84,7 +86,7 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
20
,
$check
->
age
);
}
public
function
testManualStringId
()
public
function
testManualStringId
()
:
void
{
$user
=
new
User
;
$user
->
_id
=
'4af9f23d8ead0e1d32000000'
;
...
...
@@ -113,7 +115,7 @@ class ModelTest extends TestCase
$this
->
assertInternalType
(
'string'
,
$raw
[
'_id'
]);
}
public
function
testManualIntId
()
public
function
testManualIntId
()
:
void
{
$user
=
new
User
;
$user
->
_id
=
1
;
...
...
@@ -129,7 +131,7 @@ class ModelTest extends TestCase
$this
->
assertInternalType
(
'integer'
,
$raw
[
'_id'
]);
}
public
function
testDelete
()
public
function
testDelete
()
:
void
{
$user
=
new
User
;
$user
->
name
=
'John Doe'
;
...
...
@@ -145,7 +147,7 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
0
,
User
::
count
());
}
public
function
testAll
()
public
function
testAll
()
:
void
{
$user
=
new
User
;
$user
->
name
=
'John Doe'
;
...
...
@@ -166,7 +168,7 @@ class ModelTest extends TestCase
$this
->
assertContains
(
'Jane Doe'
,
$all
->
pluck
(
'name'
));
}
public
function
testFind
()
public
function
testFind
()
:
void
{
$user
=
new
User
;
$user
->
name
=
'John Doe'
;
...
...
@@ -174,6 +176,7 @@ class ModelTest extends TestCase
$user
->
age
=
35
;
$user
->
save
();
/** @var User $check */
$check
=
User
::
find
(
$user
->
_id
);
$this
->
assertInstanceOf
(
Model
::
class
,
$check
);
...
...
@@ -184,7 +187,7 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
35
,
$check
->
age
);
}
public
function
testGet
()
public
function
testGet
()
:
void
{
User
::
insert
([
[
'name'
=>
'John Doe'
],
...
...
@@ -197,19 +200,20 @@ class ModelTest extends TestCase
$this
->
assertInstanceOf
(
Model
::
class
,
$users
[
0
]);
}
public
function
testFirst
()
public
function
testFirst
()
:
void
{
User
::
insert
([
[
'name'
=>
'John Doe'
],
[
'name'
=>
'Jane Doe'
],
]);
/** @var User $user */
$user
=
User
::
first
();
$this
->
assertInstanceOf
(
Model
::
class
,
$user
);
$this
->
assertEquals
(
'John Doe'
,
$user
->
name
);
}
public
function
testNoDocument
()
public
function
testNoDocument
()
:
void
{
$items
=
Item
::
where
(
'name'
,
'nothing'
)
->
get
();
$this
->
assertInstanceOf
(
Collection
::
class
,
$items
);
...
...
@@ -222,25 +226,27 @@ class ModelTest extends TestCase
$this
->
assertNull
(
$item
);
}
public
function
testFindOr
fail
()
public
function
testFindOr
Fail
()
:
void
{
$this
->
expectException
(
Illuminate\Database\Eloquent\
ModelNotFoundException
::
class
);
User
::
findOr
f
ail
(
'51c33d8981fec6813e00000a'
);
$this
->
expectException
(
ModelNotFoundException
::
class
);
User
::
findOr
F
ail
(
'51c33d8981fec6813e00000a'
);
}
public
function
testCreate
()
public
function
testCreate
()
:
void
{
/** @var User $user */
$user
=
User
::
create
([
'name'
=>
'Jane Poe'
]);
$this
->
assertInstanceOf
(
Model
::
class
,
$user
);
$this
->
assertTrue
(
$user
->
exists
);
$this
->
assertEquals
(
'Jane Poe'
,
$user
->
name
);
/** @var User $check */
$check
=
User
::
where
(
'name'
,
'Jane Poe'
)
->
first
();
$this
->
assertEquals
(
$user
->
_id
,
$check
->
_id
);
}
public
function
testDestroy
()
public
function
testDestroy
()
:
void
{
$user
=
new
User
;
$user
->
name
=
'John Doe'
;
...
...
@@ -253,7 +259,7 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
0
,
User
::
count
());
}
public
function
testTouch
()
public
function
testTouch
()
:
void
{
$user
=
new
User
;
$user
->
name
=
'John Doe'
;
...
...
@@ -264,18 +270,21 @@ class ModelTest extends TestCase
$old
=
$user
->
updated_at
;
sleep
(
1
);
$user
->
touch
();
/** @var User $check */
$check
=
User
::
find
(
$user
->
_id
);
$this
->
assertNotEquals
(
$old
,
$check
->
updated_at
);
}
public
function
testSoftDelete
()
public
function
testSoftDelete
()
:
void
{
Soft
::
create
([
'name'
=>
'John Doe'
]);
Soft
::
create
([
'name'
=>
'Jane Doe'
]);
$this
->
assertEquals
(
2
,
Soft
::
count
());
/** @var Soft $user */
$user
=
Soft
::
where
(
'name'
,
'John Doe'
)
->
first
();
$this
->
assertTrue
(
$user
->
exists
);
$this
->
assertFalse
(
$user
->
trashed
());
...
...
@@ -300,7 +309,7 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
2
,
Soft
::
count
());
}
public
function
testPrimaryKey
()
public
function
testPrimaryKey
()
:
void
{
$user
=
new
User
;
$this
->
assertEquals
(
'_id'
,
$user
->
getKeyName
());
...
...
@@ -314,13 +323,14 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
'A Game of Thrones'
,
$book
->
getKey
());
/** @var Book $check */
$check
=
Book
::
find
(
'A Game of Thrones'
);
$this
->
assertEquals
(
'title'
,
$check
->
getKeyName
());
$this
->
assertEquals
(
'A Game of Thrones'
,
$check
->
getKey
());
$this
->
assertEquals
(
'A Game of Thrones'
,
$check
->
title
);
}
public
function
testScope
()
public
function
testScope
()
:
void
{
Item
::
insert
([
[
'name'
=>
'knife'
,
'type'
=>
'sharp'
],
...
...
@@ -331,7 +341,7 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
1
,
$sharp
->
count
());
}
public
function
testToArray
()
public
function
testToArray
()
:
void
{
$item
=
Item
::
create
([
'name'
=>
'fork'
,
'type'
=>
'sharp'
]);
...
...
@@ -344,7 +354,7 @@ class ModelTest extends TestCase
$this
->
assertInternalType
(
'string'
,
$array
[
'_id'
]);
}
public
function
testUnset
()
public
function
testUnset
()
:
void
{
$user1
=
User
::
create
([
'name'
=>
'John Doe'
,
'note1'
=>
'ABC'
,
'note2'
=>
'DEF'
]);
$user2
=
User
::
create
([
'name'
=>
'Jane Doe'
,
'note1'
=>
'ABC'
,
'note2'
=>
'DEF'
]);
...
...
@@ -371,7 +381,7 @@ class ModelTest extends TestCase
$this
->
assertObjectNotHasAttribute
(
'note2'
,
$user2
);
}
public
function
testDates
()
public
function
testDates
()
:
void
{
$birthday
=
new
DateTime
(
'1980/1/1'
);
$user
=
User
::
create
([
'name'
=>
'John Doe'
,
'birthday'
=>
$birthday
]);
...
...
@@ -398,10 +408,12 @@ class ModelTest extends TestCase
$this
->
assertLessThan
(
2
,
abs
(
time
()
-
$item
->
created_at
->
getTimestamp
()));
// test default date format for json output
/** @var Item $item */
$item
=
Item
::
create
([
'name'
=>
'sword'
]);
$json
=
$item
->
toArray
();
$this
->
assertEquals
(
$item
->
created_at
->
format
(
'Y-m-d H:i:s'
),
$json
[
'created_at'
]);
/** @var User $user */
$user
=
User
::
create
([
'name'
=>
'Jane Doe'
,
'birthday'
=>
time
()]);
$this
->
assertInstanceOf
(
Carbon
::
class
,
$user
->
birthday
);
...
...
@@ -422,8 +434,9 @@ class ModelTest extends TestCase
$this
->
assertEquals
((
string
)
$user
->
getAttribute
(
'entry.date'
)
->
format
(
'Y-m-d H:i:s'
),
$data
[
'entry'
][
'date'
]);
}
public
function
testIdAttribute
()
public
function
testIdAttribute
()
:
void
{
/** @var User $user */
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$this
->
assertEquals
(
$user
->
id
,
$user
->
_id
);
...
...
@@ -431,8 +444,9 @@ class ModelTest extends TestCase
$this
->
assertNotEquals
(
$user
->
id
,
$user
->
_id
);
}
public
function
testPushPull
()
public
function
testPushPull
()
:
void
{
/** @var User $user */
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
->
push
(
'tags'
,
'tag1'
);
...
...
@@ -457,36 +471,36 @@ class ModelTest extends TestCase
$this
->
assertEquals
([],
$user
->
tags
);
}
public
function
testRaw
()
public
function
testRaw
()
:
void
{
User
::
create
([
'name'
=>
'John Doe'
,
'age'
=>
35
]);
User
::
create
([
'name'
=>
'Jane Doe'
,
'age'
=>
35
]);
User
::
create
([
'name'
=>
'Harry Hoe'
,
'age'
=>
15
]);
$users
=
User
::
raw
(
function
(
$collection
)
{
$users
=
User
::
raw
(
function
(
\Jenssegers\Mongodb\Collection
$collection
)
{
return
$collection
->
find
([
'age'
=>
35
]);
});
$this
->
assertInstanceOf
(
Collection
::
class
,
$users
);
$this
->
assertInstanceOf
(
Model
::
class
,
$users
[
0
]);
$user
=
User
::
raw
(
function
(
$collection
)
{
$user
=
User
::
raw
(
function
(
\Jenssegers\Mongodb\Collection
$collection
)
{
return
$collection
->
findOne
([
'age'
=>
35
]);
});
$this
->
assertInstanceOf
(
Model
::
class
,
$user
);
$count
=
User
::
raw
(
function
(
$collection
)
{
$count
=
User
::
raw
(
function
(
\Jenssegers\Mongodb\Collection
$collection
)
{
return
$collection
->
count
();
});
$this
->
assertEquals
(
3
,
$count
);
$result
=
User
::
raw
(
function
(
$collection
)
{
$result
=
User
::
raw
(
function
(
\Jenssegers\Mongodb\Collection
$collection
)
{
return
$collection
->
insertOne
([
'name'
=>
'Yvonne Yoe'
,
'age'
=>
35
]);
});
$this
->
assertNotNull
(
$result
);
}
public
function
testDotNotation
()
public
function
testDotNotation
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
,
...
...
@@ -508,8 +522,9 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
'Strasbourg'
,
$user
[
'address.city'
]);
}
public
function
testMultipleLevelDotNotation
()
public
function
testMultipleLevelDotNotation
()
:
void
{
/** @var Book $book */
$book
=
Book
::
create
([
'title'
=>
'A Game of Thrones'
,
'chapters'
=>
[
...
...
@@ -524,7 +539,7 @@ class ModelTest extends TestCase
$this
->
assertEquals
(
'The first chapter'
,
$book
[
'chapters.one.title'
]);
}
public
function
testGetDirtyDates
()
public
function
testGetDirtyDates
()
:
void
{
$user
=
new
User
();
$user
->
setRawAttributes
([
'name'
=>
'John Doe'
,
'birthday'
=>
new
DateTime
(
'19 august 1989'
)],
true
);
...
...
@@ -534,14 +549,14 @@ class ModelTest extends TestCase
$this
->
assertEmpty
(
$user
->
getDirty
());
}
public
function
testChunkById
()
public
function
testChunkById
()
:
void
{
User
::
create
([
'name'
=>
'fork'
,
'tags'
=>
[
'sharp'
,
'pointy'
]]);
User
::
create
([
'name'
=>
'spork'
,
'tags'
=>
[
'sharp'
,
'pointy'
,
'round'
,
'bowl'
]]);
User
::
create
([
'name'
=>
'spoon'
,
'tags'
=>
[
'round'
,
'bowl'
]]);
$count
=
0
;
User
::
chunkById
(
2
,
function
(
$items
)
use
(
&
$count
)
{
User
::
chunkById
(
2
,
function
(
\Illuminate\Database\Eloquent\Collection
$items
)
use
(
&
$count
)
{
$count
+=
count
(
$items
);
});
...
...
tests/QueryBuilderTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Support\Facades\DB
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\Regex
;
...
...
tests/QueryTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
QueryTest
extends
TestCase
{
...
...
@@ -25,7 +26,7 @@ class QueryTest extends TestCase
parent
::
tearDown
();
}
public
function
testWhere
()
public
function
testWhere
()
:
void
{
$users
=
User
::
where
(
'age'
,
35
)
->
get
();
$this
->
assertCount
(
3
,
$users
);
...
...
@@ -46,7 +47,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
6
,
$users
);
}
public
function
testAndWhere
()
public
function
testAndWhere
()
:
void
{
$users
=
User
::
where
(
'age'
,
35
)
->
where
(
'title'
,
'admin'
)
->
get
();
$this
->
assertCount
(
2
,
$users
);
...
...
@@ -55,7 +56,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
2
,
$users
);
}
public
function
testLike
()
public
function
testLike
()
:
void
{
$users
=
User
::
where
(
'name'
,
'like'
,
'%doe'
)
->
get
();
$this
->
assertCount
(
2
,
$users
);
...
...
@@ -70,7 +71,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
1
,
$users
);
}
public
function
testSelect
()
public
function
testSelect
()
:
void
{
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
select
(
'name'
)
->
first
();
...
...
@@ -96,7 +97,7 @@ class QueryTest extends TestCase
$this
->
assertNull
(
$user
->
age
);
}
public
function
testOrWhere
()
public
function
testOrWhere
()
:
void
{
$users
=
User
::
where
(
'age'
,
13
)
->
orWhere
(
'title'
,
'admin'
)
->
get
();
$this
->
assertCount
(
4
,
$users
);
...
...
@@ -105,7 +106,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
2
,
$users
);
}
public
function
testBetween
()
public
function
testBetween
()
:
void
{
$users
=
User
::
whereBetween
(
'age'
,
[
0
,
25
])
->
get
();
$this
->
assertCount
(
2
,
$users
);
...
...
@@ -118,7 +119,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
6
,
$users
);
}
public
function
testIn
()
public
function
testIn
()
:
void
{
$users
=
User
::
whereIn
(
'age'
,
[
13
,
23
])
->
get
();
$this
->
assertCount
(
2
,
$users
);
...
...
@@ -134,19 +135,19 @@ class QueryTest extends TestCase
$this
->
assertCount
(
3
,
$users
);
}
public
function
testWhereNull
()
public
function
testWhereNull
()
:
void
{
$users
=
User
::
whereNull
(
'age'
)
->
get
();
$this
->
assertCount
(
1
,
$users
);
}
public
function
testWhereNotNull
()
public
function
testWhereNotNull
()
:
void
{
$users
=
User
::
whereNotNull
(
'age'
)
->
get
();
$this
->
assertCount
(
8
,
$users
);
}
public
function
testOrder
()
public
function
testOrder
()
:
void
{
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'age'
,
'asc'
)
->
first
();
$this
->
assertEquals
(
13
,
$user
->
age
);
...
...
@@ -167,7 +168,7 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
35
,
$user
->
age
);
}
public
function
testGroupBy
()
public
function
testGroupBy
()
:
void
{
$users
=
User
::
groupBy
(
'title'
)
->
get
();
$this
->
assertCount
(
3
,
$users
);
...
...
@@ -197,7 +198,7 @@ class QueryTest extends TestCase
$this
->
assertNotNull
(
$users
[
0
]
->
name
);
}
public
function
testCount
()
public
function
testCount
()
:
void
{
$count
=
User
::
where
(
'age'
,
'<>'
,
35
)
->
count
();
$this
->
assertEquals
(
6
,
$count
);
...
...
@@ -207,13 +208,13 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
6
,
$count
);
}
public
function
testExists
()
public
function
testExists
()
:
void
{
$this
->
assertFalse
(
User
::
where
(
'age'
,
'>'
,
37
)
->
exists
());
$this
->
assertTrue
(
User
::
where
(
'age'
,
'<'
,
37
)
->
exists
());
}
public
function
testSub
query
()
public
function
testSub
Query
()
:
void
{
$users
=
User
::
where
(
'title'
,
'admin'
)
->
orWhere
(
function
(
$query
)
{
$query
->
where
(
'name'
,
'Tommy Toe'
)
...
...
@@ -262,7 +263,7 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
5
,
$users
->
count
());
}
public
function
testWhereRaw
()
public
function
testWhereRaw
()
:
void
{
$where
=
[
'age'
=>
[
'$gt'
=>
30
,
'$lt'
=>
40
]];
$users
=
User
::
whereRaw
(
$where
)
->
get
();
...
...
@@ -276,7 +277,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
6
,
$users
);
}
public
function
testMultipleOr
()
public
function
testMultipleOr
()
:
void
{
$users
=
User
::
where
(
function
(
$query
)
{
$query
->
where
(
'age'
,
35
)
->
orWhere
(
'age'
,
33
);
...
...
@@ -297,7 +298,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
2
,
$users
);
}
public
function
testPaginate
()
public
function
testPaginate
()
:
void
{
$results
=
User
::
paginate
(
2
);
$this
->
assertEquals
(
2
,
$results
->
count
());
...
...
@@ -311,7 +312,7 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
1
,
$results
->
currentPage
());
}
public
function
testUpdate
()
public
function
testUpdate
()
:
void
{
$this
->
assertEquals
(
1
,
User
::
where
([
'name'
=>
'John Doe'
])
->
update
([
'name'
=>
'Jim Morrison'
]));
$this
->
assertEquals
(
1
,
User
::
where
([
'name'
=>
'Jim Morrison'
])
->
count
());
...
...
tests/QueueTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
QueueTest
extends
TestCase
{
...
...
@@ -11,7 +12,7 @@ class QueueTest extends TestCase
Queue
::
getDatabase
()
->
table
(
Config
::
get
(
'queue.failed.table'
))
->
truncate
();
}
public
function
testQueueJobLifeCycle
()
public
function
testQueueJobLifeCycle
()
:
void
{
$id
=
Queue
::
push
(
'test'
,
[
'action'
=>
'QueueJobLifeCycle'
],
'test'
);
$this
->
assertNotNull
(
$id
);
...
...
@@ -34,7 +35,7 @@ class QueueTest extends TestCase
$this
->
assertEquals
(
0
,
Queue
::
getDatabase
()
->
table
(
Config
::
get
(
'queue.connections.database.table'
))
->
count
());
}
public
function
testQueueJobExpired
()
public
function
testQueueJobExpired
()
:
void
{
$id
=
Queue
::
push
(
'test'
,
[
'action'
=>
'QueueJobExpired'
],
'test'
);
$this
->
assertNotNull
(
$id
);
...
...
tests/RelationsTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
RelationsTest
extends
TestCase
{
...
...
@@ -17,7 +18,7 @@ class RelationsTest extends TestCase
Photo
::
truncate
();
}
public
function
testHasMany
()
public
function
testHasMany
()
:
void
{
$author
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
Book
::
create
([
'title'
=>
'A Game of Thrones'
,
'author_id'
=>
$author
->
_id
]);
...
...
@@ -36,7 +37,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
3
,
$items
);
}
public
function
testBelongsTo
()
public
function
testBelongsTo
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
Book
::
create
([
'title'
=>
'A Game of Thrones'
,
'author_id'
=>
$user
->
_id
]);
...
...
@@ -55,7 +56,7 @@ class RelationsTest extends TestCase
$this
->
assertNull
(
$book
->
author
);
}
public
function
testHasOne
()
public
function
testHasOne
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
Role
::
create
([
'type'
=>
'admin'
,
'user_id'
=>
$user
->
_id
]);
...
...
@@ -78,7 +79,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
$user
->
_id
,
$role
->
user_id
);
}
public
function
testWithBelongsTo
()
public
function
testWithBelongsTo
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
Item
::
create
([
'type'
=>
'knife'
,
'user_id'
=>
$user
->
_id
]);
...
...
@@ -95,7 +96,7 @@ class RelationsTest extends TestCase
$this
->
assertNull
(
$items
[
3
]
->
getRelation
(
'user'
));
}
public
function
testWithHashMany
()
public
function
testWithHashMany
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
Item
::
create
([
'type'
=>
'knife'
,
'user_id'
=>
$user
->
_id
]);
...
...
@@ -110,7 +111,7 @@ class RelationsTest extends TestCase
$this
->
assertInstanceOf
(
'Item'
,
$items
[
0
]);
}
public
function
testWithHasOne
()
public
function
testWithHasOne
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
Role
::
create
([
'type'
=>
'admin'
,
'user_id'
=>
$user
->
_id
]);
...
...
@@ -123,7 +124,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
'admin'
,
$role
->
type
);
}
public
function
testEasyRelation
()
public
function
testEasyRelation
()
:
void
{
// Has Many
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
...
...
@@ -148,7 +149,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
$user
->
_id
,
$role
->
user_id
);
}
public
function
testBelongsToMany
()
public
function
testBelongsToMany
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
...
...
@@ -222,7 +223,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
1
,
$client
->
users
);
}
public
function
testBelongsToManyAttachesExistingModels
()
public
function
testBelongsToManyAttachesExistingModels
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
,
'client_ids'
=>
[
'1234523'
]]);
...
...
@@ -261,7 +262,7 @@ class RelationsTest extends TestCase
$this
->
assertStringStartsWith
(
'synced'
,
$user
->
clients
[
1
]
->
name
);
}
public
function
testBelongsToManySync
()
public
function
testBelongsToManySync
()
:
void
{
// create test instances
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
...
...
@@ -280,7 +281,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
1
,
$user
->
clients
);
}
public
function
testBelongsToManyAttachArray
()
public
function
testBelongsToManyAttachArray
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
])
->
_id
;
...
...
@@ -291,7 +292,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
2
,
$user
->
clients
);
}
public
function
testBelongsToManyAttachEloquentCollection
()
public
function
testBelongsToManyAttachEloquentCollection
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
]);
...
...
@@ -303,7 +304,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
2
,
$user
->
clients
);
}
public
function
testBelongsToManySyncAlreadyPresent
()
public
function
testBelongsToManySyncAlreadyPresent
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
])
->
_id
;
...
...
@@ -320,7 +321,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
1
,
$user
[
'client_ids'
]);
}
public
function
testBelongsToManyCustom
()
public
function
testBelongsToManyCustom
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$group
=
$user
->
groups
()
->
create
([
'name'
=>
'Admins'
]);
...
...
@@ -340,7 +341,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
$user
->
_id
,
$group
->
users
()
->
first
()
->
_id
);
}
public
function
testMorph
()
public
function
testMorph
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client
=
Client
::
create
([
'name'
=>
'Jane Doe'
]);
...
...
@@ -383,7 +384,7 @@ class RelationsTest extends TestCase
$this
->
assertInstanceOf
(
'Client'
,
$photos
[
1
]
->
imageable
);
}
public
function
testHasManyHas
()
public
function
testHasManyHas
()
:
void
{
$author1
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
$author1
->
books
()
->
create
([
'title'
=>
'A Game of Thrones'
,
'rating'
=>
5
]);
...
...
@@ -433,7 +434,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
1
,
$authors
);
}
public
function
testHasOneHas
()
public
function
testHasOneHas
()
:
void
{
$user1
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user1
->
role
()
->
create
([
'title'
=>
'admin'
]);
...
...
@@ -455,7 +456,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
2
,
$users
);
}
public
function
testNestedKeys
()
public
function
testNestedKeys
()
:
void
{
$client
=
Client
::
create
([
'data'
=>
[
...
...
@@ -481,7 +482,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
'Paris'
,
$client
->
addresses
->
first
()
->
data
[
'city'
]);
}
public
function
testDoubleSaveOneToMany
()
public
function
testDoubleSaveOneToMany
()
:
void
{
$author
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
$book
=
Book
::
create
([
'title'
=>
'A Game of Thrones'
]);
...
...
@@ -504,7 +505,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
$author
->
_id
,
$book
->
author_id
);
}
public
function
testDoubleSaveManyToMany
()
public
function
testDoubleSaveManyToMany
()
:
void
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client
=
Client
::
create
([
'name'
=>
'Admins'
]);
...
...
tests/SchemaTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
SchemaTest
extends
TestCase
{
...
...
@@ -8,14 +9,14 @@ class SchemaTest extends TestCase
Schema
::
drop
(
'newcollection_two'
);
}
public
function
testCreate
()
public
function
testCreate
()
:
void
{
Schema
::
create
(
'newcollection'
);
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection'
));
$this
->
assertTrue
(
Schema
::
hasTable
(
'newcollection'
));
}
public
function
testCreateWithCallback
()
public
function
testCreateWithCallback
()
:
void
{
$instance
=
$this
;
...
...
@@ -26,21 +27,21 @@ class SchemaTest extends TestCase
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection'
));
}
public
function
testCreateWithOptions
()
public
function
testCreateWithOptions
()
:
void
{
Schema
::
create
(
'newcollection_two'
,
null
,
[
'capped'
=>
true
,
'size'
=>
1024
]);
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection_two'
));
$this
->
assertTrue
(
Schema
::
hasTable
(
'newcollection_two'
));
}
public
function
testDrop
()
public
function
testDrop
()
:
void
{
Schema
::
create
(
'newcollection'
);
Schema
::
drop
(
'newcollection'
);
$this
->
assertFalse
(
Schema
::
hasCollection
(
'newcollection'
));
}
public
function
testBluePrint
()
public
function
testBluePrint
()
:
void
{
$instance
=
$this
;
...
...
@@ -53,7 +54,7 @@ class SchemaTest extends TestCase
});
}
public
function
testIndex
()
public
function
testIndex
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
index
(
'mykey1'
);
...
...
@@ -77,7 +78,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'mykey3'
]);
}
public
function
testPrimary
()
public
function
testPrimary
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
string
(
'mykey'
,
100
)
->
primary
();
...
...
@@ -87,7 +88,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'unique'
]);
}
public
function
testUnique
()
public
function
testUnique
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
unique
(
'uniquekey'
);
...
...
@@ -97,7 +98,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'unique'
]);
}
public
function
testDropIndex
()
public
function
testDropIndex
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
unique
(
'uniquekey'
);
...
...
@@ -144,7 +145,7 @@ class SchemaTest extends TestCase
$this
->
assertFalse
(
$index
);
}
public
function
testBackground
()
public
function
testBackground
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
background
(
'backgroundkey'
);
...
...
@@ -154,7 +155,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'background'
]);
}
public
function
testSparse
()
public
function
testSparse
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
sparse
(
'sparsekey'
);
...
...
@@ -164,7 +165,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'sparse'
]);
}
public
function
testExpire
()
public
function
testExpire
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
expire
(
'expirekey'
,
60
);
...
...
@@ -174,7 +175,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
60
,
$index
[
'expireAfterSeconds'
]);
}
public
function
testSoftDeletes
()
public
function
testSoftDeletes
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
softDeletes
();
...
...
@@ -188,7 +189,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'email'
]);
}
public
function
testFluent
()
public
function
testFluent
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
string
(
'email'
)
->
index
();
...
...
@@ -203,7 +204,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'token'
]);
}
public
function
testGeospatial
()
public
function
testGeospatial
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
geospatial
(
'point'
);
...
...
@@ -221,7 +222,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
'2dsphere'
,
$index
[
'key'
][
'continent'
]);
}
public
function
testDummies
()
public
function
testDummies
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
boolean
(
'activated'
)
->
default
(
0
);
...
...
@@ -229,7 +230,7 @@ class SchemaTest extends TestCase
});
}
public
function
testSparseUnique
()
public
function
testSparseUnique
()
:
void
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
sparse_and_unique
(
'sparseuniquekey'
);
...
...
@@ -240,7 +241,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'unique'
]);
}
protected
function
getIndex
(
$collection
,
$name
)
protected
function
getIndex
(
string
$collection
,
string
$name
)
{
$collection
=
DB
::
getCollection
(
$collection
);
...
...
tests/SeederTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
SeederTest
extends
TestCase
{
...
...
@@ -7,7 +8,7 @@ class SeederTest extends TestCase
User
::
truncate
();
}
public
function
testSeed
()
public
function
testSeed
()
:
void
{
$seeder
=
new
UserTableSeeder
;
$seeder
->
run
();
...
...
@@ -16,7 +17,7 @@ class SeederTest extends TestCase
$this
->
assertTrue
(
$user
->
seed
);
}
public
function
testArtisan
()
public
function
testArtisan
()
:
void
{
Artisan
::
call
(
'db:seed'
);
...
...
tests/TestCase.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Auth\Passwords\PasswordResetServiceProvider
;
class
TestCase
extends
Orchestra\Testbench\TestCase
{
...
...
@@ -13,7 +16,7 @@ class TestCase extends Orchestra\Testbench\TestCase
{
$providers
=
parent
::
getApplicationProviders
(
$app
);
unset
(
$providers
[
array_search
(
'Illuminate\Auth\Passwords\PasswordResetServiceProvider'
,
$providers
)]);
unset
(
$providers
[
array_search
(
PasswordResetServiceProvider
::
class
,
$providers
)]);
return
$providers
;
}
...
...
tests/ValidationTest.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
class
ValidationTest
extends
TestCase
{
...
...
@@ -7,7 +8,7 @@ class ValidationTest extends TestCase
User
::
truncate
();
}
public
function
testUnique
()
public
function
testUnique
()
:
void
{
$validator
=
Validator
::
make
(
[
'name'
=>
'John Doe'
],
...
...
@@ -42,7 +43,7 @@ class ValidationTest extends TestCase
$this
->
assertFalse
(
$validator
->
fails
());
}
public
function
testExists
()
public
function
testExists
()
:
void
{
$validator
=
Validator
::
make
(
[
'name'
=>
'John Doe'
],
...
...
tests/config/database.php
View file @
47398ff4
...
...
@@ -25,7 +25,7 @@ return [
'host'
=>
env
(
'MYSQL_HOST'
,
'mysql'
),
'database'
=>
env
(
'MYSQL_DATABASE'
,
'unittest'
),
'username'
=>
env
(
'MYSQL_USERNAME'
,
'root'
),
'password'
=>
''
,
'password'
=>
env
(
'MYSQL_PASSWORD'
,
''
)
,
'charset'
=>
'utf8'
,
'collation'
=>
'utf8_unicode_ci'
,
'prefix'
=>
''
,
...
...
tests/models/Address.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Relations\EmbedsMany
;
class
Address
extends
Eloquent
{
protected
$connection
=
'mongodb'
;
protected
static
$unguarded
=
true
;
public
function
addresses
()
public
function
addresses
()
:
EmbedsMany
{
return
$this
->
embedsMany
(
'Address'
);
}
...
...
tests/models/Book.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
/**
* Class Book
*
* @property string $title
* @property string $author
* @property array $chapters
*/
class
Book
extends
Eloquent
{
protected
$connection
=
'mongodb'
;
...
...
@@ -9,12 +18,12 @@ class Book extends Eloquent
protected
static
$unguarded
=
true
;
protected
$primaryKey
=
'title'
;
public
function
author
()
public
function
author
()
:
BelongsTo
{
return
$this
->
belongsTo
(
'User'
,
'author_id'
);
}
public
function
mysqlAuthor
()
public
function
mysqlAuthor
()
:
BelongsTo
{
return
$this
->
belongsTo
(
'MysqlUser'
,
'author_id'
);
}
...
...
tests/models/Client.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
;
use
Illuminate\Database\Eloquent\Relations\HasMany
;
use
Illuminate\Database\Eloquent\Relations\MorphOne
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Client
extends
Eloquent
...
...
@@ -8,17 +12,17 @@ class Client extends Eloquent
protected
$collection
=
'clients'
;
protected
static
$unguarded
=
true
;
public
function
users
()
public
function
users
()
:
BelongsToMany
{
return
$this
->
belongsToMany
(
'User'
);
}
public
function
photo
()
public
function
photo
()
:
MorphOne
{
return
$this
->
morphOne
(
'Photo'
,
'imageable'
);
}
public
function
addresses
()
public
function
addresses
()
:
HasMany
{
return
$this
->
hasMany
(
'Address'
,
'data.client_id'
,
'data.client_id'
);
}
...
...
tests/models/Group.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Group
extends
Eloquent
...
...
@@ -8,7 +10,7 @@ class Group extends Eloquent
protected
$collection
=
'groups'
;
protected
static
$unguarded
=
true
;
public
function
users
()
public
function
users
()
:
BelongsToMany
{
return
$this
->
belongsToMany
(
'User'
,
'users'
,
'groups'
,
'users'
,
'_id'
,
'_id'
,
'users'
);
}
...
...
tests/models/Item.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
/**
* Class Item
*
* @property \Carbon\Carbon $created_at
*/
class
Item
extends
Eloquent
{
protected
$connection
=
'mongodb'
;
protected
$collection
=
'items'
;
protected
static
$unguarded
=
true
;
public
function
user
()
public
function
user
()
:
BelongsTo
{
return
$this
->
belongsTo
(
'User'
);
}
public
function
scopeSharp
(
$query
)
public
function
scopeSharp
(
Builder
$query
)
{
return
$query
->
where
(
'type'
,
'sharp'
);
}
...
...
tests/models/Location.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
...
...
tests/models/MysqlBook.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
...
...
@@ -12,7 +15,7 @@ class MysqlBook extends Eloquent
protected
static
$unguarded
=
true
;
protected
$primaryKey
=
'title'
;
public
function
author
()
public
function
author
()
:
BelongsTo
{
return
$this
->
belongsTo
(
'User'
,
'author_id'
);
}
...
...
@@ -20,12 +23,13 @@ class MysqlBook extends Eloquent
/**
* Check if we need to run the schema.
*/
public
static
function
executeSchema
()
public
static
function
executeSchema
()
:
void
{
/** @var \Illuminate\Database\Schema\MySqlBuilder $schema */
$schema
=
Schema
::
connection
(
'mysql'
);
if
(
!
$schema
->
hasTable
(
'books'
))
{
Schema
::
connection
(
'mysql'
)
->
create
(
'books'
,
function
(
$table
)
{
Schema
::
connection
(
'mysql'
)
->
create
(
'books'
,
function
(
Blueprint
$table
)
{
$table
->
string
(
'title'
);
$table
->
string
(
'author_id'
)
->
nullable
();
$table
->
integer
(
'mysql_user_id'
)
->
unsigned
()
->
nullable
();
...
...
tests/models/MysqlRole.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
...
...
@@ -11,12 +14,12 @@ class MysqlRole extends Eloquent
protected
$table
=
'roles'
;
protected
static
$unguarded
=
true
;
public
function
user
()
public
function
user
()
:
BelongsTo
{
return
$this
->
belongsTo
(
'User'
);
}
public
function
mysqlUser
()
public
function
mysqlUser
()
:
BelongsTo
{
return
$this
->
belongsTo
(
'MysqlUser'
);
}
...
...
@@ -26,10 +29,11 @@ class MysqlRole extends Eloquent
*/
public
static
function
executeSchema
()
{
/** @var \Illuminate\Database\Schema\MySqlBuilder $schema */
$schema
=
Schema
::
connection
(
'mysql'
);
if
(
!
$schema
->
hasTable
(
'roles'
))
{
Schema
::
connection
(
'mysql'
)
->
create
(
'roles'
,
function
(
$table
)
{
Schema
::
connection
(
'mysql'
)
->
create
(
'roles'
,
function
(
Blueprint
$table
)
{
$table
->
string
(
'type'
);
$table
->
string
(
'user_id'
);
$table
->
timestamps
();
...
...
tests/models/MysqlUser.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\HasMany
;
use
Illuminate\Database\Eloquent\Relations\HasOne
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
...
...
@@ -11,17 +15,17 @@ class MysqlUser extends Eloquent
protected
$table
=
'users'
;
protected
static
$unguarded
=
true
;
public
function
books
()
public
function
books
()
:
HasMany
{
return
$this
->
hasMany
(
'Book'
,
'author_id'
);
}
public
function
role
()
public
function
role
()
:
HasOne
{
return
$this
->
hasOne
(
'Role'
);
}
public
function
mysqlBooks
()
public
function
mysqlBooks
()
:
HasMany
{
return
$this
->
hasMany
(
MysqlBook
::
class
);
}
...
...
@@ -29,12 +33,13 @@ class MysqlUser extends Eloquent
/**
* Check if we need to run the schema.
*/
public
static
function
executeSchema
()
public
static
function
executeSchema
()
:
void
{
/** @var \Illuminate\Database\Schema\MySqlBuilder $schema */
$schema
=
Schema
::
connection
(
'mysql'
);
if
(
!
$schema
->
hasTable
(
'users'
))
{
Schema
::
connection
(
'mysql'
)
->
create
(
'users'
,
function
(
$table
)
{
Schema
::
connection
(
'mysql'
)
->
create
(
'users'
,
function
(
Blueprint
$table
)
{
$table
->
increments
(
'id'
);
$table
->
string
(
'name'
);
$table
->
timestamps
();
...
...
tests/models/Photo.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\MorphTo
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Photo
extends
Eloquent
...
...
@@ -8,7 +10,7 @@ class Photo extends Eloquent
protected
$collection
=
'photos'
;
protected
static
$unguarded
=
true
;
public
function
imageable
()
public
function
imageable
()
:
MorphTo
{
return
$this
->
morphTo
();
}
...
...
tests/models/Role.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Role
extends
Eloquent
...
...
@@ -8,12 +10,12 @@ class Role extends Eloquent
protected
$collection
=
'roles'
;
protected
static
$unguarded
=
true
;
public
function
user
()
public
function
user
()
:
BelongsTo
{
return
$this
->
belongsTo
(
'User'
);
}
public
function
mysqlUser
()
public
function
mysqlUser
()
:
BelongsTo
{
return
$this
->
belongsTo
(
'MysqlUser'
);
}
...
...
tests/models/Scoped.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
...
...
tests/models/Soft.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\SoftDeletes
;
/**
* Class Soft
*
* @property \Carbon\Carbon $deleted_at
*/
class
Soft
extends
Eloquent
{
use
SoftDeletes
;
...
...
tests/models/User.php
View file @
47398ff4
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Notifications\Notifiable
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Illuminate\Auth\Authenticatable
;
...
...
@@ -7,9 +9,20 @@ use Illuminate\Auth\Passwords\CanResetPassword;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Contracts\Auth\CanResetPassword
as
CanResetPasswordContract
;
/**
* Class User
*
* @property string $_id
* @property string $name
* @property string $title
* @property int $age
* @property \Carbon\Carbon $birthday
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
*/
class
User
extends
Eloquent
implements
AuthenticatableContract
,
CanResetPasswordContract
{
use
Authenticatable
,
CanResetPassword
,
HybridRelations
;
use
Authenticatable
,
CanResetPassword
,
HybridRelations
,
Notifiable
;
protected
$connection
=
'mongodb'
;
protected
$dates
=
[
'birthday'
,
'entry.date'
];
...
...
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