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
e821aec1
Commit
e821aec1
authored
Aug 23, 2019
by
Simon Schaufelberger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup
parent
01ac069c
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 @
e821aec1
...
...
@@ -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 @
e821aec1
...
...
@@ -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 @
e821aec1
...
...
@@ -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 @
e821aec1
...
...
@@ -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,15 +197,13 @@ 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
);
$class
=
$this
->
getActualClassNameForMorph
(
$class
);
$instance
=
new
$class
;
$instance
=
new
$class
;
return
new
MorphTo
(
$instance
->
newQuery
(),
$this
,
$id
,
$instance
->
getKeyName
(),
$type
,
$name
);
}
return
new
MorphTo
(
$instance
->
newQuery
(),
$this
,
$id
,
$instance
->
getKeyName
(),
$type
,
$name
);
}
/**
...
...
@@ -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 @
e821aec1
...
...
@@ -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,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 @
e821aec1
...
...
@@ -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 @
e821aec1
...
...
@@ -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 @
e821aec1
...
...
@@ -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 @
e821aec1
...
...
@@ -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 @
e821aec1
...
...
@@ -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 @
e821aec1
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Collection
;
...
...
tests/ConnectionTest.php
View file @
e821aec1
<?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 @
e821aec1
<?php
declare
(
strict_types
=
1
);
class
DsnTest
extends
TestCase
{
...
...
tests/EmbeddedRelationsTest.php
View file @
e821aec1
This diff is collapsed.
Click to expand it.
tests/GeospatialTest.php
View file @
e821aec1
<?php
declare
(
strict_types
=
1
);
class
GeospatialTest
extends
TestCase
{
...
...
tests/HybridRelationsTest.php
View file @
e821aec1
<?php
declare
(
strict_types
=
1
);
class
HybridRelationsTest
extends
TestCase
{
...
...
tests/ModelTest.php
View file @
e821aec1
This diff is collapsed.
Click to expand it.
tests/QueryBuilderTest.php
View file @
e821aec1
<?php
declare
(
strict_types
=
1
);
use
Illuminate\Support\Facades\DB
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\Regex
;
...
...
tests/QueryTest.php
View file @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
...
...
@@ -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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
...
...
tests/models/MysqlBook.php
View file @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?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 @
e821aec1
<?php
declare
(
strict_types
=
1
);
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
...
...
tests/models/Soft.php
View file @
e821aec1
<?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 @
e821aec1
<?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