Completed
Push — 8.x-2.x ( 4aaf30...f7089a )
by Frédéric G.
02:40
created

ClientFactoryTest::testGetSadBadAlias()   A

Complexity

Conditions 3
Paths 7

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 3
eloc 10
c 2
b 0
f 1
nc 7
nop 0
dl 0
loc 16
rs 9.4285
1
<?php
2
3
namespace Drupal\mongodb\Tests;
4
5
use Drupal\Component\Render\FormattableMarkup;
6
use Drupal\mongodb\ClientFactory;
7
use MongoDB\Driver\Exception\ConnectionTimeoutException;
8
9
/**
10
 * Class ClientFactoryTest.
11
 *
12
 * @group MongoDB
13
 */
14
class ClientFactoryTest extends MongoDbTestBase {
15
16
  /**
17
   * Test a normal client creation attempt.
18
   */
19
  public function testGetHappy() {
20
    $clientFactory = new ClientFactory($this->settings);
1 ignored issue
show
introduced by
Variable "clientFactory" is camel caps format. do not use mixed case (camelCase), use lower case and _
Loading history...
21
22
    try {
23
      $client = $clientFactory->get(static::CLIENT_TEST_ALIAS);
1 ignored issue
show
introduced by
Variable "clientFactory" is camel caps format. do not use mixed case (camelCase), use lower case and _
Loading history...
24
      // Force connection attempt by executing a command.
25
      $client->listDatabases();
26
    }
27
    catch (ConnectionTimeoutException $e) {
28
      $this->fail(new FormattableMarkup('Could not connect to server on @uri. Enable one on @default or specify one in MONGODB_URI.', [
29
        '@default' => static::DEFAULT_URI,
30
        '@uri' => $this->uri,
31
      ]));
32
    }
33
    catch (\Exception $e) {
34
      $this->fail($e->getMessage());
35
    }
36
  }
37
38
  /**
39
   * Test an existing alias pointing to an invalid server.
40
   */
41
  public function testGetSadBadAlias() {
42
    $clientFactory = new ClientFactory($this->settings);
1 ignored issue
show
introduced by
Variable "clientFactory" is camel caps format. do not use mixed case (camelCase), use lower case and _
Loading history...
43
44
    try {
45
      $client = $clientFactory->get(static::CLIENT_BAD_ALIAS);
1 ignored issue
show
introduced by
Variable "clientFactory" is camel caps format. do not use mixed case (camelCase), use lower case and _
Loading history...
46
      // Force connection attempt by executing a command.
47
      $client->listDatabases();
48
      $this->fail('Should not have been able to connect to a non-server.');
49
    }
50
    catch (ConnectionTimeoutException $e) {
1 ignored issue
show
Bug introduced by
The class MongoDB\Driver\Exception...nectionTimeoutException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
51
      $this->assertTrue(TRUE, 'Cannot create a client to a non-server.');
52
    }
53
    catch (\Exception $e) {
54
      $this->fail($e->getMessage());
55
    }
56
  }
57
58
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
59