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
9c8bf642
Commit
9c8bf642
authored
Mar 04, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #146 from neoxia/master-test-and-refactor-create-many-embedded
Test and refactor EmbedsMany::createMany
parents
652ef4b0
1c07ca16
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
18 deletions
+26
-18
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+1
-6
QueryBuilderTest.php
tests/QueryBuilderTest.php
+9
-8
RelationsTest.php
tests/RelationsTest.php
+16
-4
No files found.
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
9c8bf642
...
...
@@ -265,12 +265,7 @@ class EmbedsMany extends Relation {
*/
public
function
createMany
(
array
$records
)
{
$instances
=
array
();
foreach
(
$records
as
$record
)
{
$instances
[]
=
$this
->
create
(
$record
);
}
$instances
=
array_map
(
array
(
$this
,
'create'
),
$records
);
return
$instances
;
}
...
...
tests/QueryBuilderTest.php
View file @
9c8bf642
...
...
@@ -78,10 +78,7 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
$users
=
DB
::
collection
(
'users'
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$users
));
$user
=
$users
[
0
];
$this
->
assertEquals
(
'Jane Doe'
,
$user
[
'name'
]);
$this
->
assertTrue
(
is_array
(
$user
[
'tags'
]));
$this
->
assertTrue
(
is_array
(
$users
[
0
][
'tags'
]));
}
public
function
testFind
()
...
...
@@ -118,8 +115,10 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'John Doe'
)
->
update
(
array
(
'age'
=>
100
));
$users
=
DB
::
collection
(
'users'
)
->
get
();
$this
->
assertEquals
(
20
,
$users
[
0
][
'age'
]);
$this
->
assertEquals
(
100
,
$users
[
1
][
'age'
]);
$john
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'John Doe'
)
->
first
();
$jane
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'Jane Doe'
)
->
first
();
$this
->
assertEquals
(
100
,
$john
[
'age'
]);
$this
->
assertEquals
(
20
,
$jane
[
'age'
]);
}
public
function
testDelete
()
...
...
@@ -326,7 +325,7 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
array
(
'name'
=>
'spoon'
,
'type'
=>
'round'
,
'amount'
=>
14
)
));
$items
=
DB
::
collection
(
'items'
)
->
skip
(
2
)
->
get
();
$items
=
DB
::
collection
(
'items'
)
->
orderBy
(
'name'
)
->
skip
(
2
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$items
));
$this
->
assertEquals
(
'spoon'
,
$items
[
0
][
'name'
]);
}
...
...
@@ -471,7 +470,9 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase {
$results
=
DB
::
collection
(
'users'
)
->
where
(
'age'
,
'exists'
,
true
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$results
));
$this
->
assertEquals
(
'John Doe'
,
$results
[
0
][
'name'
]);
$resultsNames
=
array
(
$results
[
0
][
'name'
],
$results
[
1
][
'name'
]);
$this
->
assertContains
(
'John Doe'
,
$resultsNames
);
$this
->
assertContains
(
'Robert Roe'
,
$resultsNames
);
$results
=
DB
::
collection
(
'users'
)
->
where
(
'age'
,
'exists'
,
false
)
->
get
();
$this
->
assertEquals
(
1
,
count
(
$results
));
...
...
tests/RelationsTest.php
View file @
9c8bf642
...
...
@@ -146,13 +146,13 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
$this
->
assertTrue
(
array_key_exists
(
'user_ids'
,
$client
->
getAttributes
()));
$this
->
assertTrue
(
array_key_exists
(
'client_ids'
,
$user
->
getAttributes
()));
$
client
s
=
$client
->
getRelation
(
'users'
);
$
user
s
=
$user
->
getRelation
(
'clients'
);
$
user
s
=
$client
->
getRelation
(
'users'
);
$
client
s
=
$user
->
getRelation
(
'clients'
);
$this
->
assertInstanceOf
(
'Illuminate\Database\Eloquent\Collection'
,
$users
);
$this
->
assertInstanceOf
(
'Illuminate\Database\Eloquent\Collection'
,
$clients
);
$this
->
assertInstanceOf
(
'Client'
,
$
user
s
[
0
]);
$this
->
assertInstanceOf
(
'User'
,
$
client
s
[
0
]);
$this
->
assertInstanceOf
(
'Client'
,
$
client
s
[
0
]);
$this
->
assertInstanceOf
(
'User'
,
$
user
s
[
0
]);
$this
->
assertCount
(
2
,
$user
->
clients
);
$this
->
assertCount
(
1
,
$client
->
users
);
...
...
@@ -355,6 +355,18 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
$this
->
assertInstanceOf
(
'MongoID'
,
$address
->
_id
);
}
public
function
testEmbedsManyCreateMany
()
{
$user
=
User
::
create
(
array
());
list
(
$bruxelles
,
$paris
)
=
$user
->
addresses
()
->
createMany
(
array
(
array
(
'city'
=>
'Bruxelles'
),
array
(
'city'
=>
'Paris'
)));
$this
->
assertInstanceOf
(
'Address'
,
$bruxelles
);
$this
->
assertEquals
(
'Bruxelles'
,
$bruxelles
->
city
);
$this
->
assertEquals
(
array
(
'Bruxelles'
,
'Paris'
),
$user
->
addresses
->
lists
(
'city'
));
$freshUser
=
User
::
find
(
$user
->
id
);
$this
->
assertEquals
(
array
(
'Bruxelles'
,
'Paris'
),
$freshUser
->
addresses
->
lists
(
'city'
));
}
public
function
testEmbedsManyDestroy
()
{
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
...
...
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