class InstalledPackagesListTest
Tests Drupal\package_manager\InstalledPackagesList.
Attributes
#[CoversClass(InstalledPackagesList::class)]
#[Group('package_manager')]
  Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase- class \Drupal\Tests\package_manager\Unit\InstalledPackagesListTest extends \Drupal\Tests\UnitTestCase
 
Expanded class hierarchy of InstalledPackagesListTest
File
- 
              core/modules/ package_manager/ tests/ src/ Unit/ InstalledPackagesListTest.php, line 17 
Namespace
Drupal\Tests\package_manager\UnitView source
class InstalledPackagesListTest extends UnitTestCase {
  
  /**
   * Tests immutability.
   *
   * @legacy-covers ::offsetSet
   * @legacy-covers ::offsetUnset
   * @legacy-covers ::append
   * @legacy-covers ::exchangeArray
   */
  public function testImmutability(string $method, array $arguments) : void {
    $list = new InstalledPackagesList([
      'existing' => 'thing',
    ]);
    $this->expectException(\LogicException::class);
    $this->expectExceptionMessage('Installed package lists cannot be modified.');
    $list->{$method}(...$arguments);
  }
  
  /**
   * Tests package comparison.
   *
   * @legacy-covers ::getPackagesNotIn
   * @legacy-covers ::getPackagesWithDifferentVersionsIn
   */
  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));
  }
  
  /**
   * Tests core packages.
   *
   * @legacy-covers ::getCorePackages
   */
  public function testCorePackages() : void {
    $data = [
      'drupal/core' => InstalledPackage::createFromArray([
        'name' => 'drupal/core',
        'version' => \Drupal::VERSION,
        'type' => 'drupal-core',
        'path' => __DIR__,
      ]),
      'drupal/core-dev' => InstalledPackage::createFromArray([
        'name' => 'drupal/core-dev',
        'version' => \Drupal::VERSION,
        'type' => 'metapackage',
        'path' => NULL,
      ]),
      'drupal/core-dev-pinned' => InstalledPackage::createFromArray([
        'name' => 'drupal/core-dev-pinned',
        'version' => \Drupal::VERSION,
        'type' => 'metapackage',
        'path' => NULL,
      ]),
      'drupal/core-composer-scaffold' => InstalledPackage::createFromArray([
        'name' => 'drupal/core-composer-scaffold',
        'version' => \Drupal::VERSION,
        'type' => 'composer-plugin',
        'path' => __DIR__,
      ]),
      'drupal/core-project-message' => [
        'name' => 'drupal/core-project-message',
        'version' => \Drupal::VERSION,
        'type' => 'composer-plugin',
        'path' => __DIR__,
      ],
      'drupal/core-vendor-hardening' => InstalledPackage::createFromArray([
        'name' => 'drupal/core-vendor-hardening',
        'version' => \Drupal::VERSION,
        'type' => 'composer-plugin',
        'path' => __DIR__,
      ]),
      'drupal/not-core' => InstalledPackage::createFromArray([
        'name' => 'drupal/not-core',
        'version' => '1.0.0',
        'type' => 'drupal-module',
        'path' => __DIR__,
      ]),
    ];
    $list = new InstalledPackagesList($data);
    $this->assertArrayNotHasKey('drupal/not-core', $list->getCorePackages());
    // Tests that we don't get core packages intended for development when
    // include_dev is set to FALSE.
    $core_packages_no_dev = $list->getCorePackages(FALSE);
    $this->assertArrayNotHasKey('drupal/core-dev', $core_packages_no_dev);
    $this->assertArrayNotHasKey('drupal/core-dev-pinned', $core_packages_no_dev);
    // We still get other packages as intended.
    $this->assertArrayHasKey('drupal/core', $core_packages_no_dev);
    // If drupal/core-recommended is in the list, it should supersede
    // drupal/core.
    $this->assertArrayHasKey('drupal/core', $list->getCorePackages());
    $data['drupal/core-recommended'] = InstalledPackage::createFromArray([
      'name' => 'drupal/core-recommended',
      'version' => \Drupal::VERSION,
      'type' => 'metapackage',
      'path' => NULL,
    ]);
    $list = new InstalledPackagesList($data);
    $this->assertArrayNotHasKey('drupal/core', $list->getCorePackages());
  }
}Members
| Title Sort descending | Modifiers | Object type | Summary | Overrides | 
|---|---|---|---|---|
| ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
| ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
| InstalledPackagesListTest::testCorePackages | public | function | Tests core packages. | |
| InstalledPackagesListTest::testImmutability | public | function | Tests immutability. | |
| InstalledPackagesListTest::testPackageComparison | public | function | Tests package comparison. | |
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
| UnitTestCase::$root | protected | property | The app root. | |
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
| UnitTestCase::setUp | protected | function | 366 | |
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
