Doctrine\MongoDB\Connection::dropDatabase PHP Method

dropDatabase() public method

This method will dispatch preDropDatabase and postDropDatabase events.
See also: http://php.net/manual/en/mongoclient.dropdb.php
public dropDatabase ( string $database ) : array
$database string
return array
    public function dropDatabase($database)
    {
        if ($this->eventManager->hasListeners(Events::preDropDatabase)) {
            $this->eventManager->dispatchEvent(Events::preDropDatabase, new EventArgs($this, $database));
        }
        $this->initialize();
        $result = $this->mongoClient->dropDB($database);
        if ($this->eventManager->hasListeners(Events::postDropDatabase)) {
            $this->eventManager->dispatchEvent(Events::postDropDatabase, new EventArgs($this, $result));
        }
        return $result;
    }

Usage Example

 protected function setUp()
 {
     $connection = new Connection();
     $eventStoreOptions = new DoctrineMongoDBStorageOptions('palya-test-events');
     $snapshotStorageOptions = new DoctrineMongoDBStorageOptions('palya-test-snapshots');
     // set up a clean state by deleting the database
     $connection->dropDatabase($eventStoreOptions->getDatabase());
     $connection->dropDatabase($snapshotStorageOptions->getDatabase());
     $serializer = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $registry) {
         $registry->registerSubscribingHandler(new UuidHandler());
     })->build();
     $this->eventStore = new EventStore(new DoctrineMongoDBEventStorage($connection, $eventStoreOptions, $serializer), new NullBus(), new InMemoryIdentityMap());
     $snapshotStorage = new DoctrineMongoDBSnapshotStorage($connection, $eventStoreOptions, $serializer);
     $this->customerRepository = new CustomerRepository($this->eventStore);
     $this->customerSnapshotRepository = new CustomerSnapshotRepository($this->eventStore, $snapshotStorage);
 }