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
93e53ec9
Commit
93e53ec9
authored
Nov 07, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding date tests for issue #51
parent
802e6c32
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
7 deletions
+38
-7
ModelTest.php
tests/ModelTest.php
+14
-0
QueryBuilderTest.php
tests/QueryBuilderTest.php
+21
-6
User.php
tests/models/User.php
+3
-1
No files found.
tests/ModelTest.php
View file @
93e53ec9
...
@@ -309,4 +309,18 @@ class ModelTest extends PHPUnit_Framework_TestCase {
...
@@ -309,4 +309,18 @@ class ModelTest extends PHPUnit_Framework_TestCase {
$this
->
assertFalse
(
isset
(
$user2
->
note2
));
$this
->
assertFalse
(
isset
(
$user2
->
note2
));
}
}
public
function
testDates
()
{
$user1
=
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'birthday'
=>
new
DateTime
(
'1980/1/1'
)));
$user2
=
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'birthday'
=>
new
DateTime
(
'1981/1/1'
)));
$this
->
assertInstanceOf
(
'DateTime'
,
$user1
->
birthday
);
// Re-fetch to be sure
$user1
=
User
::
find
(
$user1
->
_id
);
$user2
=
User
::
find
(
$user2
->
_id
);
$this
->
assertInstanceOf
(
'DateTime'
,
$user1
->
birthday
);
}
}
}
tests/QueryBuilderTest.php
View file @
93e53ec9
...
@@ -415,16 +415,31 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
...
@@ -415,16 +415,31 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
public
function
testUpdateSubdocument
()
public
function
testUpdateSubdocument
()
{
{
DB
::
collection
(
'users'
)
->
insertGetId
(
array
(
$id
=
DB
::
collection
(
'users'
)
->
insertGetId
(
array
(
'name'
=>
'John Doe'
,
'address'
=>
array
(
'country'
=>
'Belgium'
)));
'name'
=>
'John Doe'
,
'address'
=>
array
(
'country'
=>
'Belgium'
)
DB
::
collection
(
'users'
)
->
where
(
'_id'
,
$id
)
->
update
(
array
(
'address.country'
=>
'England'
));
$check
=
DB
::
collection
(
'users'
)
->
find
(
$id
);
$this
->
assertEquals
(
'England'
,
$check
[
'address'
][
'country'
]);
}
public
function
testDates
()
{
DB
::
collection
(
'users'
)
->
insert
(
array
(
array
(
'name'
=>
'John Doe'
,
'birthday'
=>
new
MongoDate
(
strtotime
(
"1980-01-01 00:00:00"
))),
array
(
'name'
=>
'Jane Doe'
,
'birthday'
=>
new
MongoDate
(
strtotime
(
"1981-01-01 00:00:00"
))),
array
(
'name'
=>
'Robert Roe'
,
'birthday'
=>
new
MongoDate
(
strtotime
(
"1982-01-01 00:00:00"
))),
array
(
'name'
=>
'Mark Moe'
,
'birthday'
=>
new
MongoDate
(
strtotime
(
"1983-01-01 00:00:00"
))),
));
));
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'John Doe'
)
->
update
(
array
(
'address.country'
=>
'England'
));
$user
=
DB
::
collection
(
'users'
)
->
where
(
'birthday'
,
new
MongoDate
(
strtotime
(
"1980-01-01 00:00:00"
)))
->
first
();
$this
->
assertEquals
(
'John Doe'
,
$user
[
'name'
]);
$check
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'John Doe'
)
->
first
();
$start
=
new
MongoDate
(
strtotime
(
"1981-01-01 00:00:00"
));
$stop
=
new
MongoDate
(
strtotime
(
"1982-01-01 00:00:00"
));
$this
->
assertEquals
(
'England'
,
$check
[
'address'
][
'country'
]);
$users
=
DB
::
collection
(
'users'
)
->
whereBetween
(
'birthday'
,
array
(
$start
,
$stop
))
->
get
();
$this
->
assertEquals
(
2
,
count
(
$users
));
}
}
}
}
tests/models/User.php
View file @
93e53ec9
...
@@ -9,6 +9,8 @@ class User extends Eloquent implements UserInterface, RemindableInterface {
...
@@ -9,6 +9,8 @@ class User extends Eloquent implements UserInterface, RemindableInterface {
protected
$collection
=
'users'
;
protected
$collection
=
'users'
;
protected
$dates
=
array
(
'birthday'
);
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
books
()
public
function
books
()
...
...
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