function FixtureManipulatorTest::testModifyPackageConfig

@covers ::modifyPackageConfig

File

core/modules/package_manager/tests/src/Kernel/FixtureManipulatorTest.php, line 145

Class

FixtureManipulatorTest
@coversDefaultClass \Drupal\fixture_manipulator\FixtureManipulator

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testModifyPackageConfig() : void {
    // Assert ::modifyPackage() works with a package in an existing fixture not
    // created by ::addPackage().
    $decode_packages_json = function () : array {
        return json_decode(file_get_contents($this->dir . "/packages.json"), TRUE, flags: JSON_THROW_ON_ERROR);
    };
    $original_packages_json = $decode_packages_json();
    (new ActiveFixtureManipulator())->modifyPackageConfig('my/dev-package', '2.1.0', [
        'description' => 'something else',
    ], TRUE)
        ->commitChanges();
    // Verify that the package is indeed properly installed.
    $this->assertSame('2.1.0', $this->inspector
        ->getInstalledPackagesList($this->dir)['my/dev-package']?->version);
    // Verify that the original exists, but has no description.
    $this->assertSame('my/dev-package', $original_packages_json['packages']['my/dev-package']['2.1.0']['name']);
    $this->assertArrayNotHasKey('description', $original_packages_json);
    // Verify that the description was updated.
    $this->assertSame('something else', $decode_packages_json()['packages']['my/dev-package']['2.1.0']['description']);
    (new ActiveFixtureManipulator())->modifyPackageConfig('my/package', '1.2.3', [
        'extra' => [
            'foo' => 'bar',
        ],
    ])
        ->setVersion('my/dev-package', '3.2.1', TRUE)
        ->commitChanges();
    $this->assertSame([
        'foo' => 'bar',
    ], $decode_packages_json()['packages']['my/package']['1.2.3']['extra']);
    $this->assertSame('3.2.1', $this->inspector
        ->getInstalledPackagesList($this->dir)['my/dev-package']?->version);
}

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