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
593b4a52
Commit
593b4a52
authored
Mar 29, 2015
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use short array notations in tests
parent
96039491
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
515 additions
and
515 deletions
+515
-515
AuthTest.php
tests/AuthTest.php
+8
-8
ConnectionTest.php
tests/ConnectionTest.php
+2
-2
EmbeddedRelationsTest.php
tests/EmbeddedRelationsTest.php
+139
-139
ModelTest.php
tests/ModelTest.php
+46
-46
MysqlRelationsTest.php
tests/MysqlRelationsTest.php
+4
-4
QueryBuilderTest.php
tests/QueryBuilderTest.php
+178
-178
QueryTest.php
tests/QueryTest.php
+22
-22
RelationsTest.php
tests/RelationsTest.php
+96
-96
SchemaTest.php
tests/SchemaTest.php
+2
-2
TestCase.php
tests/TestCase.php
+2
-2
ValidationTest.php
tests/ValidationTest.php
+5
-5
database.php
tests/config/database.php
+8
-8
Soft.php
tests/models/Soft.php
+1
-1
User.php
tests/models/User.php
+1
-1
UserTableSeeder.php
tests/seeds/UserTableSeeder.php
+1
-1
No files found.
tests/AuthTest.php
View file @
593b4a52
...
@@ -12,13 +12,13 @@ class AuthTest extends TestCase {
...
@@ -12,13 +12,13 @@ class AuthTest extends TestCase {
public
function
testAuthAttempt
()
public
function
testAuthAttempt
()
{
{
$user
=
User
::
create
(
array
(
$user
=
User
::
create
(
[
'name'
=>
'John Doe'
,
'name'
=>
'John Doe'
,
'email'
=>
'john@doe.com'
,
'email'
=>
'john@doe.com'
,
'password'
=>
Hash
::
make
(
'foobar'
)
'password'
=>
Hash
::
make
(
'foobar'
)
)
);
]
);
$this
->
assertTrue
(
Auth
::
attempt
(
array
(
'email'
=>
'john@doe.com'
,
'password'
=>
'foobar'
)
,
true
));
$this
->
assertTrue
(
Auth
::
attempt
(
[
'email'
=>
'john@doe.com'
,
'password'
=>
'foobar'
]
,
true
));
$this
->
assertTrue
(
Auth
::
check
());
$this
->
assertTrue
(
Auth
::
check
());
}
}
...
@@ -30,14 +30,14 @@ class AuthTest extends TestCase {
...
@@ -30,14 +30,14 @@ class AuthTest extends TestCase {
$broker
=
new
PasswordBroker
(
$tokens
,
$users
,
$mailer
,
''
);
$broker
=
new
PasswordBroker
(
$tokens
,
$users
,
$mailer
,
''
);
$user
=
User
::
create
(
array
(
$user
=
User
::
create
(
[
'name'
=>
'John Doe'
,
'name'
=>
'John Doe'
,
'email'
=>
'john@doe.com'
,
'email'
=>
'john@doe.com'
,
'password'
=>
Hash
::
make
(
'foobar'
)
'password'
=>
Hash
::
make
(
'foobar'
)
)
);
]
);
$mailer
->
shouldReceive
(
'send'
)
->
once
();
$mailer
->
shouldReceive
(
'send'
)
->
once
();
$broker
->
sendResetLink
(
array
(
'email'
=>
'john@doe.com'
)
);
$broker
->
sendResetLink
(
[
'email'
=>
'john@doe.com'
]
);
$this
->
assertEquals
(
1
,
DB
::
collection
(
'password_resets'
)
->
count
());
$this
->
assertEquals
(
1
,
DB
::
collection
(
'password_resets'
)
->
count
());
$reminder
=
DB
::
collection
(
'password_resets'
)
->
first
();
$reminder
=
DB
::
collection
(
'password_resets'
)
->
first
();
...
@@ -45,12 +45,12 @@ class AuthTest extends TestCase {
...
@@ -45,12 +45,12 @@ class AuthTest extends TestCase {
$this
->
assertNotNull
(
$reminder
[
'token'
]);
$this
->
assertNotNull
(
$reminder
[
'token'
]);
$this
->
assertInstanceOf
(
'MongoDate'
,
$reminder
[
'created_at'
]);
$this
->
assertInstanceOf
(
'MongoDate'
,
$reminder
[
'created_at'
]);
$credentials
=
array
(
$credentials
=
[
'email'
=>
'john@doe.com'
,
'email'
=>
'john@doe.com'
,
'password'
=>
'foobar'
,
'password'
=>
'foobar'
,
'password_confirmation'
=>
'foobar'
,
'password_confirmation'
=>
'foobar'
,
'token'
=>
$reminder
[
'token'
]
'token'
=>
$reminder
[
'token'
]
)
;
]
;
$response
=
$broker
->
reset
(
$credentials
,
function
(
$user
,
$password
)
$response
=
$broker
->
reset
(
$credentials
,
function
(
$user
,
$password
)
{
{
...
...
tests/ConnectionTest.php
View file @
593b4a52
...
@@ -71,13 +71,13 @@ class ConnectionTest extends TestCase {
...
@@ -71,13 +71,13 @@ class ConnectionTest extends TestCase {
DB
::
collection
(
'items'
)
->
get
();
DB
::
collection
(
'items'
)
->
get
();
$this
->
assertEquals
(
1
,
count
(
DB
::
getQueryLog
()));
$this
->
assertEquals
(
1
,
count
(
DB
::
getQueryLog
()));
DB
::
collection
(
'items'
)
->
insert
(
array
(
'name'
=>
'test'
)
);
DB
::
collection
(
'items'
)
->
insert
(
[
'name'
=>
'test'
]
);
$this
->
assertEquals
(
2
,
count
(
DB
::
getQueryLog
()));
$this
->
assertEquals
(
2
,
count
(
DB
::
getQueryLog
()));
DB
::
collection
(
'items'
)
->
count
();
DB
::
collection
(
'items'
)
->
count
();
$this
->
assertEquals
(
3
,
count
(
DB
::
getQueryLog
()));
$this
->
assertEquals
(
3
,
count
(
DB
::
getQueryLog
()));
DB
::
collection
(
'items'
)
->
where
(
'name'
,
'test'
)
->
update
(
array
(
'name'
=>
'test'
)
);
DB
::
collection
(
'items'
)
->
where
(
'name'
,
'test'
)
->
update
(
[
'name'
=>
'test'
]
);
$this
->
assertEquals
(
4
,
count
(
DB
::
getQueryLog
()));
$this
->
assertEquals
(
4
,
count
(
DB
::
getQueryLog
()));
DB
::
collection
(
'items'
)
->
where
(
'name'
,
'test'
)
->
delete
();
DB
::
collection
(
'items'
)
->
where
(
'name'
,
'test'
)
->
delete
();
...
...
tests/EmbeddedRelationsTest.php
View file @
593b4a52
This diff is collapsed.
Click to expand it.
tests/ModelTest.php
View file @
593b4a52
...
@@ -69,7 +69,7 @@ class ModelTest extends TestCase {
...
@@ -69,7 +69,7 @@ class ModelTest extends TestCase {
$this
->
assertEquals
(
'John Doe'
,
$check
->
name
);
$this
->
assertEquals
(
'John Doe'
,
$check
->
name
);
$this
->
assertEquals
(
36
,
$check
->
age
);
$this
->
assertEquals
(
36
,
$check
->
age
);
$user
->
update
(
array
(
'age'
=>
20
)
);
$user
->
update
(
[
'age'
=>
20
]
);
$raw
=
$user
->
getAttributes
();
$raw
=
$user
->
getAttributes
();
$this
->
assertInstanceOf
(
'MongoId'
,
$raw
[
'_id'
]);
$this
->
assertInstanceOf
(
'MongoId'
,
$raw
[
'_id'
]);
...
@@ -180,10 +180,10 @@ class ModelTest extends TestCase {
...
@@ -180,10 +180,10 @@ class ModelTest extends TestCase {
public
function
testGet
()
public
function
testGet
()
{
{
User
::
insert
(
array
(
User
::
insert
(
[
array
(
'name'
=>
'John Doe'
)
,
[
'name'
=>
'John Doe'
]
,
array
(
'name'
=>
'Jane Doe'
)
[
'name'
=>
'Jane Doe'
]
)
);
]
);
$users
=
User
::
get
();
$users
=
User
::
get
();
$this
->
assertEquals
(
2
,
count
(
$users
));
$this
->
assertEquals
(
2
,
count
(
$users
));
...
@@ -193,10 +193,10 @@ class ModelTest extends TestCase {
...
@@ -193,10 +193,10 @@ class ModelTest extends TestCase {
public
function
testFirst
()
public
function
testFirst
()
{
{
User
::
insert
(
array
(
User
::
insert
(
[
array
(
'name'
=>
'John Doe'
)
,
[
'name'
=>
'John Doe'
]
,
array
(
'name'
=>
'Jane Doe'
)
[
'name'
=>
'Jane Doe'
]
)
);
]
);
$user
=
User
::
first
();
$user
=
User
::
first
();
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Model'
,
$user
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Model'
,
$user
);
...
@@ -224,7 +224,7 @@ class ModelTest extends TestCase {
...
@@ -224,7 +224,7 @@ class ModelTest extends TestCase {
public
function
testCreate
()
public
function
testCreate
()
{
{
$user
=
User
::
create
(
array
(
'name'
=>
'Jane Poe'
)
);
$user
=
User
::
create
(
[
'name'
=>
'Jane Poe'
]
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Model'
,
$user
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Model'
,
$user
);
$this
->
assertEquals
(
true
,
$user
->
exists
);
$this
->
assertEquals
(
true
,
$user
->
exists
);
...
@@ -266,8 +266,8 @@ class ModelTest extends TestCase {
...
@@ -266,8 +266,8 @@ class ModelTest extends TestCase {
public
function
testSoftDelete
()
public
function
testSoftDelete
()
{
{
Soft
::
create
(
array
(
'name'
=>
'John Doe'
)
);
Soft
::
create
(
[
'name'
=>
'John Doe'
]
);
Soft
::
create
(
array
(
'name'
=>
'Jane Doe'
)
);
Soft
::
create
(
[
'name'
=>
'Jane Doe'
]
);
$this
->
assertEquals
(
2
,
Soft
::
count
());
$this
->
assertEquals
(
2
,
Soft
::
count
());
...
@@ -317,10 +317,10 @@ class ModelTest extends TestCase {
...
@@ -317,10 +317,10 @@ class ModelTest extends TestCase {
public
function
testScope
()
public
function
testScope
()
{
{
Item
::
insert
(
array
(
Item
::
insert
(
[
array
(
'name'
=>
'knife'
,
'type'
=>
'sharp'
)
,
[
'name'
=>
'knife'
,
'type'
=>
'sharp'
]
,
array
(
'name'
=>
'spoon'
,
'type'
=>
'round'
)
[
'name'
=>
'spoon'
,
'type'
=>
'round'
]
)
);
]
);
$sharp
=
Item
::
sharp
()
->
get
();
$sharp
=
Item
::
sharp
()
->
get
();
$this
->
assertEquals
(
1
,
$sharp
->
count
());
$this
->
assertEquals
(
1
,
$sharp
->
count
());
...
@@ -328,11 +328,11 @@ class ModelTest extends TestCase {
...
@@ -328,11 +328,11 @@ class ModelTest extends TestCase {
public
function
testToArray
()
public
function
testToArray
()
{
{
$item
=
Item
::
create
(
array
(
'name'
=>
'fork'
,
'type'
=>
'sharp'
)
);
$item
=
Item
::
create
(
[
'name'
=>
'fork'
,
'type'
=>
'sharp'
]
);
$array
=
$item
->
toArray
();
$array
=
$item
->
toArray
();
$keys
=
array_keys
(
$array
);
sort
(
$keys
);
$keys
=
array_keys
(
$array
);
sort
(
$keys
);
$this
->
assertEquals
(
array
(
'_id'
,
'created_at'
,
'name'
,
'type'
,
'updated_at'
)
,
$keys
);
$this
->
assertEquals
(
[
'_id'
,
'created_at'
,
'name'
,
'type'
,
'updated_at'
]
,
$keys
);
$this
->
assertTrue
(
is_string
(
$array
[
'created_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'created_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'updated_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'updated_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'_id'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'_id'
]));
...
@@ -340,8 +340,8 @@ class ModelTest extends TestCase {
...
@@ -340,8 +340,8 @@ class ModelTest extends TestCase {
public
function
testUnset
()
public
function
testUnset
()
{
{
$user1
=
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'note1'
=>
'ABC'
,
'note2'
=>
'DEF'
)
);
$user1
=
User
::
create
(
[
'name'
=>
'John Doe'
,
'note1'
=>
'ABC'
,
'note2'
=>
'DEF'
]
);
$user2
=
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'note1'
=>
'ABC'
,
'note2'
=>
'DEF'
)
);
$user2
=
User
::
create
(
[
'name'
=>
'Jane Doe'
,
'note1'
=>
'ABC'
,
'note2'
=>
'DEF'
]
);
$user1
->
unset
(
'note1'
);
$user1
->
unset
(
'note1'
);
...
@@ -359,7 +359,7 @@ class ModelTest extends TestCase {
...
@@ -359,7 +359,7 @@ class ModelTest extends TestCase {
$this
->
assertTrue
(
isset
(
$user2
->
note1
));
$this
->
assertTrue
(
isset
(
$user2
->
note1
));
$this
->
assertTrue
(
isset
(
$user2
->
note2
));
$this
->
assertTrue
(
isset
(
$user2
->
note2
));
$user2
->
unset
(
array
(
'note1'
,
'note2'
)
);
$user2
->
unset
(
[
'note1'
,
'note2'
]
);
$this
->
assertFalse
(
isset
(
$user2
->
note1
));
$this
->
assertFalse
(
isset
(
$user2
->
note1
));
$this
->
assertFalse
(
isset
(
$user2
->
note2
));
$this
->
assertFalse
(
isset
(
$user2
->
note2
));
...
@@ -368,7 +368,7 @@ class ModelTest extends TestCase {
...
@@ -368,7 +368,7 @@ class ModelTest extends TestCase {
public
function
testDates
()
public
function
testDates
()
{
{
$birthday
=
new
DateTime
(
'1980/1/1'
);
$birthday
=
new
DateTime
(
'1980/1/1'
);
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'birthday'
=>
$birthday
)
);
$user
=
User
::
create
(
[
'name'
=>
'John Doe'
,
'birthday'
=>
$birthday
]
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
birthday
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
birthday
);
$check
=
User
::
find
(
$user
->
_id
);
$check
=
User
::
find
(
$user
->
_id
);
...
@@ -384,20 +384,20 @@ class ModelTest extends TestCase {
...
@@ -384,20 +384,20 @@ class ModelTest extends TestCase {
$this
->
assertEquals
((
string
)
$user
->
created_at
,
$json
[
'created_at'
]);
$this
->
assertEquals
((
string
)
$user
->
created_at
,
$json
[
'created_at'
]);
// test default date format for json output
// test default date format for json output
$item
=
Item
::
create
(
array
(
'name'
=>
'sword'
)
);
$item
=
Item
::
create
(
[
'name'
=>
'sword'
]
);
$json
=
$item
->
toArray
();
$json
=
$item
->
toArray
();
$this
->
assertEquals
(
$item
->
created_at
->
format
(
'Y-m-d H:i:s'
),
$json
[
'created_at'
]);
$this
->
assertEquals
(
$item
->
created_at
->
format
(
'Y-m-d H:i:s'
),
$json
[
'created_at'
]);
$user
=
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'birthday'
=>
time
())
);
$user
=
User
::
create
(
[
'name'
=>
'Jane Doe'
,
'birthday'
=>
time
()]
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
birthday
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
birthday
);
$user
=
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'birthday'
=>
'Monday 8th of August 2005 03:12:46 PM'
)
);
$user
=
User
::
create
(
[
'name'
=>
'Jane Doe'
,
'birthday'
=>
'Monday 8th of August 2005 03:12:46 PM'
]
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
birthday
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
birthday
);
$user
=
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'birthday'
=>
'2005-08-08'
)
);
$user
=
User
::
create
(
[
'name'
=>
'Jane Doe'
,
'birthday'
=>
'2005-08-08'
]
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
birthday
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
birthday
);
$user
=
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'entry'
=>
array
(
'date'
=>
'2005-08-08'
))
);
$user
=
User
::
create
(
[
'name'
=>
'Jane Doe'
,
'entry'
=>
[
'date'
=>
'2005-08-08'
]]
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
getAttribute
(
'entry.date'
));
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
getAttribute
(
'entry.date'
));
$user
->
setAttribute
(
'entry.date'
,
new
DateTime
);
$user
->
setAttribute
(
'entry.date'
,
new
DateTime
);
...
@@ -406,55 +406,55 @@ class ModelTest extends TestCase {
...
@@ -406,55 +406,55 @@ class ModelTest extends TestCase {
public
function
testIdAttribute
()
public
function
testIdAttribute
()
{
{
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
)
);
$user
=
User
::
create
(
[
'name'
=>
'John Doe'
]
);
$this
->
assertEquals
(
$user
->
id
,
$user
->
_id
);
$this
->
assertEquals
(
$user
->
id
,
$user
->
_id
);
$user
=
User
::
create
(
array
(
'id'
=>
'custom_id'
,
'name'
=>
'John Doe'
)
);
$user
=
User
::
create
(
[
'id'
=>
'custom_id'
,
'name'
=>
'John Doe'
]
);
$this
->
assertNotEquals
(
$user
->
id
,
$user
->
_id
);
$this
->
assertNotEquals
(
$user
->
id
,
$user
->
_id
);
}
}
public
function
testPushPull
()
public
function
testPushPull
()
{
{
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
)
);
$user
=
User
::
create
(
[
'name'
=>
'John Doe'
]
);
$user
->
push
(
'tags'
,
'tag1'
);
$user
->
push
(
'tags'
,
'tag1'
);
$user
->
push
(
'tags'
,
array
(
'tag1'
,
'tag2'
)
);
$user
->
push
(
'tags'
,
[
'tag1'
,
'tag2'
]
);
$user
->
push
(
'tags'
,
'tag2'
,
true
);
$user
->
push
(
'tags'
,
'tag2'
,
true
);
$this
->
assertEquals
(
array
(
'tag1'
,
'tag1'
,
'tag2'
)
,
$user
->
tags
);
$this
->
assertEquals
(
[
'tag1'
,
'tag1'
,
'tag2'
]
,
$user
->
tags
);
$user
=
User
::
where
(
'_id'
,
$user
->
_id
)
->
first
();
$user
=
User
::
where
(
'_id'
,
$user
->
_id
)
->
first
();
$this
->
assertEquals
(
array
(
'tag1'
,
'tag1'
,
'tag2'
)
,
$user
->
tags
);
$this
->
assertEquals
(
[
'tag1'
,
'tag1'
,
'tag2'
]
,
$user
->
tags
);
$user
->
pull
(
'tags'
,
'tag1'
);
$user
->
pull
(
'tags'
,
'tag1'
);
$this
->
assertEquals
(
array
(
'tag2'
)
,
$user
->
tags
);
$this
->
assertEquals
(
[
'tag2'
]
,
$user
->
tags
);
$user
=
User
::
where
(
'_id'
,
$user
->
_id
)
->
first
();
$user
=
User
::
where
(
'_id'
,
$user
->
_id
)
->
first
();
$this
->
assertEquals
(
array
(
'tag2'
)
,
$user
->
tags
);
$this
->
assertEquals
(
[
'tag2'
]
,
$user
->
tags
);
$user
->
push
(
'tags'
,
'tag3'
);
$user
->
push
(
'tags'
,
'tag3'
);
$user
->
pull
(
'tags'
,
array
(
'tag2'
,
'tag3'
)
);
$user
->
pull
(
'tags'
,
[
'tag2'
,
'tag3'
]
);
$this
->
assertEquals
(
array
()
,
$user
->
tags
);
$this
->
assertEquals
(
[]
,
$user
->
tags
);
$user
=
User
::
where
(
'_id'
,
$user
->
_id
)
->
first
();
$user
=
User
::
where
(
'_id'
,
$user
->
_id
)
->
first
();
$this
->
assertEquals
(
array
()
,
$user
->
tags
);
$this
->
assertEquals
(
[]
,
$user
->
tags
);
}
}
public
function
testRaw
()
public
function
testRaw
()
{
{
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'age'
=>
35
)
);
User
::
create
(
[
'name'
=>
'John Doe'
,
'age'
=>
35
]
);
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'age'
=>
35
)
);
User
::
create
(
[
'name'
=>
'Jane Doe'
,
'age'
=>
35
]
);
User
::
create
(
array
(
'name'
=>
'Harry Hoe'
,
'age'
=>
15
)
);
User
::
create
(
[
'name'
=>
'Harry Hoe'
,
'age'
=>
15
]
);
$users
=
User
::
raw
(
function
(
$collection
)
$users
=
User
::
raw
(
function
(
$collection
)
{
{
return
$collection
->
find
(
array
(
'age'
=>
35
)
);
return
$collection
->
find
(
[
'age'
=>
35
]
);
});
});
$this
->
assertInstanceOf
(
'Illuminate\Database\Eloquent\Collection'
,
$users
);
$this
->
assertInstanceOf
(
'Illuminate\Database\Eloquent\Collection'
,
$users
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Model'
,
$users
[
0
]);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Model'
,
$users
[
0
]);
$user
=
User
::
raw
(
function
(
$collection
)
$user
=
User
::
raw
(
function
(
$collection
)
{
{
return
$collection
->
findOne
(
array
(
'age'
=>
35
)
);
return
$collection
->
findOne
(
[
'age'
=>
35
]
);
});
});
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Model'
,
$user
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Model'
,
$user
);
...
@@ -466,20 +466,20 @@ class ModelTest extends TestCase {
...
@@ -466,20 +466,20 @@ class ModelTest extends TestCase {
$result
=
User
::
raw
(
function
(
$collection
)
$result
=
User
::
raw
(
function
(
$collection
)
{
{
return
$collection
->
insert
(
array
(
'name'
=>
'Yvonne Yoe'
,
'age'
=>
35
)
);
return
$collection
->
insert
(
[
'name'
=>
'Yvonne Yoe'
,
'age'
=>
35
]
);
});
});
$this
->
assertTrue
(
is_array
(
$result
));
$this
->
assertTrue
(
is_array
(
$result
));
}
}
public
function
testDotNotation
()
public
function
testDotNotation
()
{
{
$user
=
User
::
create
(
array
(
$user
=
User
::
create
(
[
'name'
=>
'John Doe'
,
'name'
=>
'John Doe'
,
'address'
=>
[
'address'
=>
[
'city'
=>
'Paris'
,
'city'
=>
'Paris'
,
'country'
=>
'France'
,
'country'
=>
'France'
,
]
]
)
);
]
);
$this
->
assertEquals
(
'Paris'
,
$user
->
getAttribute
(
'address.city'
));
$this
->
assertEquals
(
'Paris'
,
$user
->
getAttribute
(
'address.city'
));
$this
->
assertEquals
(
'Paris'
,
$user
[
'address.city'
]);
$this
->
assertEquals
(
'Paris'
,
$user
[
'address.city'
]);
...
...
tests/MysqlRelationsTest.php
View file @
593b4a52
...
@@ -30,7 +30,7 @@ class MysqlRelationsTest extends TestCase {
...
@@ -30,7 +30,7 @@ class MysqlRelationsTest extends TestCase {
$this
->
assertTrue
(
is_int
(
$user
->
id
));
$this
->
assertTrue
(
is_int
(
$user
->
id
));
// SQL has many
// SQL has many
$book
=
new
Book
(
array
(
'title'
=>
'Game of Thrones'
)
);
$book
=
new
Book
(
[
'title'
=>
'Game of Thrones'
]
);
$user
->
books
()
->
save
(
$book
);
$user
->
books
()
->
save
(
$book
);
$user
=
MysqlUser
::
find
(
$user
->
id
);
// refetch
$user
=
MysqlUser
::
find
(
$user
->
id
);
// refetch
$this
->
assertEquals
(
1
,
count
(
$user
->
books
));
$this
->
assertEquals
(
1
,
count
(
$user
->
books
));
...
@@ -40,7 +40,7 @@ class MysqlRelationsTest extends TestCase {
...
@@ -40,7 +40,7 @@ class MysqlRelationsTest extends TestCase {
$this
->
assertEquals
(
'John Doe'
,
$book
->
mysqlAuthor
->
name
);
$this
->
assertEquals
(
'John Doe'
,
$book
->
mysqlAuthor
->
name
);
// SQL has one
// SQL has one
$role
=
new
Role
(
array
(
'type'
=>
'admin'
)
);
$role
=
new
Role
(
[
'type'
=>
'admin'
]
);
$user
->
role
()
->
save
(
$role
);
$user
->
role
()
->
save
(
$role
);
$user
=
MysqlUser
::
find
(
$user
->
id
);
// refetch
$user
=
MysqlUser
::
find
(
$user
->
id
);
// refetch
$this
->
assertEquals
(
'admin'
,
$user
->
role
->
type
);
$this
->
assertEquals
(
'admin'
,
$user
->
role
->
type
);
...
@@ -55,7 +55,7 @@ class MysqlRelationsTest extends TestCase {
...
@@ -55,7 +55,7 @@ class MysqlRelationsTest extends TestCase {
$user
->
save
();
$user
->
save
();
// MongoDB has many
// MongoDB has many
$book
=
new
MysqlBook
(
array
(
'title'
=>
'Game of Thrones'
)
);
$book
=
new
MysqlBook
(
[
'title'
=>
'Game of Thrones'
]
);
$user
->
mysqlBooks
()
->
save
(
$book
);
$user
->
mysqlBooks
()
->
save
(
$book
);
$user
=
User
::
find
(
$user
->
_id
);
// refetch
$user
=
User
::
find
(
$user
->
_id
);
// refetch
$this
->
assertEquals
(
1
,
count
(
$user
->
mysqlBooks
));
$this
->
assertEquals
(
1
,
count
(
$user
->
mysqlBooks
));
...
@@ -65,7 +65,7 @@ class MysqlRelationsTest extends TestCase {
...
@@ -65,7 +65,7 @@ class MysqlRelationsTest extends TestCase {
$this
->
assertEquals
(
'John Doe'
,
$book
->
author
->
name
);
$this
->
assertEquals
(
'John Doe'
,
$book
->
author
->
name
);
// MongoDB has one
// MongoDB has one
$role
=
new
MysqlRole
(
array
(
'type'
=>
'admin'
)
);
$role
=
new
MysqlRole
(
[
'type'
=>
'admin'
]
);
$user
->
mysqlRole
()
->
save
(
$role
);
$user
->
mysqlRole
()
->
save
(
$role
);
$user
=
User
::
find
(
$user
->
_id
);
// refetch
$user
=
User
::
find
(
$user
->
_id
);
// refetch
$this
->
assertEquals
(
'admin'
,
$user
->
mysqlRole
->
type
);
$this
->
assertEquals
(
'admin'
,
$user
->
mysqlRole
->
type
);
...
...
tests/QueryBuilderTest.php
View file @
593b4a52
This diff is collapsed.
Click to expand it.
tests/QueryTest.php
View file @
593b4a52
...
@@ -7,15 +7,15 @@ class QueryTest extends TestCase {
...
@@ -7,15 +7,15 @@ class QueryTest extends TestCase {
public
function
setUp
()
public
function
setUp
()
{
{
parent
::
setUp
();
parent
::
setUp
();
User
::
create
(
array
(
'name'
=>
'John Doe'
,
'age'
=>
35
,
'title'
=>
'admin'
)
);
User
::
create
(
[
'name'
=>
'John Doe'
,
'age'
=>
35
,
'title'
=>
'admin'
]
);
User
::
create
(
array
(
'name'
=>
'Jane Doe'
,
'age'
=>
33
,
'title'
=>
'admin'
)
);
User
::
create
(
[
'name'
=>
'Jane Doe'
,
'age'
=>
33
,
'title'
=>
'admin'
]
);
User
::
create
(
array
(
'name'
=>
'Harry Hoe'
,
'age'
=>
13
,
'title'
=>
'user'
)
);
User
::
create
(
[
'name'
=>
'Harry Hoe'
,
'age'
=>
13
,
'title'
=>
'user'
]
);
User
::
create
(
array
(
'name'
=>
'Robert Roe'
,
'age'
=>
37
,
'title'
=>
'user'
)
);
User
::
create
(
[
'name'
=>
'Robert Roe'
,
'age'
=>
37
,
'title'
=>
'user'
]
);
User
::
create
(
array
(
'name'
=>
'Mark Moe'
,
'age'
=>
23
,
'title'
=>
'user'
)
);
User
::
create
(
[
'name'
=>
'Mark Moe'
,
'age'
=>
23
,
'title'
=>
'user'
]
);
User
::
create
(
array
(
'name'
=>
'Brett Boe'
,
'age'
=>
35
,
'title'
=>
'user'
)
);
User
::
create
(
[
'name'
=>
'Brett Boe'
,
'age'
=>
35
,
'title'
=>
'user'
]
);
User
::
create
(
array
(
'name'
=>
'Tommy Toe'
,
'age'
=>
33
,
'title'
=>
'user'
)
);
User
::
create
(
[
'name'
=>
'Tommy Toe'
,
'age'
=>
33
,
'title'
=>
'user'
]
);
User
::
create
(
array
(
'name'
=>
'Yvonne Yoe'
,
'age'
=>
35
,
'title'
=>
'admin'
)
);
User
::
create
(
[
'name'
=>
'Yvonne Yoe'
,
'age'
=>
35
,
'title'
=>
'admin'
]
);
User
::
create
(
array
(
'name'
=>
'Error'
,
'age'
=>
null
,
'title'
=>
null
)
);
User
::
create
(
[
'name'
=>
'Error'
,
'age'
=>
null
,
'title'
=>
null
]
);
}
}
public
function
tearDown
()
public
function
tearDown
()
...
@@ -83,13 +83,13 @@ class QueryTest extends TestCase {
...
@@ -83,13 +83,13 @@ class QueryTest extends TestCase {
$this
->
assertEquals
(
'admin'
,
$user
->
title
);
$this
->
assertEquals
(
'admin'
,
$user
->
title
);
$this
->
assertEquals
(
null
,
$user
->
age
);
$this
->
assertEquals
(
null
,
$user
->
age
);
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
select
(
array
(
'name'
,
'title'
)
)
->
get
()
->
first
();
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
select
(
[
'name'
,
'title'
]
)
->
get
()
->
first
();
$this
->
assertEquals
(
'John Doe'
,
$user
->
name
);
$this
->
assertEquals
(
'John Doe'
,
$user
->
name
);
$this
->
assertEquals
(
'admin'
,
$user
->
title
);
$this
->
assertEquals
(
'admin'
,
$user
->
title
);
$this
->
assertEquals
(
null
,
$user
->
age
);
$this
->
assertEquals
(
null
,
$user
->
age
);
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
get
(
array
(
'name'
)
)
->
first
();
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
get
(
[
'name'
]
)
->
first
();
$this
->
assertEquals
(
'John Doe'
,
$user
->
name
);
$this
->
assertEquals
(
'John Doe'
,
$user
->
name
);
$this
->
assertEquals
(
null
,
$user
->
age
);
$this
->
assertEquals
(
null
,
$user
->
age
);
...
@@ -106,30 +106,30 @@ class QueryTest extends TestCase {
...
@@ -106,30 +106,30 @@ class QueryTest extends TestCase {
public
function
testBetween
()
public
function
testBetween
()
{
{
$users
=
User
::
whereBetween
(
'age'
,
array
(
0
,
25
)
)
->
get
();
$users
=
User
::
whereBetween
(
'age'
,
[
0
,
25
]
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$users
));
$this
->
assertEquals
(
2
,
count
(
$users
));
$users
=
User
::
whereBetween
(
'age'
,
array
(
13
,
23
)
)
->
get
();
$users
=
User
::
whereBetween
(
'age'
,
[
13
,
23
]
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$users
));
$this
->
assertEquals
(
2
,
count
(
$users
));
// testing whereNotBetween for version 4.1
// testing whereNotBetween for version 4.1
$users
=
User
::
whereBetween
(
'age'
,
array
(
0
,
25
)
,
'and'
,
true
)
->
get
();
$users
=
User
::
whereBetween
(
'age'
,
[
0
,
25
]
,
'and'
,
true
)
->
get
();
$this
->
assertEquals
(
6
,
count
(
$users
));
$this
->
assertEquals
(
6
,
count
(
$users
));
}
}
public
function
testIn
()
public
function
testIn
()
{
{
$users
=
User
::
whereIn
(
'age'
,
array
(
13
,
23
)
)
->
get
();
$users
=
User
::
whereIn
(
'age'
,
[
13
,
23
]
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$users
));
$this
->
assertEquals
(
2
,
count
(
$users
));
$users
=
User
::
whereIn
(
'age'
,
array
(
33
,
35
,
13
)
)
->
get
();
$users
=
User
::
whereIn
(
'age'
,
[
33
,
35
,
13
]
)
->
get
();
$this
->
assertEquals
(
6
,
count
(
$users
));
$this
->
assertEquals
(
6
,
count
(
$users
));
$users
=
User
::
whereNotIn
(
'age'
,
array
(
33
,
35
)
)
->
get
();
$users
=
User
::
whereNotIn
(
'age'
,
[
33
,
35
]
)
->
get
();
$this
->
assertEquals
(
4
,
count
(
$users
));
$this
->
assertEquals
(
4
,
count
(
$users
));
$users
=
User
::
whereNotNull
(
'age'
)
$users
=
User
::
whereNotNull
(
'age'
)
->
whereNotIn
(
'age'
,
array
(
33
,
35
)
)
->
get
();
->
whereNotIn
(
'age'
,
[
33
,
35
]
)
->
get
();
$this
->
assertEquals
(
3
,
count
(
$users
));
$this
->
assertEquals
(
3
,
count
(
$users
));
}
}
...
@@ -263,13 +263,13 @@ class QueryTest extends TestCase {
...
@@ -263,13 +263,13 @@ class QueryTest extends TestCase {
public
function
testWhereRaw
()
public
function
testWhereRaw
()
{
{
$where
=
array
(
'age'
=>
array
(
'$gt'
=>
30
,
'$lt'
=>
40
))
;
$where
=
[
'age'
=>
[
'$gt'
=>
30
,
'$lt'
=>
40
]]
;
$users
=
User
::
whereRaw
(
$where
)
->
get
();
$users
=
User
::
whereRaw
(
$where
)
->
get
();
$this
->
assertEquals
(
6
,
count
(
$users
));
$this
->
assertEquals
(
6
,
count
(
$users
));
$where1
=
array
(
'age'
=>
array
(
'$gt'
=>
30
,
'$lte'
=>
35
))
;
$where1
=
[
'age'
=>
[
'$gt'
=>
30
,
'$lte'
=>
35
]]
;
$where2
=
array
(
'age'
=>
array
(
'$gt'
=>
35
,
'$lt'
=>
40
))
;
$where2
=
[
'age'
=>
[
'$gt'
=>
35
,
'$lt'
=>
40
]]
;
$users
=
User
::
whereRaw
(
$where1
)
->
orWhereRaw
(
$where2
)
->
get
();
$users
=
User
::
whereRaw
(
$where1
)
->
orWhereRaw
(
$where2
)
->
get
();
$this
->
assertEquals
(
6
,
count
(
$users
));
$this
->
assertEquals
(
6
,
count
(
$users
));
...
@@ -307,7 +307,7 @@ class QueryTest extends TestCase {
...
@@ -307,7 +307,7 @@ class QueryTest extends TestCase {
$this
->
assertNotNull
(
$results
->
first
()
->
title
);
$this
->
assertNotNull
(
$results
->
first
()
->
title
);
$this
->
assertEquals
(
9
,
$results
->
total
());
$this
->
assertEquals
(
9
,
$results
->
total
());
$results
=
User
::
paginate
(
2
,
array
(
'name'
,
'age'
)
);
$results
=
User
::
paginate
(
2
,
[
'name'
,
'age'
]
);
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertNull
(
$results
->
first
()
->
title
);
$this
->
assertNull
(
$results
->
first
()
->
title
);
$this
->
assertEquals
(
9
,
$results
->
total
());
$this
->
assertEquals
(
9
,
$results
->
total
());
...
...
tests/RelationsTest.php
View file @
593b4a52
This diff is collapsed.
Click to expand it.
tests/SchemaTest.php
View file @
593b4a52
...
@@ -60,7 +60,7 @@ class SchemaTest extends TestCase {
...
@@ -60,7 +60,7 @@ class SchemaTest extends TestCase {
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
index
(
array
(
'mykey'
)
);
$collection
->
index
(
[
'mykey'
]
);
});
});
$index
=
$this
->
getIndex
(
'newcollection'
,
'mykey'
);
$index
=
$this
->
getIndex
(
'newcollection'
,
'mykey'
);
...
@@ -92,7 +92,7 @@ class SchemaTest extends TestCase {
...
@@ -92,7 +92,7 @@ class SchemaTest extends TestCase {
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
unique
(
'uniquekey'
);
$collection
->
unique
(
'uniquekey'
);
$collection
->
dropIndex
(
array
(
'uniquekey'
)
);
$collection
->
dropIndex
(
[
'uniquekey'
]
);
});
});
$index
=
$this
->
getIndex
(
'newcollection'
,
'uniquekey'
);
$index
=
$this
->
getIndex
(
'newcollection'
,
'uniquekey'
);
...
...
tests/TestCase.php
View file @
593b4a52
...
@@ -10,10 +10,10 @@ class TestCase extends Orchestra\Testbench\TestCase {
...
@@ -10,10 +10,10 @@ class TestCase extends Orchestra\Testbench\TestCase {
*/
*/
protected
function
getPackageProviders
(
$app
)
protected
function
getPackageProviders
(
$app
)
{
{
return
array
(
return
[
'Jenssegers\Mongodb\MongodbServiceProvider'
,
'Jenssegers\Mongodb\MongodbServiceProvider'
,
'Jenssegers\Mongodb\Auth\PasswordResetServiceProvider'
,
'Jenssegers\Mongodb\Auth\PasswordResetServiceProvider'
,
)
;
]
;
}
}
/**
/**
...
...
tests/ValidationTest.php
View file @
593b4a52
...
@@ -10,16 +10,16 @@ class ValidationTest extends TestCase {
...
@@ -10,16 +10,16 @@ class ValidationTest extends TestCase {
public
function
testUnique
()
public
function
testUnique
()
{
{
$validator
=
Validator
::
make
(
$validator
=
Validator
::
make
(
array
(
'name'
=>
'John Doe'
)
,
[
'name'
=>
'John Doe'
]
,
array
(
'name'
=>
'required|unique:users'
)
[
'name'
=>
'required|unique:users'
]
);
);
$this
->
assertFalse
(
$validator
->
fails
());
$this
->
assertFalse
(
$validator
->
fails
());
User
::
create
(
array
(
'name'
=>
'John Doe'
)
);
User
::
create
(
[
'name'
=>
'John Doe'
]
);
$validator
=
Validator
::
make
(
$validator
=
Validator
::
make
(
array
(
'name'
=>
'John Doe'
)
,
[
'name'
=>
'John Doe'
]
,
array
(
'name'
=>
'required|unique:users'
)
[
'name'
=>
'required|unique:users'
]
);
);
$this
->
assertTrue
(
$validator
->
fails
());
$this
->
assertTrue
(
$validator
->
fails
());
}
}
...
...
tests/config/database.php
View file @
593b4a52
<?php
<?php
return
array
(
return
[
'connections'
=>
array
(
'connections'
=>
[
'mongodb'
=>
array
(
'mongodb'
=>
[
'name'
=>
'mongodb'
,
'name'
=>
'mongodb'
,
'driver'
=>
'mongodb'
,
'driver'
=>
'mongodb'
,
'host'
=>
'localhost'
,
'host'
=>
'localhost'
,
'database'
=>
'unittest'
,
'database'
=>
'unittest'
,
)
,
]
,
'mysql'
=>
array
(
'mysql'
=>
[
'driver'
=>
'mysql'
,
'driver'
=>
'mysql'
,
'host'
=>
'localhost'
,
'host'
=>
'localhost'
,
'database'
=>
'unittest'
,
'database'
=>
'unittest'
,
...
@@ -20,7 +20,7 @@ return array(
...
@@ -20,7 +20,7 @@ return array(
'charset'
=>
'utf8'
,
'charset'
=>
'utf8'
,
'collation'
=>
'utf8_unicode_ci'
,
'collation'
=>
'utf8_unicode_ci'
,
'prefix'
=>
''
,
'prefix'
=>
''
,
)
,
]
,
)
]
)
;
]
;
tests/models/Soft.php
View file @
593b4a52
...
@@ -9,6 +9,6 @@ class Soft extends Eloquent {
...
@@ -9,6 +9,6 @@ class Soft extends Eloquent {
protected
$collection
=
'soft'
;
protected
$collection
=
'soft'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
protected
$dates
=
array
(
'deleted_at'
)
;
protected
$dates
=
[
'deleted_at'
]
;
}
}
tests/models/User.php
View file @
593b4a52
...
@@ -11,7 +11,7 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword
...
@@ -11,7 +11,7 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword
use
Authenticatable
,
CanResetPassword
;
use
Authenticatable
,
CanResetPassword
;
protected
$dates
=
array
(
'birthday'
,
'entry.date'
)
;
protected
$dates
=
[
'birthday'
,
'entry.date'
]
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
public
function
books
()
public
function
books
()
...
...
tests/seeds/UserTableSeeder.php
View file @
593b4a52
...
@@ -9,6 +9,6 @@ class UserTableSeeder extends Seeder {
...
@@ -9,6 +9,6 @@ class UserTableSeeder extends Seeder {
{
{
DB
::
collection
(
'users'
)
->
delete
();
DB
::
collection
(
'users'
)
->
delete
();
DB
::
collection
(
'users'
)
->
insert
(
array
(
'name'
=>
'John Doe'
,
'seed'
=>
true
)
);
DB
::
collection
(
'users'
)
->
insert
(
[
'name'
=>
'John Doe'
,
'seed'
=>
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