Completed
Push — mkdocs ( 0b51ae...44be76 )
by Frédéric G.
10:49 queued 07:15
created

ClientFactoryTest::testGetSadBadAlias()   A

Complexity

Conditions 3
Paths 7

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 10
c 1
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
    $cf = new ClientFactory($this->settings);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $cf. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
21
22
    try {
23
      $client = $cf->get(static::CLIENT_TEST_ALIAS);
24
      // Force connection attempt by executing a command.
25
      $client->listDatabases();
26
    }
27
    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...
28
      $this->fail(new FormattableMarkup("Could not connect to server on @uri. Enable one on @default or specify one in MONGODB_URI.", [
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Could not connect to ser...ify one in MONGODB_URI. does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
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
    $cf = new ClientFactory($this->settings);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $cf. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
43
44
    try {
45
      $client = $cf->get(static::CLIENT_BAD_ALIAS);
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.");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Should not have been abl...onnect to a non-server. does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
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.");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Cannot create a client to a non-server. does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
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