Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
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
mongo-php-library
Commits
56395109
Commit
56395109
authored
Apr 24, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-69: Do not allow empty index name for dropIndex()
parent
33f6ca4d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
Collection.php
src/Collection.php
+5
-2
CollectionFunctionalTest.php
tests/CollectionFunctionalTest.php
+10
-0
No files found.
src/Collection.php
View file @
56395109
...
@@ -401,13 +401,16 @@ class Collection
...
@@ -401,13 +401,16 @@ class Collection
* @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndex/
* @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndex/
* @param string $indexName
* @param string $indexName
* @return Cursor
* @return Cursor
* @throws InvalidArgumentException if "*" is specified, since dropIndexes()
* @throws InvalidArgumentException if $indexName is an empty string or "*"
* should be used to drop multiple indexes
*/
*/
public
function
dropIndex
(
$indexName
)
public
function
dropIndex
(
$indexName
)
{
{
$indexName
=
(
string
)
$indexName
;
$indexName
=
(
string
)
$indexName
;
if
(
$indexName
===
''
)
{
throw
new
InvalidArgumentException
(
'Index name cannot be empty'
);
}
if
(
$indexName
===
'*'
)
{
if
(
$indexName
===
'*'
)
{
throw
new
InvalidArgumentException
(
'dropIndexes() must be used to drop multiple indexes'
);
throw
new
InvalidArgumentException
(
'dropIndexes() must be used to drop multiple indexes'
);
}
}
...
...
tests/CollectionFunctionalTest.php
View file @
56395109
...
@@ -150,6 +150,16 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -150,6 +150,16 @@ class CollectionFunctionalTest extends FunctionalTestCase
}
}
}
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public
function
testDropIndexShouldNotAllowEmptyIndexName
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
(
array
(
'x'
=>
1
)));
$this
->
assertIndexExists
(
'x_1'
);
$this
->
collection
->
dropIndex
(
''
);
}
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
*/
...
...
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