class StageBaseTest

Same name in this branch
  1. 11.x core/modules/package_manager/tests/src/Kernel/StageBaseTest.php \Drupal\Tests\package_manager\Kernel\StageBaseTest

@coversDefaultClass \Drupal\package_manager\StageBase @group package_manager @internal

Hierarchy

  • class \Drupal\Tests\package_manager\Unit\StageBaseTest extends \Drupal\Tests\UnitTestCase

Expanded class hierarchy of StageBaseTest

File

core/modules/package_manager/tests/src/Unit/StageBaseTest.php, line 15

Namespace

Drupal\Tests\package_manager\Unit
View source
class StageBaseTest extends UnitTestCase {
    
    /**
     * @covers ::validateRequirements
     *
     * @param string|null $expected_exception
     *   The exception class that should be thrown, or NULL if there should not be
     *   any exception.
     * @param string $requirement
     *   The requirement (package name and optional constraint) to validate.
     *
     * @dataProvider providerValidateRequirements
     */
    public function testValidateRequirements(?string $expected_exception, string $requirement) : void {
        $reflector = new \ReflectionClass(StageBase::class);
        $method = $reflector->getMethod('validateRequirements');
        if ($expected_exception) {
            $this->expectException($expected_exception);
        }
        else {
            $this->assertNull($expected_exception);
        }
        $method->invoke(NULL, [
            $requirement,
        ]);
    }
    
    /**
     * Data provider for testValidateRequirements.
     *
     * @return array[]
     *   The test cases.
     */
    public static function providerValidateRequirements() : array {
        return [
            // Valid requirements.
[
                NULL,
                'vendor/package',
            ],
            [
                NULL,
                'vendor/snake_case',
            ],
            [
                NULL,
                'vendor/kebab-case',
            ],
            [
                NULL,
                'vendor/with.dots',
            ],
            [
                NULL,
                '1vendor2/3package4',
            ],
            [
                NULL,
                'vendor/package:1',
            ],
            [
                NULL,
                'vendor/package:1.2',
            ],
            [
                NULL,
                'vendor/package:1.2.3',
            ],
            [
                NULL,
                'vendor/package:1.x',
            ],
            [
                NULL,
                'vendor/package:^1',
            ],
            [
                NULL,
                'vendor/package:~1',
            ],
            [
                NULL,
                'vendor/package:>1',
            ],
            [
                NULL,
                'vendor/package:<1',
            ],
            [
                NULL,
                'vendor/package:>=1',
            ],
            [
                NULL,
                'vendor/package:>1 <2',
            ],
            [
                NULL,
                'vendor/package:1 || 2',
            ],
            [
                NULL,
                'vendor/package:>=1,<1.1.0',
            ],
            [
                NULL,
                'vendor/package:1a',
            ],
            [
                NULL,
                'vendor/package:*',
            ],
            [
                NULL,
                'vendor/package:dev-master',
            ],
            [
                NULL,
                'vendor/package:*@dev',
            ],
            [
                NULL,
                'vendor/package:@dev',
            ],
            [
                NULL,
                'vendor/package:master@dev',
            ],
            [
                NULL,
                'vendor/package:master@beta',
            ],
            [
                NULL,
                'php',
            ],
            [
                NULL,
                'php:8',
            ],
            [
                NULL,
                'php:8.0',
            ],
            [
                NULL,
                'php:^8.1',
            ],
            [
                NULL,
                'php:~8.1',
            ],
            [
                NULL,
                'php-64bit',
            ],
            [
                NULL,
                'composer',
            ],
            [
                NULL,
                'composer-plugin-api',
            ],
            [
                NULL,
                'composer-plugin-api:1',
            ],
            [
                NULL,
                'ext-json',
            ],
            [
                NULL,
                'ext-json:1',
            ],
            [
                NULL,
                'ext-pdo_mysql',
            ],
            [
                NULL,
                'ext-pdo_mysql:1',
            ],
            [
                NULL,
                'lib-curl',
            ],
            [
                NULL,
                'lib-curl:1',
            ],
            [
                NULL,
                'lib-curl-zlib',
            ],
            [
                NULL,
                'lib-curl-zlib:1',
            ],
            // Invalid requirements.
[
                \InvalidArgumentException::class,
                '',
            ],
            [
                \InvalidArgumentException::class,
                ' ',
            ],
            [
                \InvalidArgumentException::class,
                '/',
            ],
            [
                \InvalidArgumentException::class,
                'php8',
            ],
            [
                \InvalidArgumentException::class,
                'package',
            ],
            [
                \InvalidArgumentException::class,
                'vendor\\package',
            ],
            [
                \InvalidArgumentException::class,
                'vendor//package',
            ],
            [
                \InvalidArgumentException::class,
                'vendor/package1 vendor/package2',
            ],
            [
                \InvalidArgumentException::class,
                'vendor/package/extra',
            ],
            [
                \UnexpectedValueException::class,
                'vendor/package:a',
            ],
            [
                \UnexpectedValueException::class,
                'vendor/package:',
            ],
            [
                \UnexpectedValueException::class,
                'vendor/package::',
            ],
            [
                \UnexpectedValueException::class,
                'vendor/package::1',
            ],
            [
                \UnexpectedValueException::class,
                'vendor/package:1:2',
            ],
            [
                \UnexpectedValueException::class,
                'vendor/package:develop@dev@dev',
            ],
            [
                \UnexpectedValueException::class,
                'vendor/package:develop@',
            ],
            [
                \InvalidArgumentException::class,
                'vEnDor/pAcKaGe',
            ],
            [
                \InvalidArgumentException::class,
                '_vendor/package',
            ],
            [
                \InvalidArgumentException::class,
                '_vendor/_package',
            ],
            [
                \InvalidArgumentException::class,
                'vendor_/package',
            ],
            [
                \InvalidArgumentException::class,
                '_vendor/package_',
            ],
            [
                \InvalidArgumentException::class,
                'vendor/package-',
            ],
            [
                \InvalidArgumentException::class,
                'php-',
            ],
            [
                \InvalidArgumentException::class,
                'ext',
            ],
            [
                \InvalidArgumentException::class,
                'lib',
            ],
        ];
    }
    
    /**
     * @covers ::getType
     */
    public function testTypeMustBeExplicitlyOverridden() : void {
        $good_grandchild = new class  extends ChildStage {
            
            /**
             * {@inheritdoc}
             */
            // phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable
            protected string $type = 'package_manager:good_grandchild';

};
        $this->assertSame('package_manager:good_grandchild', $good_grandchild->getType());
        $bad_grandchild = new class  extends ChildStage {

};
        $this->expectException(\LogicException::class);
        $this->expectExceptionMessage(get_class($bad_grandchild) . ' must explicitly override the $type property.');
        $bad_grandchild->getType();
    }

}

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.
StageBaseTest::providerValidateRequirements public static function Data provider for testValidateRequirements.
StageBaseTest::testTypeMustBeExplicitlyOverridden public function @covers ::getType
StageBaseTest::testValidateRequirements public function @covers ::validateRequirements
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.