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
797ef704
Commit
797ef704
authored
Nov 18, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #49
parents
ce26ec3c
c50d9a6d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
362 additions
and
11 deletions
+362
-11
CreateIndexes.php
src/Operation/CreateIndexes.php
+2
-1
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+9
-0
CreateIndexesFunctionalTest.php
tests/Operation/CreateIndexesFunctionalTest.php
+194
-0
CreateIndexesTest.php
tests/Operation/CreateIndexesTest.php
+30
-0
DropIndexesFunctionalTest.php
tests/Operation/DropIndexesFunctionalTest.php
+102
-0
DropIndexesTest.php
tests/Operation/DropIndexesTest.php
+16
-0
ListIndexesFunctionalTest.php
tests/Operation/ListIndexesFunctionalTest.php
+9
-10
No files found.
src/Operation/CreateIndexes.php
View file @
797ef704
...
...
@@ -5,6 +5,7 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\BulkWrite
as
Bulk
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\UnexpectedTypeException
;
...
...
@@ -113,6 +114,6 @@ class CreateIndexes implements Executable
$bulk
->
insert
(
$index
);
}
$server
->
executeBulkWrite
(
$this
->
databaseName
.
'.system.indexes'
,
$bulk
);
$server
->
executeBulkWrite
(
$this
->
databaseName
.
'.system.indexes'
,
$bulk
,
new
WriteConcern
(
1
)
);
}
}
tests/Collection/CollectionFunctionalTest.php
View file @
797ef704
...
...
@@ -61,6 +61,15 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @todo Move this to a unit test once Manager can be mocked
*/
public
function
testDropIndexShouldNotAllowWildcardCharacter
()
{
$this
->
collection
->
dropIndex
(
'*'
);
}
public
function
testFindOne
()
{
$this
->
createFixtures
(
5
);
...
...
tests/
Collection/IndexManagement
FunctionalTest.php
→
tests/
Operation/CreateIndexes
FunctionalTest.php
View file @
797ef704
<?php
namespace
MongoDB\Tests\
Collec
tion
;
namespace
MongoDB\Tests\
Opera
tion
;
use
MongoDB\Model\IndexInfo
;
use
MongoDB\Operation\CreateIndexes
;
use
MongoDB\Operation\DropIndexes
;
use
MongoDB\Operation\ListIndexes
;
use
InvalidArgumentException
;
/**
* Functional tests for index management methods.
*
* @see https://github.com/mongodb/specifications/blob/master/source/index-management.rst
*/
class
IndexManagementFunctionalTest
extends
FunctionalTestCase
class
CreateIndexesFunctionalTest
extends
FunctionalTestCase
{
public
function
testCreateIndex
()
private
static
$wireVersionForCommand
=
2
;
public
function
testCreateSparseUniqueIndex
()
{
$that
=
$this
;
$indexes
=
[[
'key'
=>
[
'x'
=>
1
],
'sparse'
=>
true
,
'unique'
=>
true
]];
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertSame
(
'x_1'
,
$
this
->
collection
->
createIndex
([
'x'
=>
1
],
[
'sparse'
=>
true
,
'unique'
=>
true
])
);
$this
->
assertIndexExists
(
'x_1'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$th
at
->
assertTrue
(
$info
->
isSparse
());
$th
at
->
assertTrue
(
$info
->
isUnique
());
$th
at
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertSame
(
'x_1'
,
$
createdIndexNames
[
0
]
);
$this
->
assertIndexExists
(
'x_1'
,
function
(
IndexInfo
$info
)
{
$th
is
->
assertTrue
(
$info
->
isSparse
());
$th
is
->
assertTrue
(
$info
->
isUnique
());
$th
is
->
assertFalse
(
$info
->
isTtl
());
});
}
public
function
testCreateCompoundIndex
()
{
$indexes
=
[[
'key'
=>
[
'y'
=>
-
1
,
'z'
=>
1
]]];
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertSame
(
'y_-1_z_1'
,
$
this
->
collection
->
createIndex
([
'y'
=>
-
1
,
'z'
=>
1
])
);
$this
->
assertIndexExists
(
'y_-1_z_1'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$th
at
->
assertFalse
(
$info
->
isSparse
());
$th
at
->
assertFalse
(
$info
->
isUnique
());
$th
at
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertSame
(
'y_-1_z_1'
,
$
createdIndexNames
[
0
]
);
$this
->
assertIndexExists
(
'y_-1_z_1'
,
function
(
IndexInfo
$info
)
{
$th
is
->
assertFalse
(
$info
->
isSparse
());
$th
is
->
assertFalse
(
$info
->
isUnique
());
$th
is
->
assertFalse
(
$info
->
isTtl
());
});
}
public
function
testCreateGeospatialIndex
()
{
$indexes
=
[[
'key'
=>
[
'g'
=>
'2dsphere'
,
'z'
=>
1
]]];
$this
->
assertSame
(
'g_2dsphere_z_1'
,
$this
->
collection
->
createIndex
([
'g'
=>
'2dsphere'
,
'z'
=>
1
]));
$this
->
assertIndexExists
(
'g_2dsphere_z_1'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$that
->
assertFalse
(
$info
->
isSparse
());
$that
->
assertFalse
(
$info
->
isUnique
());
$that
->
assertFalse
(
$info
->
isTtl
());
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertSame
(
'g_2dsphere_z_1'
,
$createdIndexNames
[
0
]);
$this
->
assertIndexExists
(
'g_2dsphere_z_1'
,
function
(
IndexInfo
$info
)
{
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isUnique
());
$this
->
assertFalse
(
$info
->
isTtl
());
});
}
$this
->
assertSame
(
'my_ttl'
,
$this
->
collection
->
createIndex
([
't'
=>
1
],
[
'expireAfterSeconds'
=>
0
,
'name'
=>
'my_ttl'
]));
$this
->
assertIndexExists
(
'my_ttl'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$that
->
assertFalse
(
$info
->
isSparse
());
$that
->
assertFalse
(
$info
->
isUnique
());
$that
->
assertTrue
(
$info
->
isTtl
());
public
function
testCreateTTLIndex
()
{
$indexes
=
[[
'key'
=>
[
't'
=>
1
],
'expireAfterSeconds'
=>
0
,
'name'
=>
'my_ttl'
]];
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertSame
(
'my_ttl'
,
$createdIndexNames
[
0
]);
$this
->
assertIndexExists
(
'my_ttl'
,
function
(
IndexInfo
$info
)
{
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isUnique
());
$this
->
assertTrue
(
$info
->
isTtl
());
});
}
public
function
testCreateIndexes
()
{
$that
=
$this
;
$expectedNames
=
[
'x_1'
,
'y_-1_z_1'
,
'g_2dsphere_z_1'
,
'my_ttl'
];
$indexes
=
[
...
...
@@ -58,103 +83,78 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
[
'key'
=>
[
't'
=>
1
],
'expireAfterSeconds'
=>
0
,
'name'
=>
'my_ttl'
],
];
$this
->
assertSame
(
$expectedNames
,
$this
->
collection
->
createIndexes
(
$indexes
));
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertSame
(
$expectedNames
,
$createdIndexNames
);
$this
->
assertIndexExists
(
'x_1'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$th
at
->
assertTrue
(
$info
->
isSparse
());
$th
at
->
assertTrue
(
$info
->
isUnique
());
$th
at
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertIndexExists
(
'x_1'
,
function
(
IndexInfo
$info
)
{
$th
is
->
assertTrue
(
$info
->
isSparse
());
$th
is
->
assertTrue
(
$info
->
isUnique
());
$th
is
->
assertFalse
(
$info
->
isTtl
());
});
$this
->
assertIndexExists
(
'y_-1_z_1'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$th
at
->
assertFalse
(
$info
->
isSparse
());
$th
at
->
assertFalse
(
$info
->
isUnique
());
$th
at
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertIndexExists
(
'y_-1_z_1'
,
function
(
IndexInfo
$info
)
{
$th
is
->
assertFalse
(
$info
->
isSparse
());
$th
is
->
assertFalse
(
$info
->
isUnique
());
$th
is
->
assertFalse
(
$info
->
isTtl
());
});
$this
->
assertIndexExists
(
'g_2dsphere_z_1'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$th
at
->
assertFalse
(
$info
->
isSparse
());
$th
at
->
assertFalse
(
$info
->
isUnique
());
$th
at
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertIndexExists
(
'g_2dsphere_z_1'
,
function
(
IndexInfo
$info
)
{
$th
is
->
assertFalse
(
$info
->
isSparse
());
$th
is
->
assertFalse
(
$info
->
isUnique
());
$th
is
->
assertFalse
(
$info
->
isTtl
());
});
$this
->
assertIndexExists
(
'my_ttl'
,
function
(
IndexInfo
$info
)
use
(
$that
)
{
$th
at
->
assertFalse
(
$info
->
isSparse
());
$th
at
->
assertFalse
(
$info
->
isUnique
());
$th
at
->
assertTrue
(
$info
->
isTtl
());
$this
->
assertIndexExists
(
'my_ttl'
,
function
(
IndexInfo
$info
)
{
$th
is
->
assertFalse
(
$info
->
isSparse
());
$th
is
->
assertFalse
(
$info
->
isUnique
());
$th
is
->
assertTrue
(
$info
->
isTtl
());
});
}
/**
* @expectedException MongoDB\
Exception\InvalidArgument
Exception
* @expectedException MongoDB\
Driver\Exception\Runtime
Exception
*/
public
function
testCreate
IndexesRequiresAtLeastOneIndex
()
public
function
testCreate
ConflictingIndexesWithCommand
()
{
$this
->
assertSame
([],
$this
->
collection
->
createIndexes
([]));
}
public
function
testDropIndex
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
([
'x'
=>
1
]));
$this
->
assertIndexExists
(
'x_1'
);
$this
->
assertCommandSucceeded
(
$this
->
collection
->
dropIndex
(
'x_1'
));
foreach
(
$this
->
collection
->
listIndexes
()
as
$index
)
{
if
(
$index
->
getName
()
===
'x_1'
)
{
$this
->
fail
(
'The "x_1" index should have been deleted'
);
}
if
(
!
\MongoDB\server_supports_feature
(
$this
->
getPrimaryServer
(),
self
::
$wireVersionForCommand
))
{
$this
->
markTestSkipped
(
'createIndexes command is not supported'
);
}
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public
function
testDropIndexShouldNotAllowEmptyIndexName
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
([
'x'
=>
1
]));
$this
->
assertIndexExists
(
'x_1'
);
$this
->
collection
->
dropIndex
(
''
);
}
$indexes
=
[
[
'key'
=>
[
'x'
=>
1
],
'sparse'
=>
true
,
'unique'
=>
false
],
[
'key'
=>
[
'x'
=>
1
],
'sparse'
=>
false
,
'unique'
=>
true
],
];
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public
function
testDropIndexShouldNotAllowWildcardCharacter
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
([
'x'
=>
1
]));
$this
->
assertIndexExists
(
'x_1'
);
$this
->
collection
->
dropIndex
(
'*'
);
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
public
function
test
DropIndexes
()
public
function
test
CreateConflictingIndexesWithLegacyInsert
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
([
'x'
=>
1
]));
$this
->
assertSame
(
'y_1'
,
$this
->
collection
->
createIndex
([
'y'
=>
1
]));
$this
->
assertIndexExists
(
'x_1'
);
$this
->
assertIndexExists
(
'y_1'
);
$this
->
assertCommandSucceeded
(
$this
->
collection
->
dropIndexes
());
foreach
(
$this
->
collection
->
listIndexes
()
as
$index
)
{
if
(
$index
->
getName
()
===
'x_1'
)
{
$this
->
fail
(
'The "x_1" index should have been deleted'
);
}
if
(
$index
->
getName
()
===
'y_1'
)
{
$this
->
fail
(
'The "y_1" index should have been deleted'
);
}
if
(
\MongoDB\server_supports_feature
(
$this
->
getPrimaryServer
(),
self
::
$wireVersionForCommand
))
{
$this
->
markTestSkipped
(
'Index creation does not use legacy insertion'
);
}
}
public
function
testListIndexes
()
{
$this
->
assertSame
(
'x_1'
,
$this
->
collection
->
createIndex
([
'x'
=>
1
]));
$indexes
=
$this
->
collection
->
listIndexes
();
$this
->
assertInstanceOf
(
'MongoDB\Model\IndexInfoIterator'
,
$indexes
);
$indexes
=
[
[
'key'
=>
[
'x'
=>
1
],
'sparse'
=>
true
,
'unique'
=>
false
],
[
'key'
=>
[
'x'
=>
1
],
'sparse'
=>
false
,
'unique'
=>
true
],
];
foreach
(
$indexes
as
$index
)
{
$this
->
assertInstanceOf
(
'MongoDB\Model\IndexInfo'
,
$index
);
}
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
/* When creating indexes with legacy insert operations, the server
* ignores conflicting index specifications and leaves the original
* index in place.
*/
$this
->
assertSame
(
'x_1'
,
$createdIndexNames
[
0
]);
$this
->
assertIndexExists
(
'x_1'
,
function
(
IndexInfo
$info
)
{
$this
->
assertTrue
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isUnique
());
$this
->
assertFalse
(
$info
->
isTtl
());
});
}
/**
...
...
@@ -173,7 +173,8 @@ class IndexManagementFunctionalTest extends FunctionalTestCase
throw
new
InvalidArgumentException
(
'$callback is not a callable'
);
}
$indexes
=
$this
->
collection
->
listIndexes
();
$operation
=
new
ListIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$indexes
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$foundIndex
=
null
;
...
...
tests/Operation/CreateIndexesTest.php
0 → 100644
View file @
797ef704
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\CreateIndexes
;
class
CreateIndexesTest
extends
TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public
function
testCreateIndexesRequiresAtLeastOneIndex
()
{
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]);
}
/**
* @expectedException MongoDB\Exception\UnexpectedTypeException
* @dataProvider provideInvalidIndexSpecificationTypes
*/
public
function
testCreateIndexesRequiresIndexSpecificationsToBeAnArray
(
$index
)
{
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
$index
]);
}
public
function
provideInvalidIndexSpecificationTypes
()
{
return
$this
->
wrapValuesForDataProvider
(
$this
->
getInvalidArrayValues
());
}
}
tests/Operation/DropIndexesFunctionalTest.php
0 → 100644
View file @
797ef704
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Model\IndexInfo
;
use
MongoDB\Operation\CreateIndexes
;
use
MongoDB\Operation\DropIndexes
;
use
MongoDB\Operation\ListIndexes
;
use
InvalidArgumentException
;
class
DropIndexesFunctionalTest
extends
FunctionalTestCase
{
public
function
testDropOneIndexByName
()
{
$indexes
=
[[
'key'
=>
[
'x'
=>
1
]]];
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertSame
(
'x_1'
,
$createdIndexNames
[
0
]);
$this
->
assertIndexExists
(
'x_1'
);
$operation
=
new
DropIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x_1'
);
$this
->
assertCommandSucceeded
(
$operation
->
execute
(
$this
->
getPrimaryServer
()));
$operation
=
new
ListIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$indexes
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
foreach
(
$indexes
as
$index
)
{
if
(
$index
->
getName
()
===
'x_1'
)
{
$this
->
fail
(
'The "x_1" index should have been deleted'
);
}
}
}
public
function
testDropAllIndexesByWildcard
()
{
$indexes
=
[
[
'key'
=>
[
'x'
=>
1
]],
[
'key'
=>
[
'y'
=>
1
]],
];
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertSame
(
'x_1'
,
$createdIndexNames
[
0
]);
$this
->
assertSame
(
'y_1'
,
$createdIndexNames
[
1
]);
$this
->
assertIndexExists
(
'x_1'
);
$this
->
assertIndexExists
(
'y_1'
);
$operation
=
new
DropIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'*'
);
$this
->
assertCommandSucceeded
(
$operation
->
execute
(
$this
->
getPrimaryServer
()));
$operation
=
new
ListIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$indexes
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
foreach
(
$indexes
as
$index
)
{
if
(
$index
->
getName
()
===
'x_1'
)
{
$this
->
fail
(
'The "x_1" index should have been deleted'
);
}
if
(
$index
->
getName
()
===
'y_1'
)
{
$this
->
fail
(
'The "y_1" index should have been deleted'
);
}
}
}
/**
* Asserts that an index with the given name exists for the collection.
*
* An optional $callback may be provided, which should take an IndexInfo
* argument as its first and only parameter. If an IndexInfo matching the
* given name is found, it will be passed to the callback, which may perform
* additional assertions.
*
* @param callable $callback
*/
private
function
assertIndexExists
(
$indexName
,
$callback
=
null
)
{
if
(
$callback
!==
null
&&
!
is_callable
(
$callback
))
{
throw
new
InvalidArgumentException
(
'$callback is not a callable'
);
}
$operation
=
new
ListIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$indexes
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$foundIndex
=
null
;
foreach
(
$indexes
as
$index
)
{
if
(
$index
->
getName
()
===
$indexName
)
{
$foundIndex
=
$index
;
break
;
}
}
$this
->
assertNotNull
(
$foundIndex
,
sprintf
(
'Found %s index for the collection'
,
$indexName
));
if
(
$callback
!==
null
)
{
call_user_func
(
$callback
,
$foundIndex
);
}
}
}
tests/Operation/DropIndexesTest.php
0 → 100644
View file @
797ef704
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\DropIndexes
;
class
DropIndexesTest
extends
TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public
function
testDropIndexShouldNotAllowEmptyIndexName
()
{
new
DropIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
''
);
}
}
tests/Operation/ListIndexesFunctionalTest.php
View file @
797ef704
...
...
@@ -2,7 +2,6 @@
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Driver\Server
;
use
MongoDB\Operation\DropCollection
;
use
MongoDB\Operation\InsertOne
;
use
MongoDB\Operation\ListIndexes
;
...
...
@@ -11,18 +10,20 @@ class ListIndexesFunctionalTest extends FunctionalTestCase
{
public
function
testListIndexesForNewlyCreatedCollection
()
{
$server
=
$this
->
getPrimaryServer
();
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$
server
);
$operation
->
execute
(
$
this
->
getPrimaryServer
()
);
$insertOne
=
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1
]);
$writeResult
=
$insertOne
->
execute
(
$
server
);
$writeResult
=
$insertOne
->
execute
(
$
this
->
getPrimaryServer
()
);
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$operation
=
new
ListIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$indexes
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertInstanceOf
(
'MongoDB\Model\IndexInfoIterator'
,
$indexes
);
// Convert the CursorInfoIterator to an array since we cannot rewind its cursor
$indexes
=
iterator_to_array
(
$
operation
->
execute
(
$server
)
);
$indexes
=
iterator_to_array
(
$
indexes
);
$this
->
assertCount
(
1
,
$indexes
);
...
...
@@ -34,13 +35,11 @@ class ListIndexesFunctionalTest extends FunctionalTestCase
public
function
testListIndexesForNonexistentCollection
()
{
$server
=
$this
->
getPrimaryServer
();
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$
server
);
$operation
->
execute
(
$
this
->
getPrimaryServer
()
);
$operation
=
new
ListIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$indexes
=
$operation
->
execute
(
$
server
);
$indexes
=
$operation
->
execute
(
$
this
->
getPrimaryServer
()
);
$this
->
assertCount
(
0
,
$indexes
);
}
...
...
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