class RequireEventTraitTest

@covers \Drupal\package_manager\Event\RequireEventTrait @group package_manager @internal

Hierarchy

Expanded class hierarchy of RequireEventTraitTest

File

core/modules/package_manager/tests/src/Unit/RequireEventTraitTest.php, line 14

Namespace

Drupal\Tests\package_manager\Unit
View source
class RequireEventTraitTest 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().
     *
     * @dataProvider providerGetPackages
     */
    public function testGetPackages(array $runtime_packages, array $dev_packages, array $expected_runtime_packages, array $expected_dev_packages) : void {
        $stage = $this->createMock('\\Drupal\\package_manager\\StageBase');
        $events = [
            '\\Drupal\\package_manager\\Event\\PostRequireEvent',
            '\\Drupal\\package_manager\\Event\\PreRequireEvent',
        ];
        foreach ($events as $event) {
            
            /** @var \Drupal\package_manager\Event\RequireEventTrait $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
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
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.
RequireEventTraitTest::providerGetPackages public static function Data provider for testGetPackages().
RequireEventTraitTest::testGetPackages public function Tests that runtime and dev packages are keyed correctly.
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::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
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::setUp protected function 367
UnitTestCase::setUpBeforeClass public static function

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