function ComposerInspectorTest::testComposerValidateIsCalled

@covers ::validate

File

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

Class

ComposerInspectorTest
@coversDefaultClass \Drupal\package_manager\ComposerInspector

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testComposerValidateIsCalled() : void {
    $project_root = $this->container
        ->get(PathLocator::class)
        ->getProjectRoot();
    // Put an invalid value into composer.json and ensure it gets surfaced as
    // an exception.
    $file = new JsonFile($project_root . '/composer.json');
    $this->assertTrue($file->exists());
    $data = $file->read();
    $data['prefer-stable'] = 'truthy';
    $file->write($data);
    try {
        $this->container
            ->get(ComposerInspector::class)
            ->validate($project_root);
        $this->fail('Expected an exception to be thrown, but it was not.');
    } catch (ComposerNotReadyException $e) {
        $this->assertSame($project_root, $e->workingDir);
        // The exception message is translated by Composer Stager and HTML-escaped
        // by Drupal's markup system, which is why there's a " in the
        // final exception message.
        $this->assertStringContainsString('composer.json" does not match the expected JSON schema', $e->getMessage());
        $this->assertStringContainsString('prefer-stable : String value found, but a boolean is required', $e->getPrevious()?->getMessage());
    }
}

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