Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
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
PSDI Army
yii2
Commits
866ba850
Commit
866ba850
authored
Mar 08, 2014
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
yii\mongodb\file\Collection::ensureMongoId() fixed to suppress exception on invalid _id format.
parent
0019f130
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
Collection.php
extensions/mongodb/Collection.php
+7
-1
CollectionTest.php
tests/unit/extensions/mongodb/CollectionTest.php
+21
-0
No files found.
extensions/mongodb/Collection.php
View file @
866ba850
...
@@ -733,7 +733,13 @@ class Collection extends Object
...
@@ -733,7 +733,13 @@ class Collection extends Object
$rawId
=
(
string
)
$rawId
;
$rawId
=
(
string
)
$rawId
;
}
}
}
}
return
new
\MongoId
(
$rawId
);
try
{
$mongoId
=
new
\MongoId
(
$rawId
);
}
catch
(
\MongoException
$e
)
{
// invalid id format
$mongoId
=
$rawId
;
}
return
$mongoId
;
}
}
/**
/**
...
...
tests/unit/extensions/mongodb/CollectionTest.php
View file @
866ba850
...
@@ -419,4 +419,24 @@ class CollectionTest extends MongoDbTestCase
...
@@ -419,4 +419,24 @@ class CollectionTest extends MongoDbTestCase
$this
->
assertNotEmpty
(
$result
);
$this
->
assertNotEmpty
(
$result
);
$this
->
assertCount
(
2
,
$result
);
$this
->
assertCount
(
2
,
$result
);
}
}
public
function
testFindByNotObjectId
()
{
$collection
=
$this
->
getConnection
()
->
getCollection
(
'customer'
);
$data
=
[
'name'
=>
'customer 1'
,
'address'
=>
'customer 1 address'
,
];
$id
=
$collection
->
insert
(
$data
);
$cursor
=
$collection
->
find
([
'_id'
=>
(
string
)
$id
]);
$this
->
assertTrue
(
$cursor
instanceof
\MongoCursor
);
$row
=
$cursor
->
getNext
();
$this
->
assertEquals
(
$id
,
$row
[
'_id'
]);
$cursor
=
$collection
->
find
([
'_id'
=>
'fake'
]);
$this
->
assertTrue
(
$cursor
instanceof
\MongoCursor
);
$this
->
assertEquals
(
0
,
$cursor
->
count
());
}
}
}
\ No newline at end of file
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