class EventWithPackageListTraitTest

Tests Event With Package List Trait.

@internal

Attributes

#[Group('package_manager')] #[CoversTrait(EventWithPackageListTrait::class)]

Hierarchy

Expanded class hierarchy of EventWithPackageListTraitTest

File

core/modules/package_manager/tests/src/Unit/EventWithPackageListTraitTest.php, line 18

Namespace

Drupal\Tests\package_manager\Unit
View source
class EventWithPackageListTraitTest extends UnitTestCase {
  
  /**
   * Tests that runtime and dev packages are keyed correctly.
   *
   * @param string[] $runtime_packages
   *   The runtime package constraints passed to the event constructor.
   * @param string[] $dev_packages
   *   The dev package constraints passed to the event constructor.
   * @param string[] $expected_runtime_packages
   *   The keyed runtime packages that should be returned by
   *   ::getRuntimePackages().
   * @param string[] $expected_dev_packages
   *   The keyed dev packages that should be returned by ::getDevPackages().
   */
  public function testGetPackages(array $runtime_packages, array $dev_packages, array $expected_runtime_packages, array $expected_dev_packages) : void {
    $stage = $this->createMock('\\Drupal\\package_manager\\SandboxManagerBase');
    $events = [
      '\\Drupal\\package_manager\\Event\\PostRequireEvent',
      '\\Drupal\\package_manager\\Event\\PreRequireEvent',
    ];
    foreach ($events as $event) {
      /** @var \Drupal\package_manager\Event\EventWithPackageListTrait $event */
      $event = new $event($stage, $runtime_packages, $dev_packages);
      $this->assertSame($expected_runtime_packages, $event->getRuntimePackages());
      $this->assertSame($expected_dev_packages, $event->getDevPackages());
    }
  }
  
  /**
   * Data provider for testGetPackages().
   *
   * @return mixed[]
   *   The test cases.
   */
  public static function providerGetPackages() : array {
    return [
      'Package with constraint' => [
        [
          'drupal/new_package:^8.1',
        ],
        [
          'drupal/dev_package:^9',
        ],
        [
          'drupal/new_package' => '^8.1',
        ],
        [
          'drupal/dev_package' => '^9',
        ],
      ],
      'Package without constraint' => [
        [
          'drupal/new_package',
        ],
        [
          'drupal/dev_package',
        ],
        [
          'drupal/new_package' => '*',
        ],
        [
          'drupal/dev_package' => '*',
        ],
      ],
    ];
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
EventWithPackageListTraitTest::providerGetPackages public static function Data provider for testGetPackages().
EventWithPackageListTraitTest::testGetPackages public function Tests that runtime and dev packages are keyed correctly.
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.
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.