I'm trying to unit test my mongodb methods, thus I need a tearDown() method to flush my entire mongo database after testing.
Here is the function:
public function tearDown()
{
$databases = $this->mongoClient->listDatabases();
foreach ($databases as $db) {
$db.dropDatabase();
}
}
However it can't see the method on my $db.
Error: Call to undefined function Api\Test\Unit\dropDatabase()
It seems listDatabases() only return some information model of my dbs, not the actual databases themselves:
/var/www/html/tests/backend/Service/MongoStorageTest.php:35:
class MongoDB\Model\DatabaseInfo#1563 (3) {
public $name =>
string(5) "local"
public $sizeOnDisk =>
double(83886080)
public $empty =>
bool(false)
}
/var/www/html/tests/backend/Service/MongoStorageTest.php:35:
class MongoDB\Model\DatabaseInfo#1483 (3) {
public $name =>
string(2) "db"
public $sizeOnDisk =>
double(83886080)
public $empty =>
bool(false)
}
Is there any practical or simple way to really select them, or just drop everything with one method?