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
Expand all
Hide 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
...
@@ -27,7 +27,7 @@ class DatabaseTokenRepository extends BaseDatabaseTokenRepository
$date
=
$createdAt
->
toDateTime
();
$date
=
$createdAt
->
toDateTime
();
$date
->
setTimezone
(
new
DateTimeZone
(
date_default_timezone_get
()));
$date
->
setTimezone
(
new
DateTimeZone
(
date_default_timezone_get
()));
$createdAt
=
$date
->
format
(
'Y-m-d H:i:s'
);
$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
=
new
DateTime
(
$createdAt
[
'date'
],
new
DateTimeZone
(
isset
(
$createdAt
[
'timezone'
])
?
$createdAt
[
'timezone'
]
:
'UTC'
));
$date
->
setTimezone
(
new
DateTimeZone
(
date_default_timezone_get
()));
$date
->
setTimezone
(
new
DateTimeZone
(
date_default_timezone_get
()));
$createdAt
=
$date
->
format
(
'Y-m-d H:i:s'
);
$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
...
@@ -188,8 +188,7 @@ class Builder extends EloquentBuilder
*/
*/
protected
function
addUpdatedAtColumn
(
array
$values
)
protected
function
addUpdatedAtColumn
(
array
$values
)
{
{
if
(
!
$this
->
model
->
usesTimestamps
()
||
if
(
!
$this
->
model
->
usesTimestamps
()
||
$this
->
model
->
getUpdatedAtColumn
()
===
null
)
{
is_null
(
$this
->
model
->
getUpdatedAtColumn
()))
{
return
$values
;
return
$values
;
}
}
...
...
src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php
View file @
47398ff4
...
@@ -22,17 +22,17 @@ trait EmbedsRelations
...
@@ -22,17 +22,17 @@ trait EmbedsRelations
// If no relation name was given, we will use this debug backtrace to extract
// 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
// 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.
// 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
);
list
(,
$caller
)
=
debug_backtrace
(
false
);
$relation
=
$caller
[
'function'
];
$relation
=
$caller
[
'function'
];
}
}
if
(
is_null
(
$localKey
)
)
{
if
(
$localKey
===
null
)
{
$localKey
=
$relation
;
$localKey
=
$relation
;
}
}
if
(
is_null
(
$foreignKey
)
)
{
if
(
$foreignKey
===
null
)
{
$foreignKey
=
Str
::
snake
(
class_basename
(
$this
));
$foreignKey
=
Str
::
snake
(
class_basename
(
$this
));
}
}
...
@@ -57,17 +57,17 @@ trait EmbedsRelations
...
@@ -57,17 +57,17 @@ trait EmbedsRelations
// If no relation name was given, we will use this debug backtrace to extract
// 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
// 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.
// 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
);
list
(,
$caller
)
=
debug_backtrace
(
false
);
$relation
=
$caller
[
'function'
];
$relation
=
$caller
[
'function'
];
}
}
if
(
is_null
(
$localKey
)
)
{
if
(
$localKey
===
null
)
{
$localKey
=
$relation
;
$localKey
=
$relation
;
}
}
if
(
is_null
(
$foreignKey
)
)
{
if
(
$foreignKey
===
null
)
{
$foreignKey
=
Str
::
snake
(
class_basename
(
$this
));
$foreignKey
=
Str
::
snake
(
class_basename
(
$this
));
}
}
...
...
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
View file @
47398ff4
...
@@ -133,7 +133,7 @@ trait HybridRelations
...
@@ -133,7 +133,7 @@ trait HybridRelations
// If no relation name was given, we will use this debug backtrace to extract
// 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
// 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.
// 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
);
list
(
$current
,
$caller
)
=
debug_backtrace
(
false
,
2
);
$relation
=
$caller
[
'function'
];
$relation
=
$caller
[
'function'
];
...
@@ -147,7 +147,7 @@ trait HybridRelations
...
@@ -147,7 +147,7 @@ trait HybridRelations
// If no foreign key was supplied, we can use a backtrace to guess the proper
// 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
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
// when combined with an "_id" should conventionally match the columns.
if
(
is_null
(
$foreignKey
)
)
{
if
(
$foreignKey
===
null
)
{
$foreignKey
=
Str
::
snake
(
$relation
)
.
'_id'
;
$foreignKey
=
Str
::
snake
(
$relation
)
.
'_id'
;
}
}
...
@@ -177,7 +177,7 @@ trait HybridRelations
...
@@ -177,7 +177,7 @@ trait HybridRelations
// If no name is provided, we will use the backtrace to get the function name
// 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
// 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.
// 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
);
list
(
$current
,
$caller
)
=
debug_backtrace
(
DEBUG_BACKTRACE_IGNORE_ARGS
,
2
);
$name
=
Str
::
snake
(
$caller
[
'function'
]);
$name
=
Str
::
snake
(
$caller
[
'function'
]);
...
@@ -188,7 +188,7 @@ trait HybridRelations
...
@@ -188,7 +188,7 @@ trait HybridRelations
// If the type value is null it is probably safe to assume we're eager loading
// 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
// 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.
// 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
(
return
new
MorphTo
(
$this
->
newQuery
(),
$this
,
$id
,
null
,
$type
,
$name
$this
->
newQuery
(),
$this
,
$id
,
null
,
$type
,
$name
);
);
...
@@ -197,15 +197,13 @@ trait HybridRelations
...
@@ -197,15 +197,13 @@ trait HybridRelations
// If we are not eager loading the relationship we will essentially treat this
// 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
// 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.
// we will pass in the appropriate values so that it behaves as expected.
else
{
$class
=
$this
->
getActualClassNameForMorph
(
$class
);
$class
=
$this
->
getActualClassNameForMorph
(
$class
);
$instance
=
new
$class
;
$instance
=
new
$class
;
return
new
MorphTo
(
return
new
MorphTo
(
$instance
->
newQuery
(),
$this
,
$id
,
$instance
->
getKeyName
(),
$type
,
$name
$instance
->
newQuery
(),
$this
,
$id
,
$instance
->
getKeyName
(),
$type
,
$name
);
);
}
}
}
/**
/**
...
@@ -232,7 +230,7 @@ trait HybridRelations
...
@@ -232,7 +230,7 @@ trait HybridRelations
// If no relationship name was passed, we will pull backtraces to get the
// 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
// 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.
// title of this relation since that is a great convention to apply.
if
(
is_null
(
$relation
)
)
{
if
(
$relation
===
null
)
{
$relation
=
$this
->
guessBelongsToManyRelation
();
$relation
=
$this
->
guessBelongsToManyRelation
();
}
}
...
@@ -261,7 +259,7 @@ trait HybridRelations
...
@@ -261,7 +259,7 @@ trait HybridRelations
// If no table name was provided, we can guess it by concatenating the two
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
// are transformed to snake case from their default CamelCase also.
if
(
is_null
(
$collection
)
)
{
if
(
$collection
===
null
)
{
$collection
=
$instance
->
getTable
();
$collection
=
$instance
->
getTable
();
}
}
...
@@ -303,8 +301,8 @@ trait HybridRelations
...
@@ -303,8 +301,8 @@ trait HybridRelations
{
{
if
(
is_subclass_of
(
$this
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
if
(
is_subclass_of
(
$this
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
new
Builder
(
$query
);
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
...
@@ -233,7 +233,7 @@ class Builder extends BaseBuilder
// If no columns have been specified for the select statement, we will set them
// 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
// here to either the passed columns, or the standard default of retrieving
// all of the columns on the table using the "wildcard" column character.
// all of the columns on the table using the "wildcard" column character.
if
(
is_null
(
$this
->
columns
)
)
{
if
(
$this
->
columns
===
null
)
{
$this
->
columns
=
$columns
;
$this
->
columns
=
$columns
;
}
}
...
@@ -469,7 +469,7 @@ class Builder extends BaseBuilder
...
@@ -469,7 +469,7 @@ class Builder extends BaseBuilder
*/
*/
public
function
exists
()
public
function
exists
()
{
{
return
!
is_null
(
$this
->
first
())
;
return
$this
->
first
()
!==
null
;
}
}
/**
/**
...
@@ -580,7 +580,7 @@ class Builder extends BaseBuilder
...
@@ -580,7 +580,7 @@ class Builder extends BaseBuilder
$result
=
$this
->
collection
->
insertOne
(
$values
);
$result
=
$this
->
collection
->
insertOne
(
$values
);
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
if
(
is_null
(
$sequence
)
)
{
if
(
$sequence
===
null
)
{
$sequence
=
'_id'
;
$sequence
=
'_id'
;
}
}
...
@@ -652,7 +652,7 @@ class Builder extends BaseBuilder
...
@@ -652,7 +652,7 @@ class Builder extends BaseBuilder
*/
*/
public
function
pluck
(
$column
,
$key
=
null
)
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
// Convert ObjectID's to strings
if
(
$key
==
'_id'
)
{
if
(
$key
==
'_id'
)
{
...
@@ -674,7 +674,7 @@ class Builder extends BaseBuilder
...
@@ -674,7 +674,7 @@ class Builder extends BaseBuilder
// If an ID is passed to the method, we will set the where clause to check
// 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
// the ID to allow developers to simply and quickly remove a single row
// from their database without manually specifying the where clauses.
// from their database without manually specifying the where clauses.
if
(
!
is_null
(
$id
)
)
{
if
(
$id
!==
null
)
{
$this
->
where
(
'_id'
,
'='
,
$id
);
$this
->
where
(
'_id'
,
'='
,
$id
);
}
}
...
@@ -730,8 +730,10 @@ class Builder extends BaseBuilder
...
@@ -730,8 +730,10 @@ class Builder extends BaseBuilder
// Execute the closure on the mongodb collection
// Execute the closure on the mongodb collection
if
(
$expression
instanceof
Closure
)
{
if
(
$expression
instanceof
Closure
)
{
return
call_user_func
(
$expression
,
$this
->
collection
);
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
);
return
new
Expression
(
$expression
);
}
}
...
@@ -854,7 +856,9 @@ class Builder extends BaseBuilder
...
@@ -854,7 +856,9 @@ class Builder extends BaseBuilder
{
{
if
(
is_string
(
$id
)
&&
strlen
(
$id
)
===
24
&&
ctype_xdigit
(
$id
))
{
if
(
is_string
(
$id
)
&&
strlen
(
$id
)
===
24
&&
ctype_xdigit
(
$id
))
{
return
new
ObjectID
(
$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
);
return
new
Binary
(
$id
,
Binary
::
TYPE_UUID
);
}
}
...
@@ -1009,7 +1013,7 @@ class Builder extends BaseBuilder
...
@@ -1009,7 +1013,7 @@ class Builder extends BaseBuilder
$regex
=
'^'
.
$regex
;
$regex
=
'^'
.
$regex
;
}
}
if
(
!
Str
::
endsWith
(
$value
,
'%'
))
{
if
(
!
Str
::
endsWith
(
$value
,
'%'
))
{
$regex
=
$regex
.
'$'
;
$regex
.=
'$'
;
}
}
$value
=
new
Regex
(
$regex
,
'i'
);
$value
=
new
Regex
(
$regex
,
'i'
);
...
@@ -1121,14 +1125,14 @@ class Builder extends BaseBuilder
...
@@ -1121,14 +1125,14 @@ class Builder extends BaseBuilder
],
],
],
],
];
];
}
else
{
return
[
$column
=>
[
'$gte'
=>
$values
[
0
],
'$lte'
=>
$values
[
1
],
],
];
}
}
return
[
$column
=>
[
'$gte'
=>
$values
[
0
],
'$lte'
=>
$values
[
1
],
],
];
}
}
/**
/**
...
...
src/Jenssegers/Mongodb/Queue/MongoQueue.php
View file @
47398ff4
...
@@ -39,7 +39,7 @@ class MongoQueue extends DatabaseQueue
...
@@ -39,7 +39,7 @@ class MongoQueue extends DatabaseQueue
{
{
$queue
=
$this
->
getQueue
(
$queue
);
$queue
=
$this
->
getQueue
(
$queue
);
if
(
!
is_null
(
$this
->
retryAfter
)
)
{
if
(
$this
->
retryAfter
!==
null
)
{
$this
->
releaseJobsThatHaveBeenReservedTooLong
(
$queue
);
$this
->
releaseJobsThatHaveBeenReservedTooLong
(
$queue
);
}
}
...
...
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
47398ff4
...
@@ -130,9 +130,9 @@ class EmbedsMany extends EmbedsOneOrMany
...
@@ -130,9 +130,9 @@ class EmbedsMany extends EmbedsOneOrMany
{
{
if
(
!
$this
->
contains
(
$model
))
{
if
(
!
$this
->
contains
(
$model
))
{
return
$this
->
associateNew
(
$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
...
@@ -279,7 +279,7 @@ abstract class EmbedsOneOrMany extends Relation
*/
*/
protected
function
toModel
(
$attributes
=
[])
protected
function
toModel
(
$attributes
=
[])
{
{
if
(
is_null
(
$attributes
)
)
{
if
(
$attributes
===
null
)
{
return
;
return
;
}
}
...
...
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
47398ff4
...
@@ -243,7 +243,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
...
@@ -243,7 +243,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
*/
*/
protected
function
fluent
(
$columns
=
null
)
protected
function
fluent
(
$columns
=
null
)
{
{
if
(
is_null
(
$columns
)
)
{
if
(
$columns
===
null
)
{
return
$this
->
columns
;
return
$this
->
columns
;
}
elseif
(
is_string
(
$columns
))
{
}
elseif
(
is_string
(
$columns
))
{
return
$this
->
columns
=
[
$columns
];
return
$this
->
columns
=
[
$columns
];
...
...
src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php
View file @
47398ff4
...
@@ -19,7 +19,7 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe
...
@@ -19,7 +19,7 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe
{
{
$query
=
$this
->
table
(
$collection
)
->
where
(
$column
,
'regex'
,
"/
$value
/i"
);
$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
);
$query
->
where
(
$idColumn
?:
'id'
,
'<>'
,
$excludeId
);
}
}
...
...
tests/CollectionTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Collection
;
use
Jenssegers\Mongodb\Collection
;
...
...
tests/ConnectionTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Support\Facades\DB
;
class
ConnectionTest
extends
TestCase
class
ConnectionTest
extends
TestCase
{
{
public
function
testConnection
()
public
function
testConnection
()
{
{
$connection
=
DB
::
connection
(
'mongodb'
);
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Connection'
,
$connection
);
$this
->
assertInstanceOf
(
\Jenssegers\Mongodb\Connection
::
class
,
$connection
);
}
}
public
function
testReconnect
()
public
function
testReconnect
()
...
@@ -23,22 +26,22 @@ class ConnectionTest extends TestCase
...
@@ -23,22 +26,22 @@ class ConnectionTest extends TestCase
public
function
testDb
()
public
function
testDb
()
{
{
$connection
=
DB
::
connection
(
'mongodb'
);
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
'MongoDB\Database'
,
$connection
->
getMongoDB
());
$this
->
assertInstanceOf
(
\MongoDB\Database
::
class
,
$connection
->
getMongoDB
());
$connection
=
DB
::
connection
(
'mongodb'
);
$connection
=
DB
::
connection
(
'mongodb'
);
$this
->
assertInstanceOf
(
'MongoDB\Client'
,
$connection
->
getMongoClient
());
$this
->
assertInstanceOf
(
\MongoDB\Client
::
class
,
$connection
->
getMongoClient
());
}
}
public
function
testCollection
()
public
function
testCollection
()
{
{
$collection
=
DB
::
connection
(
'mongodb'
)
->
getCollection
(
'unittest'
);
$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'
);
$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'
);
$collection
=
DB
::
connection
(
'mongodb'
)
->
table
(
'unittests'
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Query\Builder'
,
$collection
);
$this
->
assertInstanceOf
(
Jenssegers\Mongodb\Query\Builder
::
class
,
$collection
);
}
}
// public function testDynamic()
// public function testDynamic()
...
@@ -87,7 +90,7 @@ class ConnectionTest extends TestCase
...
@@ -87,7 +90,7 @@ class ConnectionTest extends TestCase
public
function
testSchemaBuilder
()
public
function
testSchemaBuilder
()
{
{
$schema
=
DB
::
connection
(
'mongodb'
)
->
getSchemaBuilder
();
$schema
=
DB
::
connection
(
'mongodb'
)
->
getSchemaBuilder
();
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Schema\Builder'
,
$schema
);
$this
->
assertInstanceOf
(
\Jenssegers\Mongodb\Schema\Builder
::
class
,
$schema
);
}
}
public
function
testDriverName
()
public
function
testDriverName
()
...
...
tests/DsnTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
class
DsnTest
extends
TestCase
class
DsnTest
extends
TestCase
{
{
...
...
tests/EmbeddedRelationsTest.php
View file @
47398ff4
This diff is collapsed.
Click to expand it.
tests/GeospatialTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
class
GeospatialTest
extends
TestCase
class
GeospatialTest
extends
TestCase
{
{
...
...
tests/HybridRelationsTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
class
HybridRelationsTest
extends
TestCase
class
HybridRelationsTest
extends
TestCase
{
{
...
...
tests/ModelTest.php
View file @
47398ff4
This diff is collapsed.
Click to expand it.
tests/QueryBuilderTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Support\Facades\DB
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\Regex
;
use
MongoDB\BSON\Regex
;
...
...
tests/QueryTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
class
QueryTest
extends
TestCase
class
QueryTest
extends
TestCase
{
{
...
@@ -25,7 +26,7 @@ class QueryTest extends TestCase
...
@@ -25,7 +26,7 @@ class QueryTest extends TestCase
parent
::
tearDown
();
parent
::
tearDown
();
}
}
public
function
testWhere
()
public
function
testWhere
()
:
void
{
{
$users
=
User
::
where
(
'age'
,
35
)
->
get
();
$users
=
User
::
where
(
'age'
,
35
)
->
get
();
$this
->
assertCount
(
3
,
$users
);
$this
->
assertCount
(
3
,
$users
);
...
@@ -46,7 +47,7 @@ class QueryTest extends TestCase
...
@@ -46,7 +47,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
6
,
$users
);
$this
->
assertCount
(
6
,
$users
);
}
}
public
function
testAndWhere
()
public
function
testAndWhere
()
:
void
{
{
$users
=
User
::
where
(
'age'
,
35
)
->
where
(
'title'
,
'admin'
)
->
get
();
$users
=
User
::
where
(
'age'
,
35
)
->
where
(
'title'
,
'admin'
)
->
get
();
$this
->
assertCount
(
2
,
$users
);
$this
->
assertCount
(
2
,
$users
);
...
@@ -55,7 +56,7 @@ class QueryTest extends TestCase
...
@@ -55,7 +56,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
2
,
$users
);
$this
->
assertCount
(
2
,
$users
);
}
}
public
function
testLike
()
public
function
testLike
()
:
void
{
{
$users
=
User
::
where
(
'name'
,
'like'
,
'%doe'
)
->
get
();
$users
=
User
::
where
(
'name'
,
'like'
,
'%doe'
)
->
get
();
$this
->
assertCount
(
2
,
$users
);
$this
->
assertCount
(
2
,
$users
);
...
@@ -70,7 +71,7 @@ class QueryTest extends TestCase
...
@@ -70,7 +71,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
1
,
$users
);
$this
->
assertCount
(
1
,
$users
);
}
}
public
function
testSelect
()
public
function
testSelect
()
:
void
{
{
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
select
(
'name'
)
->
first
();
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
select
(
'name'
)
->
first
();
...
@@ -96,7 +97,7 @@ class QueryTest extends TestCase
...
@@ -96,7 +97,7 @@ class QueryTest extends TestCase
$this
->
assertNull
(
$user
->
age
);
$this
->
assertNull
(
$user
->
age
);
}
}
public
function
testOrWhere
()
public
function
testOrWhere
()
:
void
{
{
$users
=
User
::
where
(
'age'
,
13
)
->
orWhere
(
'title'
,
'admin'
)
->
get
();
$users
=
User
::
where
(
'age'
,
13
)
->
orWhere
(
'title'
,
'admin'
)
->
get
();
$this
->
assertCount
(
4
,
$users
);
$this
->
assertCount
(
4
,
$users
);
...
@@ -105,7 +106,7 @@ class QueryTest extends TestCase
...
@@ -105,7 +106,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
2
,
$users
);
$this
->
assertCount
(
2
,
$users
);
}
}
public
function
testBetween
()
public
function
testBetween
()
:
void
{
{
$users
=
User
::
whereBetween
(
'age'
,
[
0
,
25
])
->
get
();
$users
=
User
::
whereBetween
(
'age'
,
[
0
,
25
])
->
get
();
$this
->
assertCount
(
2
,
$users
);
$this
->
assertCount
(
2
,
$users
);
...
@@ -118,7 +119,7 @@ class QueryTest extends TestCase
...
@@ -118,7 +119,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
6
,
$users
);
$this
->
assertCount
(
6
,
$users
);
}
}
public
function
testIn
()
public
function
testIn
()
:
void
{
{
$users
=
User
::
whereIn
(
'age'
,
[
13
,
23
])
->
get
();
$users
=
User
::
whereIn
(
'age'
,
[
13
,
23
])
->
get
();
$this
->
assertCount
(
2
,
$users
);
$this
->
assertCount
(
2
,
$users
);
...
@@ -134,19 +135,19 @@ class QueryTest extends TestCase
...
@@ -134,19 +135,19 @@ class QueryTest extends TestCase
$this
->
assertCount
(
3
,
$users
);
$this
->
assertCount
(
3
,
$users
);
}
}
public
function
testWhereNull
()
public
function
testWhereNull
()
:
void
{
{
$users
=
User
::
whereNull
(
'age'
)
->
get
();
$users
=
User
::
whereNull
(
'age'
)
->
get
();
$this
->
assertCount
(
1
,
$users
);
$this
->
assertCount
(
1
,
$users
);
}
}
public
function
testWhereNotNull
()
public
function
testWhereNotNull
()
:
void
{
{
$users
=
User
::
whereNotNull
(
'age'
)
->
get
();
$users
=
User
::
whereNotNull
(
'age'
)
->
get
();
$this
->
assertCount
(
8
,
$users
);
$this
->
assertCount
(
8
,
$users
);
}
}
public
function
testOrder
()
public
function
testOrder
()
:
void
{
{
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'age'
,
'asc'
)
->
first
();
$user
=
User
::
whereNotNull
(
'age'
)
->
orderBy
(
'age'
,
'asc'
)
->
first
();
$this
->
assertEquals
(
13
,
$user
->
age
);
$this
->
assertEquals
(
13
,
$user
->
age
);
...
@@ -167,7 +168,7 @@ class QueryTest extends TestCase
...
@@ -167,7 +168,7 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
35
,
$user
->
age
);
$this
->
assertEquals
(
35
,
$user
->
age
);
}
}
public
function
testGroupBy
()
public
function
testGroupBy
()
:
void
{
{
$users
=
User
::
groupBy
(
'title'
)
->
get
();
$users
=
User
::
groupBy
(
'title'
)
->
get
();
$this
->
assertCount
(
3
,
$users
);
$this
->
assertCount
(
3
,
$users
);
...
@@ -197,7 +198,7 @@ class QueryTest extends TestCase
...
@@ -197,7 +198,7 @@ class QueryTest extends TestCase
$this
->
assertNotNull
(
$users
[
0
]
->
name
);
$this
->
assertNotNull
(
$users
[
0
]
->
name
);
}
}
public
function
testCount
()
public
function
testCount
()
:
void
{
{
$count
=
User
::
where
(
'age'
,
'<>'
,
35
)
->
count
();
$count
=
User
::
where
(
'age'
,
'<>'
,
35
)
->
count
();
$this
->
assertEquals
(
6
,
$count
);
$this
->
assertEquals
(
6
,
$count
);
...
@@ -207,13 +208,13 @@ class QueryTest extends TestCase
...
@@ -207,13 +208,13 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
6
,
$count
);
$this
->
assertEquals
(
6
,
$count
);
}
}
public
function
testExists
()
public
function
testExists
()
:
void
{
{
$this
->
assertFalse
(
User
::
where
(
'age'
,
'>'
,
37
)
->
exists
());
$this
->
assertFalse
(
User
::
where
(
'age'
,
'>'
,
37
)
->
exists
());
$this
->
assertTrue
(
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
)
{
$users
=
User
::
where
(
'title'
,
'admin'
)
->
orWhere
(
function
(
$query
)
{
$query
->
where
(
'name'
,
'Tommy Toe'
)
$query
->
where
(
'name'
,
'Tommy Toe'
)
...
@@ -262,7 +263,7 @@ class QueryTest extends TestCase
...
@@ -262,7 +263,7 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
5
,
$users
->
count
());
$this
->
assertEquals
(
5
,
$users
->
count
());
}
}
public
function
testWhereRaw
()
public
function
testWhereRaw
()
:
void
{
{
$where
=
[
'age'
=>
[
'$gt'
=>
30
,
'$lt'
=>
40
]];
$where
=
[
'age'
=>
[
'$gt'
=>
30
,
'$lt'
=>
40
]];
$users
=
User
::
whereRaw
(
$where
)
->
get
();
$users
=
User
::
whereRaw
(
$where
)
->
get
();
...
@@ -276,7 +277,7 @@ class QueryTest extends TestCase
...
@@ -276,7 +277,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
6
,
$users
);
$this
->
assertCount
(
6
,
$users
);
}
}
public
function
testMultipleOr
()
public
function
testMultipleOr
()
:
void
{
{
$users
=
User
::
where
(
function
(
$query
)
{
$users
=
User
::
where
(
function
(
$query
)
{
$query
->
where
(
'age'
,
35
)
->
orWhere
(
'age'
,
33
);
$query
->
where
(
'age'
,
35
)
->
orWhere
(
'age'
,
33
);
...
@@ -297,7 +298,7 @@ class QueryTest extends TestCase
...
@@ -297,7 +298,7 @@ class QueryTest extends TestCase
$this
->
assertCount
(
2
,
$users
);
$this
->
assertCount
(
2
,
$users
);
}
}
public
function
testPaginate
()
public
function
testPaginate
()
:
void
{
{
$results
=
User
::
paginate
(
2
);
$results
=
User
::
paginate
(
2
);
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertEquals
(
2
,
$results
->
count
());
...
@@ -311,7 +312,7 @@ class QueryTest extends TestCase
...
@@ -311,7 +312,7 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
1
,
$results
->
currentPage
());
$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'
=>
'John Doe'
])
->
update
([
'name'
=>
'Jim Morrison'
]));
$this
->
assertEquals
(
1
,
User
::
where
([
'name'
=>
'Jim Morrison'
])
->
count
());
$this
->
assertEquals
(
1
,
User
::
where
([
'name'
=>
'Jim Morrison'
])
->
count
());
...
...
tests/QueueTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
class
QueueTest
extends
TestCase
class
QueueTest
extends
TestCase
{
{
...
@@ -11,7 +12,7 @@ class QueueTest extends TestCase
...
@@ -11,7 +12,7 @@ class QueueTest extends TestCase
Queue
::
getDatabase
()
->
table
(
Config
::
get
(
'queue.failed.table'
))
->
truncate
();
Queue
::
getDatabase
()
->
table
(
Config
::
get
(
'queue.failed.table'
))
->
truncate
();
}
}
public
function
testQueueJobLifeCycle
()
public
function
testQueueJobLifeCycle
()
:
void
{
{
$id
=
Queue
::
push
(
'test'
,
[
'action'
=>
'QueueJobLifeCycle'
],
'test'
);
$id
=
Queue
::
push
(
'test'
,
[
'action'
=>
'QueueJobLifeCycle'
],
'test'
);
$this
->
assertNotNull
(
$id
);
$this
->
assertNotNull
(
$id
);
...
@@ -34,7 +35,7 @@ class QueueTest extends TestCase
...
@@ -34,7 +35,7 @@ class QueueTest extends TestCase
$this
->
assertEquals
(
0
,
Queue
::
getDatabase
()
->
table
(
Config
::
get
(
'queue.connections.database.table'
))
->
count
());
$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'
);
$id
=
Queue
::
push
(
'test'
,
[
'action'
=>
'QueueJobExpired'
],
'test'
);
$this
->
assertNotNull
(
$id
);
$this
->
assertNotNull
(
$id
);
...
...
tests/RelationsTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
class
RelationsTest
extends
TestCase
class
RelationsTest
extends
TestCase
{
{
...
@@ -17,7 +18,7 @@ class RelationsTest extends TestCase
...
@@ -17,7 +18,7 @@ class RelationsTest extends TestCase
Photo
::
truncate
();
Photo
::
truncate
();
}
}
public
function
testHasMany
()
public
function
testHasMany
()
:
void
{
{
$author
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
$author
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
Book
::
create
([
'title'
=>
'A Game of Thrones'
,
'author_id'
=>
$author
->
_id
]);
Book
::
create
([
'title'
=>
'A Game of Thrones'
,
'author_id'
=>
$author
->
_id
]);
...
@@ -36,7 +37,7 @@ class RelationsTest extends TestCase
...
@@ -36,7 +37,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
3
,
$items
);
$this
->
assertCount
(
3
,
$items
);
}
}
public
function
testBelongsTo
()
public
function
testBelongsTo
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
$user
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
Book
::
create
([
'title'
=>
'A Game of Thrones'
,
'author_id'
=>
$user
->
_id
]);
Book
::
create
([
'title'
=>
'A Game of Thrones'
,
'author_id'
=>
$user
->
_id
]);
...
@@ -55,7 +56,7 @@ class RelationsTest extends TestCase
...
@@ -55,7 +56,7 @@ class RelationsTest extends TestCase
$this
->
assertNull
(
$book
->
author
);
$this
->
assertNull
(
$book
->
author
);
}
}
public
function
testHasOne
()
public
function
testHasOne
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
Role
::
create
([
'type'
=>
'admin'
,
'user_id'
=>
$user
->
_id
]);
Role
::
create
([
'type'
=>
'admin'
,
'user_id'
=>
$user
->
_id
]);
...
@@ -78,7 +79,7 @@ class RelationsTest extends TestCase
...
@@ -78,7 +79,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
$user
->
_id
,
$role
->
user_id
);
$this
->
assertEquals
(
$user
->
_id
,
$role
->
user_id
);
}
}
public
function
testWithBelongsTo
()
public
function
testWithBelongsTo
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
Item
::
create
([
'type'
=>
'knife'
,
'user_id'
=>
$user
->
_id
]);
Item
::
create
([
'type'
=>
'knife'
,
'user_id'
=>
$user
->
_id
]);
...
@@ -95,7 +96,7 @@ class RelationsTest extends TestCase
...
@@ -95,7 +96,7 @@ class RelationsTest extends TestCase
$this
->
assertNull
(
$items
[
3
]
->
getRelation
(
'user'
));
$this
->
assertNull
(
$items
[
3
]
->
getRelation
(
'user'
));
}
}
public
function
testWithHashMany
()
public
function
testWithHashMany
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
Item
::
create
([
'type'
=>
'knife'
,
'user_id'
=>
$user
->
_id
]);
Item
::
create
([
'type'
=>
'knife'
,
'user_id'
=>
$user
->
_id
]);
...
@@ -110,7 +111,7 @@ class RelationsTest extends TestCase
...
@@ -110,7 +111,7 @@ class RelationsTest extends TestCase
$this
->
assertInstanceOf
(
'Item'
,
$items
[
0
]);
$this
->
assertInstanceOf
(
'Item'
,
$items
[
0
]);
}
}
public
function
testWithHasOne
()
public
function
testWithHasOne
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
Role
::
create
([
'type'
=>
'admin'
,
'user_id'
=>
$user
->
_id
]);
Role
::
create
([
'type'
=>
'admin'
,
'user_id'
=>
$user
->
_id
]);
...
@@ -123,7 +124,7 @@ class RelationsTest extends TestCase
...
@@ -123,7 +124,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
'admin'
,
$role
->
type
);
$this
->
assertEquals
(
'admin'
,
$role
->
type
);
}
}
public
function
testEasyRelation
()
public
function
testEasyRelation
()
:
void
{
{
// Has Many
// Has Many
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
...
@@ -148,7 +149,7 @@ class RelationsTest extends TestCase
...
@@ -148,7 +149,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
$user
->
_id
,
$role
->
user_id
);
$this
->
assertEquals
(
$user
->
_id
,
$role
->
user_id
);
}
}
public
function
testBelongsToMany
()
public
function
testBelongsToMany
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
...
@@ -222,7 +223,7 @@ class RelationsTest extends TestCase
...
@@ -222,7 +223,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
1
,
$client
->
users
);
$this
->
assertCount
(
1
,
$client
->
users
);
}
}
public
function
testBelongsToManyAttachesExistingModels
()
public
function
testBelongsToManyAttachesExistingModels
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
,
'client_ids'
=>
[
'1234523'
]]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
,
'client_ids'
=>
[
'1234523'
]]);
...
@@ -261,7 +262,7 @@ class RelationsTest extends TestCase
...
@@ -261,7 +262,7 @@ class RelationsTest extends TestCase
$this
->
assertStringStartsWith
(
'synced'
,
$user
->
clients
[
1
]
->
name
);
$this
->
assertStringStartsWith
(
'synced'
,
$user
->
clients
[
1
]
->
name
);
}
}
public
function
testBelongsToManySync
()
public
function
testBelongsToManySync
()
:
void
{
{
// create test instances
// create test instances
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
...
@@ -280,7 +281,7 @@ class RelationsTest extends TestCase
...
@@ -280,7 +281,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
1
,
$user
->
clients
);
$this
->
assertCount
(
1
,
$user
->
clients
);
}
}
public
function
testBelongsToManyAttachArray
()
public
function
testBelongsToManyAttachArray
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
])
->
_id
;
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
])
->
_id
;
...
@@ -291,7 +292,7 @@ class RelationsTest extends TestCase
...
@@ -291,7 +292,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
2
,
$user
->
clients
);
$this
->
assertCount
(
2
,
$user
->
clients
);
}
}
public
function
testBelongsToManyAttachEloquentCollection
()
public
function
testBelongsToManyAttachEloquentCollection
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
]);
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
]);
...
@@ -303,7 +304,7 @@ class RelationsTest extends TestCase
...
@@ -303,7 +304,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
2
,
$user
->
clients
);
$this
->
assertCount
(
2
,
$user
->
clients
);
}
}
public
function
testBelongsToManySyncAlreadyPresent
()
public
function
testBelongsToManySyncAlreadyPresent
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
])
->
_id
;
$client1
=
Client
::
create
([
'name'
=>
'Test 1'
])
->
_id
;
...
@@ -320,7 +321,7 @@ class RelationsTest extends TestCase
...
@@ -320,7 +321,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
1
,
$user
[
'client_ids'
]);
$this
->
assertCount
(
1
,
$user
[
'client_ids'
]);
}
}
public
function
testBelongsToManyCustom
()
public
function
testBelongsToManyCustom
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$group
=
$user
->
groups
()
->
create
([
'name'
=>
'Admins'
]);
$group
=
$user
->
groups
()
->
create
([
'name'
=>
'Admins'
]);
...
@@ -340,7 +341,7 @@ class RelationsTest extends TestCase
...
@@ -340,7 +341,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
$user
->
_id
,
$group
->
users
()
->
first
()
->
_id
);
$this
->
assertEquals
(
$user
->
_id
,
$group
->
users
()
->
first
()
->
_id
);
}
}
public
function
testMorph
()
public
function
testMorph
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client
=
Client
::
create
([
'name'
=>
'Jane Doe'
]);
$client
=
Client
::
create
([
'name'
=>
'Jane Doe'
]);
...
@@ -383,7 +384,7 @@ class RelationsTest extends TestCase
...
@@ -383,7 +384,7 @@ class RelationsTest extends TestCase
$this
->
assertInstanceOf
(
'Client'
,
$photos
[
1
]
->
imageable
);
$this
->
assertInstanceOf
(
'Client'
,
$photos
[
1
]
->
imageable
);
}
}
public
function
testHasManyHas
()
public
function
testHasManyHas
()
:
void
{
{
$author1
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
$author1
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
$author1
->
books
()
->
create
([
'title'
=>
'A Game of Thrones'
,
'rating'
=>
5
]);
$author1
->
books
()
->
create
([
'title'
=>
'A Game of Thrones'
,
'rating'
=>
5
]);
...
@@ -433,7 +434,7 @@ class RelationsTest extends TestCase
...
@@ -433,7 +434,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
1
,
$authors
);
$this
->
assertCount
(
1
,
$authors
);
}
}
public
function
testHasOneHas
()
public
function
testHasOneHas
()
:
void
{
{
$user1
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user1
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user1
->
role
()
->
create
([
'title'
=>
'admin'
]);
$user1
->
role
()
->
create
([
'title'
=>
'admin'
]);
...
@@ -455,7 +456,7 @@ class RelationsTest extends TestCase
...
@@ -455,7 +456,7 @@ class RelationsTest extends TestCase
$this
->
assertCount
(
2
,
$users
);
$this
->
assertCount
(
2
,
$users
);
}
}
public
function
testNestedKeys
()
public
function
testNestedKeys
()
:
void
{
{
$client
=
Client
::
create
([
$client
=
Client
::
create
([
'data'
=>
[
'data'
=>
[
...
@@ -481,7 +482,7 @@ class RelationsTest extends TestCase
...
@@ -481,7 +482,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
'Paris'
,
$client
->
addresses
->
first
()
->
data
[
'city'
]);
$this
->
assertEquals
(
'Paris'
,
$client
->
addresses
->
first
()
->
data
[
'city'
]);
}
}
public
function
testDoubleSaveOneToMany
()
public
function
testDoubleSaveOneToMany
()
:
void
{
{
$author
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
$author
=
User
::
create
([
'name'
=>
'George R. R. Martin'
]);
$book
=
Book
::
create
([
'title'
=>
'A Game of Thrones'
]);
$book
=
Book
::
create
([
'title'
=>
'A Game of Thrones'
]);
...
@@ -504,7 +505,7 @@ class RelationsTest extends TestCase
...
@@ -504,7 +505,7 @@ class RelationsTest extends TestCase
$this
->
assertEquals
(
$author
->
_id
,
$book
->
author_id
);
$this
->
assertEquals
(
$author
->
_id
,
$book
->
author_id
);
}
}
public
function
testDoubleSaveManyToMany
()
public
function
testDoubleSaveManyToMany
()
:
void
{
{
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$user
=
User
::
create
([
'name'
=>
'John Doe'
]);
$client
=
Client
::
create
([
'name'
=>
'Admins'
]);
$client
=
Client
::
create
([
'name'
=>
'Admins'
]);
...
...
tests/SchemaTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
class
SchemaTest
extends
TestCase
class
SchemaTest
extends
TestCase
{
{
...
@@ -8,14 +9,14 @@ class SchemaTest extends TestCase
...
@@ -8,14 +9,14 @@ class SchemaTest extends TestCase
Schema
::
drop
(
'newcollection_two'
);
Schema
::
drop
(
'newcollection_two'
);
}
}
public
function
testCreate
()
public
function
testCreate
()
:
void
{
{
Schema
::
create
(
'newcollection'
);
Schema
::
create
(
'newcollection'
);
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection'
));
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection'
));
$this
->
assertTrue
(
Schema
::
hasTable
(
'newcollection'
));
$this
->
assertTrue
(
Schema
::
hasTable
(
'newcollection'
));
}
}
public
function
testCreateWithCallback
()
public
function
testCreateWithCallback
()
:
void
{
{
$instance
=
$this
;
$instance
=
$this
;
...
@@ -26,21 +27,21 @@ class SchemaTest extends TestCase
...
@@ -26,21 +27,21 @@ class SchemaTest extends TestCase
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection'
));
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection'
));
}
}
public
function
testCreateWithOptions
()
public
function
testCreateWithOptions
()
:
void
{
{
Schema
::
create
(
'newcollection_two'
,
null
,
[
'capped'
=>
true
,
'size'
=>
1024
]);
Schema
::
create
(
'newcollection_two'
,
null
,
[
'capped'
=>
true
,
'size'
=>
1024
]);
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection_two'
));
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection_two'
));
$this
->
assertTrue
(
Schema
::
hasTable
(
'newcollection_two'
));
$this
->
assertTrue
(
Schema
::
hasTable
(
'newcollection_two'
));
}
}
public
function
testDrop
()
public
function
testDrop
()
:
void
{
{
Schema
::
create
(
'newcollection'
);
Schema
::
create
(
'newcollection'
);
Schema
::
drop
(
'newcollection'
);
Schema
::
drop
(
'newcollection'
);
$this
->
assertFalse
(
Schema
::
hasCollection
(
'newcollection'
));
$this
->
assertFalse
(
Schema
::
hasCollection
(
'newcollection'
));
}
}
public
function
testBluePrint
()
public
function
testBluePrint
()
:
void
{
{
$instance
=
$this
;
$instance
=
$this
;
...
@@ -53,7 +54,7 @@ class SchemaTest extends TestCase
...
@@ -53,7 +54,7 @@ class SchemaTest extends TestCase
});
});
}
}
public
function
testIndex
()
public
function
testIndex
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
index
(
'mykey1'
);
$collection
->
index
(
'mykey1'
);
...
@@ -77,7 +78,7 @@ class SchemaTest extends TestCase
...
@@ -77,7 +78,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'mykey3'
]);
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'mykey3'
]);
}
}
public
function
testPrimary
()
public
function
testPrimary
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
string
(
'mykey'
,
100
)
->
primary
();
$collection
->
string
(
'mykey'
,
100
)
->
primary
();
...
@@ -87,7 +88,7 @@ class SchemaTest extends TestCase
...
@@ -87,7 +88,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'unique'
]);
$this
->
assertEquals
(
1
,
$index
[
'unique'
]);
}
}
public
function
testUnique
()
public
function
testUnique
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
unique
(
'uniquekey'
);
$collection
->
unique
(
'uniquekey'
);
...
@@ -97,7 +98,7 @@ class SchemaTest extends TestCase
...
@@ -97,7 +98,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'unique'
]);
$this
->
assertEquals
(
1
,
$index
[
'unique'
]);
}
}
public
function
testDropIndex
()
public
function
testDropIndex
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
unique
(
'uniquekey'
);
$collection
->
unique
(
'uniquekey'
);
...
@@ -144,7 +145,7 @@ class SchemaTest extends TestCase
...
@@ -144,7 +145,7 @@ class SchemaTest extends TestCase
$this
->
assertFalse
(
$index
);
$this
->
assertFalse
(
$index
);
}
}
public
function
testBackground
()
public
function
testBackground
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
background
(
'backgroundkey'
);
$collection
->
background
(
'backgroundkey'
);
...
@@ -154,7 +155,7 @@ class SchemaTest extends TestCase
...
@@ -154,7 +155,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'background'
]);
$this
->
assertEquals
(
1
,
$index
[
'background'
]);
}
}
public
function
testSparse
()
public
function
testSparse
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
sparse
(
'sparsekey'
);
$collection
->
sparse
(
'sparsekey'
);
...
@@ -164,7 +165,7 @@ class SchemaTest extends TestCase
...
@@ -164,7 +165,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'sparse'
]);
$this
->
assertEquals
(
1
,
$index
[
'sparse'
]);
}
}
public
function
testExpire
()
public
function
testExpire
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
expire
(
'expirekey'
,
60
);
$collection
->
expire
(
'expirekey'
,
60
);
...
@@ -174,7 +175,7 @@ class SchemaTest extends TestCase
...
@@ -174,7 +175,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
60
,
$index
[
'expireAfterSeconds'
]);
$this
->
assertEquals
(
60
,
$index
[
'expireAfterSeconds'
]);
}
}
public
function
testSoftDeletes
()
public
function
testSoftDeletes
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
softDeletes
();
$collection
->
softDeletes
();
...
@@ -188,7 +189,7 @@ class SchemaTest extends TestCase
...
@@ -188,7 +189,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'email'
]);
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'email'
]);
}
}
public
function
testFluent
()
public
function
testFluent
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
string
(
'email'
)
->
index
();
$collection
->
string
(
'email'
)
->
index
();
...
@@ -203,7 +204,7 @@ class SchemaTest extends TestCase
...
@@ -203,7 +204,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'token'
]);
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'token'
]);
}
}
public
function
testGeospatial
()
public
function
testGeospatial
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
geospatial
(
'point'
);
$collection
->
geospatial
(
'point'
);
...
@@ -221,7 +222,7 @@ class SchemaTest extends TestCase
...
@@ -221,7 +222,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
'2dsphere'
,
$index
[
'key'
][
'continent'
]);
$this
->
assertEquals
(
'2dsphere'
,
$index
[
'key'
][
'continent'
]);
}
}
public
function
testDummies
()
public
function
testDummies
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
boolean
(
'activated'
)
->
default
(
0
);
$collection
->
boolean
(
'activated'
)
->
default
(
0
);
...
@@ -229,7 +230,7 @@ class SchemaTest extends TestCase
...
@@ -229,7 +230,7 @@ class SchemaTest extends TestCase
});
});
}
}
public
function
testSparseUnique
()
public
function
testSparseUnique
()
:
void
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
sparse_and_unique
(
'sparseuniquekey'
);
$collection
->
sparse_and_unique
(
'sparseuniquekey'
);
...
@@ -240,7 +241,7 @@ class SchemaTest extends TestCase
...
@@ -240,7 +241,7 @@ class SchemaTest extends TestCase
$this
->
assertEquals
(
1
,
$index
[
'unique'
]);
$this
->
assertEquals
(
1
,
$index
[
'unique'
]);
}
}
protected
function
getIndex
(
$collection
,
$name
)
protected
function
getIndex
(
string
$collection
,
string
$name
)
{
{
$collection
=
DB
::
getCollection
(
$collection
);
$collection
=
DB
::
getCollection
(
$collection
);
...
...
tests/SeederTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
class
SeederTest
extends
TestCase
class
SeederTest
extends
TestCase
{
{
...
@@ -7,7 +8,7 @@ class SeederTest extends TestCase
...
@@ -7,7 +8,7 @@ class SeederTest extends TestCase
User
::
truncate
();
User
::
truncate
();
}
}
public
function
testSeed
()
public
function
testSeed
()
:
void
{
{
$seeder
=
new
UserTableSeeder
;
$seeder
=
new
UserTableSeeder
;
$seeder
->
run
();
$seeder
->
run
();
...
@@ -16,7 +17,7 @@ class SeederTest extends TestCase
...
@@ -16,7 +17,7 @@ class SeederTest extends TestCase
$this
->
assertTrue
(
$user
->
seed
);
$this
->
assertTrue
(
$user
->
seed
);
}
}
public
function
testArtisan
()
public
function
testArtisan
()
:
void
{
{
Artisan
::
call
(
'db:seed'
);
Artisan
::
call
(
'db:seed'
);
...
...
tests/TestCase.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Auth\Passwords\PasswordResetServiceProvider
;
class
TestCase
extends
Orchestra\Testbench\TestCase
class
TestCase
extends
Orchestra\Testbench\TestCase
{
{
...
@@ -13,7 +16,7 @@ class TestCase extends Orchestra\Testbench\TestCase
...
@@ -13,7 +16,7 @@ class TestCase extends Orchestra\Testbench\TestCase
{
{
$providers
=
parent
::
getApplicationProviders
(
$app
);
$providers
=
parent
::
getApplicationProviders
(
$app
);
unset
(
$providers
[
array_search
(
'Illuminate\Auth\Passwords\PasswordResetServiceProvider'
,
$providers
)]);
unset
(
$providers
[
array_search
(
PasswordResetServiceProvider
::
class
,
$providers
)]);
return
$providers
;
return
$providers
;
}
}
...
...
tests/ValidationTest.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
class
ValidationTest
extends
TestCase
class
ValidationTest
extends
TestCase
{
{
...
@@ -7,7 +8,7 @@ class ValidationTest extends TestCase
...
@@ -7,7 +8,7 @@ class ValidationTest extends TestCase
User
::
truncate
();
User
::
truncate
();
}
}
public
function
testUnique
()
public
function
testUnique
()
:
void
{
{
$validator
=
Validator
::
make
(
$validator
=
Validator
::
make
(
[
'name'
=>
'John Doe'
],
[
'name'
=>
'John Doe'
],
...
@@ -42,7 +43,7 @@ class ValidationTest extends TestCase
...
@@ -42,7 +43,7 @@ class ValidationTest extends TestCase
$this
->
assertFalse
(
$validator
->
fails
());
$this
->
assertFalse
(
$validator
->
fails
());
}
}
public
function
testExists
()
public
function
testExists
()
:
void
{
{
$validator
=
Validator
::
make
(
$validator
=
Validator
::
make
(
[
'name'
=>
'John Doe'
],
[
'name'
=>
'John Doe'
],
...
...
tests/config/database.php
View file @
47398ff4
...
@@ -25,7 +25,7 @@ return [
...
@@ -25,7 +25,7 @@ return [
'host'
=>
env
(
'MYSQL_HOST'
,
'mysql'
),
'host'
=>
env
(
'MYSQL_HOST'
,
'mysql'
),
'database'
=>
env
(
'MYSQL_DATABASE'
,
'unittest'
),
'database'
=>
env
(
'MYSQL_DATABASE'
,
'unittest'
),
'username'
=>
env
(
'MYSQL_USERNAME'
,
'root'
),
'username'
=>
env
(
'MYSQL_USERNAME'
,
'root'
),
'password'
=>
''
,
'password'
=>
env
(
'MYSQL_PASSWORD'
,
''
)
,
'charset'
=>
'utf8'
,
'charset'
=>
'utf8'
,
'collation'
=>
'utf8_unicode_ci'
,
'collation'
=>
'utf8_unicode_ci'
,
'prefix'
=>
''
,
'prefix'
=>
''
,
...
...
tests/models/Address.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Relations\EmbedsMany
;
class
Address
extends
Eloquent
class
Address
extends
Eloquent
{
{
protected
$connection
=
'mongodb'
;
protected
$connection
=
'mongodb'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
addresses
()
public
function
addresses
()
:
EmbedsMany
{
{
return
$this
->
embedsMany
(
'Address'
);
return
$this
->
embedsMany
(
'Address'
);
}
}
...
...
tests/models/Book.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
/**
* Class Book
*
* @property string $title
* @property string $author
* @property array $chapters
*/
class
Book
extends
Eloquent
class
Book
extends
Eloquent
{
{
protected
$connection
=
'mongodb'
;
protected
$connection
=
'mongodb'
;
...
@@ -9,12 +18,12 @@ class Book extends Eloquent
...
@@ -9,12 +18,12 @@ class Book extends Eloquent
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
protected
$primaryKey
=
'title'
;
protected
$primaryKey
=
'title'
;
public
function
author
()
public
function
author
()
:
BelongsTo
{
{
return
$this
->
belongsTo
(
'User'
,
'author_id'
);
return
$this
->
belongsTo
(
'User'
,
'author_id'
);
}
}
public
function
mysqlAuthor
()
public
function
mysqlAuthor
()
:
BelongsTo
{
{
return
$this
->
belongsTo
(
'MysqlUser'
,
'author_id'
);
return
$this
->
belongsTo
(
'MysqlUser'
,
'author_id'
);
}
}
...
...
tests/models/Client.php
View file @
47398ff4
<?php
<?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
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Client
extends
Eloquent
class
Client
extends
Eloquent
...
@@ -8,17 +12,17 @@ class Client extends Eloquent
...
@@ -8,17 +12,17 @@ class Client extends Eloquent
protected
$collection
=
'clients'
;
protected
$collection
=
'clients'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
users
()
public
function
users
()
:
BelongsToMany
{
{
return
$this
->
belongsToMany
(
'User'
);
return
$this
->
belongsToMany
(
'User'
);
}
}
public
function
photo
()
public
function
photo
()
:
MorphOne
{
{
return
$this
->
morphOne
(
'Photo'
,
'imageable'
);
return
$this
->
morphOne
(
'Photo'
,
'imageable'
);
}
}
public
function
addresses
()
public
function
addresses
()
:
HasMany
{
{
return
$this
->
hasMany
(
'Address'
,
'data.client_id'
,
'data.client_id'
);
return
$this
->
hasMany
(
'Address'
,
'data.client_id'
,
'data.client_id'
);
}
}
...
...
tests/models/Group.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Group
extends
Eloquent
class
Group
extends
Eloquent
...
@@ -8,7 +10,7 @@ class Group extends Eloquent
...
@@ -8,7 +10,7 @@ class Group extends Eloquent
protected
$collection
=
'groups'
;
protected
$collection
=
'groups'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
users
()
public
function
users
()
:
BelongsToMany
{
{
return
$this
->
belongsToMany
(
'User'
,
'users'
,
'groups'
,
'users'
,
'_id'
,
'_id'
,
'users'
);
return
$this
->
belongsToMany
(
'User'
,
'users'
,
'groups'
,
'users'
,
'_id'
,
'_id'
,
'users'
);
}
}
...
...
tests/models/Item.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
/**
* Class Item
*
* @property \Carbon\Carbon $created_at
*/
class
Item
extends
Eloquent
class
Item
extends
Eloquent
{
{
protected
$connection
=
'mongodb'
;
protected
$connection
=
'mongodb'
;
protected
$collection
=
'items'
;
protected
$collection
=
'items'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
user
()
public
function
user
()
:
BelongsTo
{
{
return
$this
->
belongsTo
(
'User'
);
return
$this
->
belongsTo
(
'User'
);
}
}
public
function
scopeSharp
(
$query
)
public
function
scopeSharp
(
Builder
$query
)
{
{
return
$query
->
where
(
'type'
,
'sharp'
);
return
$query
->
where
(
'type'
,
'sharp'
);
}
}
...
...
tests/models/Location.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
...
...
tests/models/MysqlBook.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Support\Facades\Schema
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
...
@@ -12,7 +15,7 @@ class MysqlBook extends Eloquent
...
@@ -12,7 +15,7 @@ class MysqlBook extends Eloquent
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
protected
$primaryKey
=
'title'
;
protected
$primaryKey
=
'title'
;
public
function
author
()
public
function
author
()
:
BelongsTo
{
{
return
$this
->
belongsTo
(
'User'
,
'author_id'
);
return
$this
->
belongsTo
(
'User'
,
'author_id'
);
}
}
...
@@ -20,12 +23,13 @@ class MysqlBook extends Eloquent
...
@@ -20,12 +23,13 @@ class MysqlBook extends Eloquent
/**
/**
* Check if we need to run the schema.
* 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'
);
$schema
=
Schema
::
connection
(
'mysql'
);
if
(
!
$schema
->
hasTable
(
'books'
))
{
if
(
!
$schema
->
hasTable
(
'books'
))
{
Schema
::
connection
(
'mysql'
)
->
create
(
'books'
,
function
(
$table
)
{
Schema
::
connection
(
'mysql'
)
->
create
(
'books'
,
function
(
Blueprint
$table
)
{
$table
->
string
(
'title'
);
$table
->
string
(
'title'
);
$table
->
string
(
'author_id'
)
->
nullable
();
$table
->
string
(
'author_id'
)
->
nullable
();
$table
->
integer
(
'mysql_user_id'
)
->
unsigned
()
->
nullable
();
$table
->
integer
(
'mysql_user_id'
)
->
unsigned
()
->
nullable
();
...
...
tests/models/MysqlRole.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Support\Facades\Schema
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
...
@@ -11,12 +14,12 @@ class MysqlRole extends Eloquent
...
@@ -11,12 +14,12 @@ class MysqlRole extends Eloquent
protected
$table
=
'roles'
;
protected
$table
=
'roles'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
user
()
public
function
user
()
:
BelongsTo
{
{
return
$this
->
belongsTo
(
'User'
);
return
$this
->
belongsTo
(
'User'
);
}
}
public
function
mysqlUser
()
public
function
mysqlUser
()
:
BelongsTo
{
{
return
$this
->
belongsTo
(
'MysqlUser'
);
return
$this
->
belongsTo
(
'MysqlUser'
);
}
}
...
@@ -26,10 +29,11 @@ class MysqlRole extends Eloquent
...
@@ -26,10 +29,11 @@ class MysqlRole extends Eloquent
*/
*/
public
static
function
executeSchema
()
public
static
function
executeSchema
()
{
{
/** @var \Illuminate\Database\Schema\MySqlBuilder $schema */
$schema
=
Schema
::
connection
(
'mysql'
);
$schema
=
Schema
::
connection
(
'mysql'
);
if
(
!
$schema
->
hasTable
(
'roles'
))
{
if
(
!
$schema
->
hasTable
(
'roles'
))
{
Schema
::
connection
(
'mysql'
)
->
create
(
'roles'
,
function
(
$table
)
{
Schema
::
connection
(
'mysql'
)
->
create
(
'roles'
,
function
(
Blueprint
$table
)
{
$table
->
string
(
'type'
);
$table
->
string
(
'type'
);
$table
->
string
(
'user_id'
);
$table
->
string
(
'user_id'
);
$table
->
timestamps
();
$table
->
timestamps
();
...
...
tests/models/MysqlUser.php
View file @
47398ff4
<?php
<?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
Illuminate\Support\Facades\Schema
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
...
@@ -11,17 +15,17 @@ class MysqlUser extends Eloquent
...
@@ -11,17 +15,17 @@ class MysqlUser extends Eloquent
protected
$table
=
'users'
;
protected
$table
=
'users'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
books
()
public
function
books
()
:
HasMany
{
{
return
$this
->
hasMany
(
'Book'
,
'author_id'
);
return
$this
->
hasMany
(
'Book'
,
'author_id'
);
}
}
public
function
role
()
public
function
role
()
:
HasOne
{
{
return
$this
->
hasOne
(
'Role'
);
return
$this
->
hasOne
(
'Role'
);
}
}
public
function
mysqlBooks
()
public
function
mysqlBooks
()
:
HasMany
{
{
return
$this
->
hasMany
(
MysqlBook
::
class
);
return
$this
->
hasMany
(
MysqlBook
::
class
);
}
}
...
@@ -29,12 +33,13 @@ class MysqlUser extends Eloquent
...
@@ -29,12 +33,13 @@ class MysqlUser extends Eloquent
/**
/**
* Check if we need to run the schema.
* 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'
);
$schema
=
Schema
::
connection
(
'mysql'
);
if
(
!
$schema
->
hasTable
(
'users'
))
{
if
(
!
$schema
->
hasTable
(
'users'
))
{
Schema
::
connection
(
'mysql'
)
->
create
(
'users'
,
function
(
$table
)
{
Schema
::
connection
(
'mysql'
)
->
create
(
'users'
,
function
(
Blueprint
$table
)
{
$table
->
increments
(
'id'
);
$table
->
increments
(
'id'
);
$table
->
string
(
'name'
);
$table
->
string
(
'name'
);
$table
->
timestamps
();
$table
->
timestamps
();
...
...
tests/models/Photo.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\MorphTo
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Photo
extends
Eloquent
class
Photo
extends
Eloquent
...
@@ -8,7 +10,7 @@ class Photo extends Eloquent
...
@@ -8,7 +10,7 @@ class Photo extends Eloquent
protected
$collection
=
'photos'
;
protected
$collection
=
'photos'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
imageable
()
public
function
imageable
()
:
MorphTo
{
{
return
$this
->
morphTo
();
return
$this
->
morphTo
();
}
}
...
...
tests/models/Role.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Role
extends
Eloquent
class
Role
extends
Eloquent
...
@@ -8,12 +10,12 @@ class Role extends Eloquent
...
@@ -8,12 +10,12 @@ class Role extends Eloquent
protected
$collection
=
'roles'
;
protected
$collection
=
'roles'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
user
()
public
function
user
()
:
BelongsTo
{
{
return
$this
->
belongsTo
(
'User'
);
return
$this
->
belongsTo
(
'User'
);
}
}
public
function
mysqlUser
()
public
function
mysqlUser
()
:
BelongsTo
{
{
return
$this
->
belongsTo
(
'MysqlUser'
);
return
$this
->
belongsTo
(
'MysqlUser'
);
}
}
...
...
tests/models/Scoped.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
...
...
tests/models/Soft.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\SoftDeletes
;
use
Jenssegers\Mongodb\Eloquent\SoftDeletes
;
/**
* Class Soft
*
* @property \Carbon\Carbon $deleted_at
*/
class
Soft
extends
Eloquent
class
Soft
extends
Eloquent
{
{
use
SoftDeletes
;
use
SoftDeletes
;
...
...
tests/models/User.php
View file @
47398ff4
<?php
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Notifications\Notifiable
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Illuminate\Auth\Authenticatable
;
use
Illuminate\Auth\Authenticatable
;
...
@@ -7,9 +9,20 @@ use Illuminate\Auth\Passwords\CanResetPassword;
...
@@ -7,9 +9,20 @@ use Illuminate\Auth\Passwords\CanResetPassword;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Contracts\Auth\CanResetPassword
as
CanResetPasswordContract
;
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
class
User
extends
Eloquent
implements
AuthenticatableContract
,
CanResetPasswordContract
{
{
use
Authenticatable
,
CanResetPassword
,
HybridRelations
;
use
Authenticatable
,
CanResetPassword
,
HybridRelations
,
Notifiable
;
protected
$connection
=
'mongodb'
;
protected
$connection
=
'mongodb'
;
protected
$dates
=
[
'birthday'
,
'entry.date'
];
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