Completed
Push — 2762893-mongodb_tests ( 476c0a...a0e627 )
by Frédéric G.
03:02
created

MongoDbTestBase   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 54
rs 10
wmc 1
lcom 1
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 28 1
1
<?php
2
3
namespace Drupal\mongodb\Tests;
4
5
use Drupal\Core\Site\Settings;
6
use Drupal\KernelTests\KernelTestBase;
7
8
abstract class MongoDbTestBase extends KernelTestBase {
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
9
  const DEFAULT_URI = 'mongodb://localhost:27017';
10
  const CLIENT_BAD_ALIAS = 'bad';
11
  const CLIENT_TEST_ALIAS = 'test';
12
13
  const DB_BAD_CLIENT_ALIAS = 'bad';
14
  const DB_INVALID_ALIAS = 'invalid';
15
  const DB_DEFAULT_ALIAS = 'default';
16
  const DB_UNSET_ALIAS = 'unset';
17
18
  public static $modules = ['mongodb'];
19
20
  /**
21
   * A test-specific instance of Settings.
22
   *
23
   * @var \Drupal\Core\Site\Settings
24
   */
25
  protected $settings;
26
27
  protected $uri;
28
29
  /**
30
   * {@inheritdoc}
31
   */
32
  public function setUp() {
33
    parent::setUp();
34
    // $_ENV if it comes from phpunit.xml <env>
35
    // $_SERVER if it comes from the phpunit command line environment
0 ignored issues
show
introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
36
    $this->uri = $_ENV['MONGODB_URL'] ?? $_SERVER['MONGODB_URI'] ?? static::DEFAULT_URI;
1 ignored issue
show
introduced by
Expected 1 space after "?"; 0 found
Loading history...
37
38
    $this->settings = new Settings([
39
      'mongodb' => [
40
        'clients' => [
41
          static::CLIENT_BAD_ALIAS => [
42
            'uri' => 'mongodb://localhost:80',
43
            'uriOptions' => [],
44
            'driverOptions' => [],
45
          ],
46
          static::CLIENT_TEST_ALIAS => [
47
            'uri' => $this->uri,
48
            'uriOptions' => [],
49
            'driverOptions' => [],
50
          ],
51
        ],
52
        'databases' => [
53
          static::DB_DEFAULT_ALIAS => [static::CLIENT_TEST_ALIAS, $this->getDatabasePrefix()],
54
          static::DB_INVALID_ALIAS => [static::CLIENT_TEST_ALIAS, ''],
55
          static::DB_BAD_CLIENT_ALIAS => [static::CLIENT_BAD_ALIAS, $this->getDatabasePrefix()],
56
        ],
57
      ],
58
    ]);
59
  }
60
61
}
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...
62