function ComposerInspectorTest::testConfig

@covers ::getConfig

File

core/modules/package_manager/tests/src/Kernel/ComposerInspectorTest.php, line 38

Class

ComposerInspectorTest
@coversDefaultClass \Drupal\package_manager\ComposerInspector[[api-linebreak]]

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testConfig() : void {
  $dir = $this->container
    ->get(PathLocator::class)
    ->getProjectRoot();
  $inspector = $this->container
    ->get(ComposerInspector::class);
  $this->assertTrue((bool) Json::decode($inspector->getConfig('secure-http', $dir)));
  $this->assertSame([
    'boo' => 'boo boo',
    "foo" => [
      "dev" => "2.x-dev",
    ],
    "foo-bar" => TRUE,
    "boo-far" => [
      "foo" => 1.23,
      "bar" => 134,
      "foo-bar" => NULL,
    ],
    'baz' => NULL,
    'installer-paths' => [
      'modules/contrib/{$name}' => [
        'type:drupal-module',
      ],
      'profiles/contrib/{$name}' => [
        'type:drupal-profile',
      ],
      'themes/contrib/{$name}' => [
        'type:drupal-theme',
      ],
    ],
  ], Json::decode($inspector->getConfig('extra', $dir)));
  try {
    $inspector->getConfig('non-existent-config', $dir);
    $this->fail('Expected an exception when trying to get a non-existent config key, but none was thrown.');
  } catch (RuntimeException) {
    // We don't need to do anything here.
  }
  // If composer.json is removed, we should get an exception because
  // getConfig() should validate that $dir is Composer-ready.
  unlink($dir . '/composer.json');
  $this->expectExceptionMessage("composer.json not found.");
  $inspector->getConfig('extra', $dir);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.