ClientFunctionalTest.php 1.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php

namespace MongoDB\Tests;

use MongoDB\Client;

/**
 * Functional tests for the Client class.
 */
class ClientFunctionalTest extends FunctionalTestCase
{
    public function testDropDatabase()
    {
        $writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
        $this->assertEquals(1, $writeResult->getInsertedCount());

        $client = new Client($this->getUri());
        $commandResult = $client->dropDatabase($this->getDatabaseName());
        $this->assertCommandSucceeded($commandResult);
        $this->assertCollectionCount($this->getNamespace(), 0);
    }
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

    public function testListDatabases()
    {
        $writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
        $this->assertEquals(1, $writeResult->getInsertedCount());

        $client = new Client($this->getUri());
        $databases = $client->listDatabases();

        $this->assertInstanceOf('Traversable', $databases);

        $foundDatabase = null;

        foreach ($databases as $database) {
            if ($database['name'] === $this->getDatabaseName()) {
                $foundDatabase = $database;
                break;
            }
        }

        $this->assertNotNull($foundDatabase, 'Found test database in list of databases');
        $this->assertFalse($foundDatabase['empty'], 'Test database is not empty');
        $this->assertGreaterThan(0, $foundDatabase['sizeOnDisk'], 'Test database takes up disk space');
    }
46
}