Completed
Push — 1.0.x ( e6ac6e...9b8cfd )
by Antonio
06:50
created

ServiceContainerContext::rebuildContainer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace NuvoleWeb\Drupal\DrupalExtension\Context;
4
5
use Behat\Gherkin\Node\TableNode;
6
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
7
use function bovigo\assert\assert;
8
use function bovigo\assert\predicate\equals;
9
use function bovigo\assert\predicate\not;
10
11
/**
12
 * Contains Contacts specific step definitions.
13
 */
14
class ServiceContainerContext extends RawDrupalContext {
15
16
  /**
17
   * Override service parameters.
18
   *
19
   * @see BehatServiceProvider
20
   *
21
   * @Given I override the following service parameters:
22
   */
23
  public function overrideParameters(TableNode $table) {
24
    \Drupal::state()->set('nuvole_web.drupal_extension.parameter_overrides', $table->getRowsHash());
25
    \Drupal::service('kernel')->rebuildContainer();
26
  }
27
28
  /**
29
   * Rebuild container on after scenario.
30
   *
31
   * @AfterScenario
32
   */
33
  public function rebuildContainer() {
34
    if (\Drupal::state()->get('nuvole_web.drupal_extension.parameter_overrides')) {
35
      \Drupal::state()->set('nuvole_web.drupal_extension.parameter_overrides', []);
36
      \Drupal::service('kernel')->rebuildContainer();
37
    }
38
  }
39
40
  /**
41
   * Assert given service parameter has given value.
42
   *
43
   * @Then the service parameter :name should be set to :expected
44
   */
45
  public function assertParameters($name, $expected) {
46
    $value = \Drupal::getContainer()->getParameter($name);
47
    assert($value, equals($expected));
48
  }
49
50
  /**
51
   * Assert given service parameter has not given value.
52
   *
53
   * @Then the service parameter :name should not be set to :expected
54
   */
55
  public function negateParameters($name, $expected) {
56
    try {
57
      $value = \Drupal::getContainer()->getParameter($name);
58
      assert($value, not(equals($expected)));
59
    }
60
    catch (ParameterNotFoundException $e) { }
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
61
  }
62
63
}
64