You are here

public function ClientFactoryTest::testGetSadBadAlias in MongoDB 8.2

Test an existing alias pointing to an invalid server.

File

modules/mongodb/tests/src/Kernel/ClientFactoryTest.php, line 48

Class

ClientFactoryTest
Tests the ClientFactory.

Namespace

Drupal\Tests\mongodb\Kernel

Code

public function testGetSadBadAlias() {
  $clientFactory = new ClientFactory($this->settings);
  try {
    $client = $clientFactory
      ->get(static::CLIENT_BAD_ALIAS);

    // Force connection attempt by executing a command.
    $client
      ->listDatabases();
    $this
      ->fail('Should not have been able to connect to a non-server.');
  } catch (ConnectionTimeoutException $e) {
    $this
      ->assertTrue(TRUE, 'Cannot create a client to a non-server.');
  } catch (\Exception $e) {
    $this
      ->fail($e
      ->getMessage());
  }
}