class DependencyTest

Same name in this branch
  1. 9 core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest
Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest
  2. 8.9.x core/tests/Drupal/Tests/Core/Extension/DependencyTest.php \Drupal\Tests\Core\Extension\DependencyTest
  3. 10 core/modules/forum/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\forum\Functional\Module\DependencyTest
  4. 10 core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest
  5. 10 core/tests/Drupal/Tests/Core/Extension/DependencyTest.php \Drupal\Tests\Core\Extension\DependencyTest
  6. 11.x core/modules/forum/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\forum\Functional\Module\DependencyTest
  7. 11.x core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest
  8. 11.x core/tests/Drupal/Tests/Core/Extension/DependencyTest.php \Drupal\Tests\Core\Extension\DependencyTest

@coversDefaultClass \Drupal\Core\Extension\Dependency @group Extension

Hierarchy

Expanded class hierarchy of DependencyTest

File

core/tests/Drupal/Tests/Core/Extension/DependencyTest.php, line 13

Namespace

Drupal\Tests\Core\Extension
View source
class DependencyTest extends UnitTestCase {
    
    /**
     * @covers ::createFromString
     * @dataProvider providerCreateFromString
     */
    public function testCreateFromString($string, $expected_name, $expected_project, $expected_constraint) {
        $dependency = Dependency::createFromString($string);
        $this->assertSame($expected_name, $dependency->getName());
        $this->assertSame($expected_project, $dependency->getProject());
        $this->assertSame($expected_constraint, $dependency->getConstraintString());
    }
    
    /**
     * Data provider for testCreateFromString.
     */
    public function providerCreateFromString() {
        $tests = [];
        $tests['module_name_only'] = [
            'views',
            'views',
            '',
            '',
        ];
        $tests['module_and_project_names'] = [
            'drupal:views',
            'views',
            'drupal',
            '',
        ];
        $tests['module_and_constraint'] = [
            'views (<8.x-3.1)',
            'views',
            '',
            '<8.x-3.1',
        ];
        $tests['module_and_project_names_and_constraint'] = [
            'drupal:views (>8.x-1.1)',
            'views',
            'drupal',
            '>8.x-1.1',
        ];
        return $tests;
    }
    
    /**
     * @covers ::isCompatible
     */
    public function testIsCompatible() {
        $dependency = new Dependency('paragraphs_demo', 'paragraphs', '>8.x-1.1');
        $this->assertFalse($dependency->isCompatible('1.1'));
        $this->assertTrue($dependency->isCompatible('1.2'));
    }
    
    /**
     * Ensures that constraint objects are not serialized.
     *
     * @covers ::__sleep
     */
    public function testSerialization() {
        $dependency = new Dependency('paragraphs_demo', 'paragraphs', '>8.x-1.1');
        $this->assertTrue($dependency->isCompatible('1.2'));
        $reflected_constraint = (new \ReflectionObject($dependency))->getProperty('constraint');
        $reflected_constraint->setAccessible(TRUE);
        $constraint = $reflected_constraint->getValue($dependency);
        $this->assertInstanceOf(Constraint::class, $constraint);
        $dependency = unserialize(serialize($dependency));
        $reflected_constraint = (new \ReflectionObject($dependency))->getProperty('constraint');
        $reflected_constraint->setAccessible(TRUE);
        $constraint = $reflected_constraint->getValue($dependency);
        $this->assertNull($constraint);
        $this->assertTrue($dependency->isCompatible('1.2'));
        $constraint = $reflected_constraint->getValue($dependency);
        $this->assertInstanceOf(Constraint::class, $constraint);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overrides
DependencyTest::providerCreateFromString public function Data provider for testCreateFromString.
DependencyTest::testCreateFromString public function @covers ::createFromString
@dataProvider providerCreateFromString
DependencyTest::testIsCompatible public function @covers ::isCompatible
DependencyTest::testSerialization public function Ensures that constraint objects are not serialized.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 338
UnitTestCase::setUpBeforeClass public static function

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