public function ClientFactoryTest::testGetHappy in MongoDB 8.2
Test a normal client creation attempt.
File
- modules/
mongodb/ tests/ src/ Kernel/ ClientFactoryTest.php, line 23
Class
- ClientFactoryTest
- Tests the ClientFactory.
Namespace
Drupal\Tests\mongodb\KernelCode
public function testGetHappy() {
$clientFactory = new ClientFactory($this->settings);
try {
$client = $clientFactory
->get(static::CLIENT_TEST_ALIAS);
// Force connection attempt by executing a command.
$client
->listDatabases();
} catch (ConnectionTimeoutException $e) {
$fail = new FormattableMarkup('Could not connect to server on @uri. Enable one on @default or specify one in MONGODB_URI.', [
'@default' => static::DEFAULT_URI,
'@uri' => $this->uri,
]);
$this
->fail("{$fail}");
} catch (\Exception $e) {
$this
->fail($e
->getMessage());
}
$this
->assertNotNull($clientFactory, "clientFactory must not be null");
$this
->assertEquals(ClientFactory::class, get_class($clientFactory));
}