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

MongoDbTestBase::setUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 28
rs 8.8571
1
<?php
2
3
namespace Drupal\mongodb\Tests;
4
5
use Drupal\Core\Site\Settings;
6
use Drupal\KernelTests\KernelTestBase;
7
8
/**
9
 * Class MongoDbTestBase provides basic setUp()/tearDown() for MongoDB.
10
 *
11
 * @group MongoDB
12
 */
13
abstract class MongoDbTestBase extends KernelTestBase {
14
  const DEFAULT_URI = 'mongodb://localhost:27017';
15
  const CLIENT_BAD_ALIAS = 'bad';
16
  const CLIENT_TEST_ALIAS = 'test';
17
18
  const DB_BAD_CLIENT_ALIAS = 'bad';
19
  const DB_INVALID_ALIAS = 'invalid';
20
  const DB_DEFAULT_ALIAS = 'default';
21
  const DB_UNSET_ALIAS = 'unset';
22
23
  public static $modules = ['mongodb'];
24
25
  /**
26
   * A test-specific instance of Settings.
27
   *
28
   * @var \Drupal\Core\Site\Settings
29
   */
30
  protected $settings;
31
32
  protected $uri;
33
34
  /**
35
   * {@inheritdoc}
36
   */
37
  public function setUp() {
38
    parent::setUp();
39
    // $_ENV if it comes from phpunit.xml <env>
40
    // $_SERVER if it comes from the phpunit command line environment.
41
    $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...
42
43
    $this->settings = new Settings([
44
      'mongodb' => [
45
        'clients' => [
46
          static::CLIENT_BAD_ALIAS => [
47
            'uri' => 'mongodb://localhost:80',
48
            'uriOptions' => [],
49
            'driverOptions' => [],
50
          ],
51
          static::CLIENT_TEST_ALIAS => [
52
            'uri' => $this->uri,
53
            'uriOptions' => [],
54
            'driverOptions' => [],
55
          ],
56
        ],
57
        'databases' => [
58
          static::DB_DEFAULT_ALIAS => [static::CLIENT_TEST_ALIAS, $this->getDatabasePrefix()],
59
          static::DB_INVALID_ALIAS => [static::CLIENT_TEST_ALIAS, ''],
60
          static::DB_BAD_CLIENT_ALIAS => [static::CLIENT_BAD_ALIAS, $this->getDatabasePrefix()],
61
        ],
62
      ],
63
    ]);
64
  }
65
66
}
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...
67