| Server IP : 54.233.248.239 / Your IP : 172.28.20.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/vendor/mongodb/mongodb/tests/Operation/ |
Upload File : |
<?php
namespace MongoDB\Tests\Operation;
use MongoDB\Driver\BulkWrite;
use MongoDB\Operation\CreateCollection;
use MongoDB\Operation\CreateIndexes;
use MongoDB\Operation\DropCollection;
use MongoDB\Operation\Find;
use MongoDB\Tests\CommandObserver;
use stdClass;
class FindFunctionalTest extends FunctionalTestCase
{
public function testDefaultReadConcernIsOmitted()
{
(new CommandObserver)->observe(
function() {
$operation = new Find(
$this->getDatabaseName(),
$this->getCollectionName(),
[],
['readConcern' => $this->createDefaultReadConcern()]
);
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertObjectNotHasAttribute('readConcern', $command);
}
);
}
public function testHintOption()
{
$bulkWrite = new BulkWrite;
$bulkWrite->insert(['_id' => 1, 'x' => 1]);
$bulkWrite->insert(['_id' => 2, 'x' => 2]);
$bulkWrite->insert(['_id' => 3, 'y' => 3]);
$this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
$createIndexes = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [
['key' => ['x' => 1], 'sparse' => true, 'name' => 'sparse_x'],
['key' => ['y' => 1]],
]);
$createIndexes->execute($this->getPrimaryServer());
$hintsUsingSparseIndex = [
['x' => 1],
'sparse_x',
];
foreach ($hintsUsingSparseIndex as $hint) {
$operation = new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['hint' => $hint]);
$cursor = $operation->execute($this->getPrimaryServer());
$expectedDocuments = [
(object) ['_id' => 1, 'x' => 1],
(object) ['_id' => 2, 'x' => 2],
];
$this->assertEquals($expectedDocuments, $cursor->toArray());
}
$hintsNotUsingSparseIndex = [
['_id' => 1],
['y' => 1],
'y_1',
];
foreach ($hintsNotUsingSparseIndex as $hint) {
$operation = new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['hint' => $hint]);
$cursor = $operation->execute($this->getPrimaryServer());
$expectedDocuments = [
(object) ['_id' => 1, 'x' => 1],
(object) ['_id' => 2, 'x' => 2],
(object) ['_id' => 3, 'y' => 3],
];
$this->assertEquals($expectedDocuments, $cursor->toArray());
}
}
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
public function testTypeMapOption(array $typeMap, array $expectedDocuments)
{
$this->createFixtures(3);
$operation = new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['typeMap' => $typeMap]);
$cursor = $operation->execute($this->getPrimaryServer());
$this->assertEquals($expectedDocuments, $cursor->toArray());
}
public function provideTypeMapOptionsAndExpectedDocuments()
{
return [
[
['root' => 'array', 'document' => 'array'],
[
['_id' => 1, 'x' => ['foo' => 'bar']],
['_id' => 2, 'x' => ['foo' => 'bar']],
['_id' => 3, 'x' => ['foo' => 'bar']],
],
],
[
['root' => 'object', 'document' => 'array'],
[
(object) ['_id' => 1, 'x' => ['foo' => 'bar']],
(object) ['_id' => 2, 'x' => ['foo' => 'bar']],
(object) ['_id' => 3, 'x' => ['foo' => 'bar']],
],
],
[
['root' => 'array', 'document' => 'stdClass'],
[
['_id' => 1, 'x' => (object) ['foo' => 'bar']],
['_id' => 2, 'x' => (object) ['foo' => 'bar']],
['_id' => 3, 'x' => (object) ['foo' => 'bar']],
],
],
];
}
public function testMaxAwaitTimeMS()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('maxAwaitTimeMS option is not supported');
}
$maxAwaitTimeMS = 10;
// Create a capped collection.
$databaseName = $this->getDatabaseName();
$cappedCollectionName = $this->getCollectionName();
$cappedCollectionOptions = [
'capped' => true,
'max' => 100,
'size' => 1048576,
];
$operation = new CreateCollection($databaseName, $cappedCollectionName, $cappedCollectionOptions);
$operation->execute($this->getPrimaryServer());
// Insert documents into the capped collection.
$bulkWrite = new BulkWrite(['ordered' => true]);
$bulkWrite->insert(['_id' => 1]);
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
$operation = new Find($databaseName, $cappedCollectionName, [], ['cursorType' => Find::TAILABLE_AWAIT, 'maxAwaitTimeMS' => $maxAwaitTimeMS]);
$cursor = $operation->execute($this->getPrimaryServer());
$it = new \IteratorIterator($cursor);
// Make sure we await results for no more than the maxAwaitTimeMS.
$it->rewind();
$it->next();
$startTime = microtime(true);
$it->next();
$this->assertGreaterThanOrEqual($maxAwaitTimeMS * 0.001, microtime(true) - $startTime);
}
/**
* Create data fixtures.
*
* @param integer $n
*/
private function createFixtures($n)
{
$bulkWrite = new BulkWrite(['ordered' => true]);
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
'_id' => $i,
'x' => (object) ['foo' => 'bar'],
]);
}
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
$this->assertEquals($n, $result->getInsertedCount());
}
}