function InstalledPackagesListTest::testPackageComparison

@covers ::getPackagesNotIn
@covers ::getPackagesWithDifferentVersionsIn

File

core/modules/package_manager/tests/src/Unit/InstalledPackagesListTest.php, line 40

Class

InstalledPackagesListTest
@coversDefaultClass \Drupal\package_manager\InstalledPackagesList[[api-linebreak]]

Namespace

Drupal\Tests\package_manager\Unit

Code

public function testPackageComparison() : void {
  $active = new InstalledPackagesList([
    'drupal/existing' => InstalledPackage::createFromArray([
      'name' => 'drupal/existing',
      'version' => '1.0.0',
      'path' => __DIR__,
      'type' => 'drupal-module',
    ]),
    'drupal/updated' => InstalledPackage::createFromArray([
      'name' => 'drupal/updated',
      'version' => '1.0.0',
      'path' => __DIR__,
      'type' => 'drupal-module',
    ]),
    'drupal/removed' => InstalledPackage::createFromArray([
      'name' => 'drupal/removed',
      'version' => '1.0.0',
      'path' => __DIR__,
      'type' => 'drupal-module',
    ]),
  ]);
  $staged = new InstalledPackagesList([
    'drupal/existing' => InstalledPackage::createFromArray([
      'name' => 'drupal/existing',
      'version' => '1.0.0',
      'path' => __DIR__,
      'type' => 'drupal-module',
    ]),
    'drupal/updated' => InstalledPackage::createFromArray([
      'name' => 'drupal/updated',
      'version' => '1.1.0',
      'path' => __DIR__,
      'type' => 'drupal-module',
    ]),
    'drupal/added' => InstalledPackage::createFromArray([
      'name' => 'drupal/added',
      'version' => '1.0.0',
      'path' => __DIR__,
      'type' => 'drupal-module',
    ]),
  ]);
  $added = $staged->getPackagesNotIn($active)
    ->getArrayCopy();
  $this->assertSame([
    'drupal/added',
  ], array_keys($added));
  $removed = $active->getPackagesNotIn($staged)
    ->getArrayCopy();
  $this->assertSame([
    'drupal/removed',
  ], array_keys($removed));
  $updated = $active->getPackagesWithDifferentVersionsIn($staged)
    ->getArrayCopy();
  $this->assertSame([
    'drupal/updated',
  ], array_keys($updated));
}

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