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
6ffda75b
Commit
6ffda75b
authored
Aug 23, 2019
by
Simon Schaufelberger
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master' into patch-1
parents
3f588096
01ac069c
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
108 additions
and
26 deletions
+108
-26
.editorconfig
.editorconfig
+9
-0
README.md
README.md
+1
-1
phpunit.xml.dist
phpunit.xml.dist
+20
-11
Builder.php
src/Jenssegers/Mongodb/Eloquent/Builder.php
+1
-1
Model.php
src/Jenssegers/Mongodb/Eloquent/Model.php
+2
-2
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+12
-2
QueryBuilderTest.php
tests/QueryBuilderTest.php
+12
-0
QueryTest.php
tests/QueryTest.php
+18
-0
QueueTest.php
tests/QueueTest.php
+1
-0
database.php
tests/config/database.php
+10
-7
queue.php
tests/config/queue.php
+2
-2
Scoped.php
tests/models/Scoped.php
+20
-0
No files found.
.editorconfig
0 → 100644
View file @
6ffda75b
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
\ No newline at end of file
README.md
View file @
6ffda75b
...
...
@@ -484,7 +484,7 @@ User::where('name', 'Jaques')->decrement('weight', 50);
The number of updated objects is returned:
```
php
$count
=
User
->
increment
(
'age'
);
$count
=
User
::
increment
(
'age'
);
```
You may also specify additional columns to update:
...
...
phpunit.xml.dist
View file @
6ffda75b
...
...
@@ -15,31 +15,40 @@
<directory>
tests/
</directory>
</testsuite>
<testsuite
name=
"schema"
>
<
directory>
tests/SchemaTest.php
</directory
>
<
file>
tests/SchemaTest.php
</file
>
</testsuite>
<testsuite
name=
"seeder"
>
<
directory>
tests/SeederTest.php
</directory
>
<
file>
tests/SeederTest.php
</file
>
</testsuite>
<testsuite
name=
"cache"
>
<
directory>
tests/CacheTest.php
</directory
>
<
file>
tests/CacheTest.php
</file
>
</testsuite>
<testsuite
name=
"builder"
>
<
directory>
tests/QueryBuilderTest.php
</directory
>
<
directory>
tests/QueryTest.php
</directory
>
<
file>
tests/QueryBuilderTest.php
</file
>
<
file>
tests/QueryTest.php
</file
>
</testsuite>
<testsuite
name=
"model"
>
<
directory>
tests/ModelTest.php
</directory
>
<
directory>
tests/RelationsTest.php
</directory
>
<
file>
tests/ModelTest.php
</file
>
<
file>
tests/RelationsTest.php
</file
>
</testsuite>
<testsuite
name=
"relations"
>
<
directory>
tests/RelationsTest.php
</directory
>
<
directory>
tests/EmbeddedRelationsTest.php
</directory
>
<
file>
tests/RelationsTest.php
</file
>
<
file>
tests/EmbeddedRelationsTest.php
</file
>
</testsuite>
<testsuite
name=
"mysqlrelations"
>
<
directory>
tests/RelationsTest.php
</directory
>
<
file>
tests/RelationsTest.php
</file
>
</testsuite>
<testsuite
name=
"validation"
>
<
directory>
tests/ValidationTest.php
</directory
>
<
file>
tests/ValidationTest.php
</file
>
</testsuite>
</testsuites>
<php>
<env
name=
"MONGO_HOST"
value=
"mongodb"
/>
<env
name=
"MONGO_DATABASE"
value=
"unittest"
/>
<env
name=
"MONGO_PORT"
value=
"27017"
/>
<env
name=
"MYSQL_HOST"
value=
"mysql"
/>
<env
name=
"MYSQL_DATABASE"
value=
"unittest"
/>
<env
name=
"MYSQL_USERNAME"
value=
"root"
/>
<env
name=
"QUEUE_CONNECTION"
value=
"database"
/>
</php>
</phpunit>
src/Jenssegers/Mongodb/Eloquent/Builder.php
View file @
6ffda75b
...
...
@@ -44,7 +44,7 @@ class Builder extends EloquentBuilder
return
1
;
}
return
$this
->
query
->
update
(
$this
->
addUpdatedAtColumn
(
$values
),
$options
);
return
$this
->
toBase
()
->
update
(
$this
->
addUpdatedAtColumn
(
$values
),
$options
);
}
/**
...
...
src/Jenssegers/Mongodb/Eloquent/Model.php
View file @
6ffda75b
...
...
@@ -32,7 +32,7 @@ abstract class Model extends BaseModel
* @var string
*/
protected
$primaryKey
=
'_id'
;
/**
* The primary key type.
*
...
...
@@ -175,7 +175,7 @@ abstract class Model extends BaseModel
public
function
setAttribute
(
$key
,
$value
)
{
// Convert _id to ObjectID.
if
(
(
$key
==
'_id'
||
Str
::
endsWith
(
$key
,
'_id'
))
&&
is_string
(
$value
))
{
if
(
$key
==
'_id'
&&
is_string
(
$value
))
{
$builder
=
$this
->
newBaseQueryBuilder
();
$value
=
$builder
->
convertKey
(
$value
);
...
...
src/Jenssegers/Mongodb/Query/Builder.php
View file @
6ffda75b
...
...
@@ -204,6 +204,16 @@ class Builder extends BaseBuilder
return
$this
->
where
(
'_id'
,
'='
,
$this
->
convertKey
(
$id
))
->
first
(
$columns
);
}
/**
* @inheritdoc
*/
public
function
value
(
$column
)
{
$result
=
(
array
)
$this
->
first
([
$column
]);
return
Arr
::
get
(
$result
,
$column
);
}
/**
* @inheritdoc
*/
...
...
@@ -844,7 +854,7 @@ class Builder extends BaseBuilder
{
if
(
is_string
(
$id
)
&&
strlen
(
$id
)
===
24
&&
ctype_xdigit
(
$id
))
{
return
new
ObjectID
(
$id
);
}
elseif
(
strlen
(
$id
)
===
16
&&
preg_match
(
'~[^\x20-\x7E\t\r\n]~'
,
$id
)
>
0
)
{
}
elseif
(
is_string
(
$id
)
&&
strlen
(
$id
)
===
16
&&
preg_match
(
'~[^\x20-\x7E\t\r\n]~'
,
$id
)
>
0
)
{
return
new
Binary
(
$id
,
Binary
::
TYPE_UUID
);
}
...
...
@@ -906,7 +916,7 @@ class Builder extends BaseBuilder
}
// Convert id's.
if
(
isset
(
$where
[
'column'
])
&&
(
$where
[
'column'
]
==
'_id'
||
Str
::
endsWith
(
$where
[
'column'
],
'_id'
)))
{
if
(
isset
(
$where
[
'column'
])
&&
(
$where
[
'column'
]
==
'_id'
||
Str
::
endsWith
(
$where
[
'column'
],
'
.
_id'
)))
{
// Multiple values.
if
(
isset
(
$where
[
'values'
]))
{
foreach
(
$where
[
'values'
]
as
&
$value
)
{
...
...
tests/QueryBuilderTest.php
View file @
6ffda75b
...
...
@@ -701,4 +701,16 @@ class QueryBuilderTest extends TestCase
$this
->
assertEquals
(
1
,
count
(
$result
[
'tags'
]));
}
}
public
function
testValue
()
{
DB
::
collection
(
'books'
)
->
insert
([
[
'title'
=>
'Moby-Dick'
,
'author'
=>
[
'first_name'
=>
'Herman'
,
'last_name'
=>
'Melville'
]]
]);
$this
->
assertEquals
(
'Moby-Dick'
,
DB
::
collection
(
'books'
)
->
value
(
'title'
));
$this
->
assertEquals
([
'first_name'
=>
'Herman'
,
'last_name'
=>
'Melville'
],
DB
::
collection
(
'books'
)
->
value
(
'author'
));
$this
->
assertEquals
(
'Herman'
,
DB
::
collection
(
'books'
)
->
value
(
'author.first_name'
));
$this
->
assertEquals
(
'Melville'
,
DB
::
collection
(
'books'
)
->
value
(
'author.last_name'
));
}
}
tests/QueryTest.php
View file @
6ffda75b
...
...
@@ -21,6 +21,7 @@ class QueryTest extends TestCase
public
function
tearDown
()
:
void
{
User
::
truncate
();
Scoped
::
truncate
();
parent
::
tearDown
();
}
...
...
@@ -309,4 +310,21 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
9
,
$results
->
total
());
$this
->
assertEquals
(
1
,
$results
->
currentPage
());
}
public
function
testUpdate
()
{
$this
->
assertEquals
(
1
,
User
::
where
([
'name'
=>
'John Doe'
])
->
update
([
'name'
=>
'Jim Morrison'
]));
$this
->
assertEquals
(
1
,
User
::
where
([
'name'
=>
'Jim Morrison'
])
->
count
());
Scoped
::
create
([
'favorite'
=>
true
]);
Scoped
::
create
([
'favorite'
=>
false
]);
$this
->
assertCount
(
1
,
Scoped
::
get
());
$this
->
assertEquals
(
1
,
Scoped
::
query
()
->
update
([
'name'
=>
'Johnny'
]));
$this
->
assertCount
(
1
,
Scoped
::
withoutGlobalScopes
()
->
where
([
'name'
=>
'Johnny'
])
->
get
());
$this
->
assertCount
(
2
,
Scoped
::
withoutGlobalScopes
()
->
get
());
$this
->
assertEquals
(
2
,
Scoped
::
withoutGlobalScopes
()
->
update
([
'name'
=>
'Jimmy'
]));
$this
->
assertCount
(
2
,
Scoped
::
withoutGlobalScopes
()
->
where
([
'name'
=>
'Jimmy'
])
->
get
());
}
}
tests/QueueTest.php
View file @
6ffda75b
...
...
@@ -24,6 +24,7 @@ class QueueTest extends TestCase
'displayName'
=>
'test'
,
'job'
=>
'test'
,
'maxTries'
=>
null
,
'delay'
=>
null
,
'timeout'
=>
null
,
'data'
=>
[
'action'
=>
'QueueJobLifeCycle'
],
]),
$job
->
getRawBody
());
...
...
tests/config/database.php
View file @
6ffda75b
<?php
$mongoHost
=
env
(
'MONGO_HOST'
,
'mongodb'
);
$mongoPort
=
env
(
'MONGO_PORT'
)
?
(
int
)
env
(
'MONGO_PORT'
)
:
27017
;
return
[
'connections'
=>
[
...
...
@@ -7,21 +10,21 @@ return [
'mongodb'
=>
[
'name'
=>
'mongodb'
,
'driver'
=>
'mongodb'
,
'host'
=>
'mongodb'
,
'database'
=>
'unittest'
,
'host'
=>
$mongoHost
,
'database'
=>
env
(
'MONGO_DATABASE'
,
'unittest'
)
,
],
'dsn_mongodb'
=>
[
'driver'
=>
'mongodb'
,
'dsn'
=>
'mongodb://mongodb:27017'
,
'database'
=>
'unittest'
,
'dsn'
=>
"mongodb://
$mongoHost
:
$mongoPort
"
,
'database'
=>
env
(
'MONGO_DATABASE'
,
'unittest'
)
,
],
'mysql'
=>
[
'driver'
=>
'mysql'
,
'host'
=>
'mysql'
,
'database'
=>
'unittest'
,
'username'
=>
'root'
,
'host'
=>
env
(
'MYSQL_HOST'
,
'mysql'
)
,
'database'
=>
env
(
'MYSQL_DATABASE'
,
'unittest'
)
,
'username'
=>
env
(
'MYSQL_USERNAME'
,
'root'
)
,
'password'
=>
''
,
'charset'
=>
'utf8'
,
'collation'
=>
'utf8_unicode_ci'
,
...
...
tests/config/queue.php
View file @
6ffda75b
...
...
@@ -2,7 +2,7 @@
return
[
'default'
=>
'database'
,
'default'
=>
env
(
'QUEUE_CONNECTION'
)
,
'connections'
=>
[
...
...
@@ -16,7 +16,7 @@ return [
],
'failed'
=>
[
'database'
=>
'mongodb'
,
'database'
=>
env
(
'MONGO_DATABASE'
)
,
'table'
=>
'failed_jobs'
,
],
...
...
tests/models/Scoped.php
0 → 100644
View file @
6ffda75b
<?php
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
class
Scoped
extends
Eloquent
{
protected
$connection
=
'mongodb'
;
protected
$collection
=
'scoped'
;
protected
$fillable
=
[
'name'
,
'favorite'
];
protected
static
function
boot
()
{
parent
::
boot
();
static
::
addGlobalScope
(
'favorite'
,
function
(
Builder
$builder
)
{
$builder
->
where
(
'favorite'
,
true
);
});
}
}
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