class ProjectCoreCompatibilityTest
@coversDefaultClass \Drupal\update\ProjectCoreCompatibility
      
    
@group update
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase- class \Drupal\Tests\update\Unit\ProjectCoreCompatibilityTest extends \Drupal\Tests\UnitTestCase
 
Expanded class hierarchy of ProjectCoreCompatibilityTest
File
- 
              core/modules/ update/ tests/ src/ Unit/ ProjectCoreCompatibilityTest.php, line 15 
Namespace
Drupal\Tests\update\UnitView source
class ProjectCoreCompatibilityTest extends UnitTestCase {
  
  /**
   * @covers ::setReleaseMessage
   * @dataProvider providerSetProjectCoreCompatibilityRanges
   */
  public function testSetProjectCoreCompatibilityRanges(array $project_data, $core_data, array $supported_branches, array $core_releases, array $expected_releases, array $expected_security_updates) : void {
    $project_compatibility = new ProjectCoreCompatibility($core_data, $core_releases, $supported_branches);
    $project_compatibility->setStringTranslation($this->getStringTranslationStub());
    $project_compatibility->setReleaseMessage($project_data);
    $this->assertSame($expected_releases, $project_data['releases']);
    $this->assertSame($expected_security_updates, $project_data['security updates']);
  }
  
  /**
   * Data provider for testSetProjectCoreCompatibilityRanges().
   */
  public static function providerSetProjectCoreCompatibilityRanges() {
    $test_cases['no 9 releases, no supported branches'] = [
      'project_data' => [
        'recommended' => '1.0.1',
        'latest_version' => '1.2.3',
        'also' => [
          '1.2.4',
          '1.2.5',
          '1.2.6',
        ],
        'releases' => [
          '1.0.1' => [
            'core_compatibility' => '8.x',
          ],
          '1.2.3' => [
            'core_compatibility' => '^8.9 || ^9',
          ],
          '1.2.4' => [
            'core_compatibility' => '^8.9.2 || ^9',
          ],
          '1.2.6' => [],
        ],
        'security updates' => [
          '1.2.5' => [
            'core_compatibility' => '8.9.0 || 8.9.2 || ^9.0.1',
          ],
        ],
      ],
      'core_data' => [
        'existing_version' => '8.8.0',
      ],
      'supported_branches' => [],
      'core_releases' => [
        '8.8.0-alpha1' => [],
        '8.8.0-beta1' => [],
        '8.8.0-rc1' => [],
        '8.8.0' => [],
        '8.8.1' => [],
        '8.8.2' => [],
        '8.9.0' => [],
        '8.9.1' => [],
        '8.9.2' => [],
      ],
    ];
    // Confirm that with no core supported branches the releases are not changed.
    $test_cases['no 9 releases, no supported branches'] += [
      'expected_releases' => $test_cases['no 9 releases, no supported branches']['project_data']['releases'],
      'expected_security_updates' => $test_cases['no 9 releases, no supported branches']['project_data']['security updates'],
    ];
    // Confirm that if core has supported branches the releases will updated
    // with 'core_compatible' and 'core_compatibility_message'.
    $test_cases['no 9 releases'] = $test_cases['no 9 releases, no supported branches'];
    $test_cases['no 9 releases']['supported_branches'] = [
      '8.8.',
      '8.9.',
    ];
    $test_cases['no 9 releases']['expected_releases'] = [
      '1.0.1' => [
        'core_compatibility' => '8.x',
        'core_compatible' => TRUE,
        'core_compatibility_message' => 'Requires Drupal core: 8.8.0 to 8.9.2',
      ],
      '1.2.3' => [
        'core_compatibility' => '^8.9 || ^9',
        'core_compatible' => FALSE,
        'core_compatibility_message' => 'Requires Drupal core: 8.9.0 to 8.9.2',
      ],
      '1.2.4' => [
        'core_compatibility' => '^8.9.2 || ^9',
        'core_compatible' => FALSE,
        'core_compatibility_message' => 'Requires Drupal core: 8.9.2',
      ],
      '1.2.6' => [],
    ];
    $test_cases['no 9 releases']['expected_security_updates'] = [
      '1.2.5' => [
        'core_compatibility' => '8.9.0 || 8.9.2 || ^9.0.1',
        'core_compatible' => FALSE,
        'core_compatibility_message' => 'Requires Drupal core: 8.9.0, 8.9.2',
      ],
    ];
    // Ensure that when only Drupal 9 pre-releases none of the expected ranges
    // change.
    $test_cases['with 9 pre releases'] = $test_cases['no 9 releases'];
    $test_cases['with 9 pre releases']['core_releases'] += [
      '9.0.0-alpha1' => [],
      '9.0.0-beta1' => [],
      '9.0.0-rc1' => [],
    ];
    // Ensure that when the Drupal 9 full releases are added but they are not
    // supported none of the expected ranges change.
    $test_cases['with 9 full releases, not supported'] = $test_cases['with 9 pre releases'];
    $test_cases['with 9 full releases, not supported']['core_releases'] += [
      '9.0.0' => [],
      '9.0.1' => [],
      '9.0.2' => [],
    ];
    // Ensure that when the Drupal 9 full releases are supported the expected
    // ranges do change.
    $test_cases['with 9 full releases, supported'] = $test_cases['with 9 full releases, not supported'];
    $test_cases['with 9 full releases, supported']['supported_branches'][] = '9.0.';
    $test_cases['with 9 full releases, supported']['expected_releases'] = [
      '1.0.1' => [
        'core_compatibility' => '8.x',
        'core_compatible' => TRUE,
        'core_compatibility_message' => 'Requires Drupal core: 8.8.0 to 8.9.2',
      ],
      '1.2.3' => [
        'core_compatibility' => '^8.9 || ^9',
        'core_compatible' => FALSE,
        'core_compatibility_message' => 'Requires Drupal core: 8.9.0 to 9.0.2',
      ],
      '1.2.4' => [
        'core_compatibility' => '^8.9.2 || ^9',
        'core_compatible' => FALSE,
        'core_compatibility_message' => 'Requires Drupal core: 8.9.2 to 9.0.2',
      ],
      '1.2.6' => [],
    ];
    $test_cases['with 9 full releases, supported']['expected_security_updates'] = [
      '1.2.5' => [
        'core_compatibility' => '8.9.0 || 8.9.2 || ^9.0.1',
        'core_compatible' => FALSE,
        'core_compatibility_message' => 'Requires Drupal core: 8.9.0, 8.9.2, 9.0.1 to 9.0.2',
      ],
    ];
    return $test_cases;
  }
  
  /**
   * @covers ::isCoreCompatible
   * @dataProvider providerIsCoreCompatible
   *
   * @param string $constraint
   *   The core_version_constraint to test.
   * @param string $installed_core
   *   The installed version of core to compare against.
   * @param bool $expected
   *   The expected result.
   */
  public function testIsCoreCompatible(string $constraint, string $installed_core, bool $expected) : void {
    $core_data['existing_version'] = $installed_core;
    $project_compatibility = new ProjectCoreCompatibility($core_data, [], []);
    $reflection = new \ReflectionClass(ProjectCoreCompatibility::class);
    $reflection_method = $reflection->getMethod('isCoreCompatible');
    $result = $reflection_method->invokeArgs($project_compatibility, [
      $constraint,
    ]);
    $this->assertSame($expected, $result);
  }
  
  /**
   * Data provider for testIsCoreCompatible().
   */
  public static function providerIsCoreCompatible() : array {
    $test_cases['compatible exact'] = [
      '10.3.0',
      '10.3.0',
      TRUE,
    ];
    $test_cases['compatible with OR'] = [
      '^9 || ^10',
      '10.3.0',
      TRUE,
    ];
    $test_cases['incompatible'] = [
      '^10',
      '11.0.0',
      FALSE,
    ];
    $test_cases['broken'] = [
      '^^11',
      '11.0.0',
      FALSE,
    ];
    return $test_cases;
  }
}Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides | 
|---|---|---|---|---|---|
| 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. | ||
| ProjectCoreCompatibilityTest::providerIsCoreCompatible | public static | function | Data provider for testIsCoreCompatible(). | ||
| ProjectCoreCompatibilityTest::providerSetProjectCoreCompatibilityRanges | public static | function | Data provider for testSetProjectCoreCompatibilityRanges(). | ||
| ProjectCoreCompatibilityTest::testIsCoreCompatible | public | function | @covers ::isCoreCompatible[[api-linebreak]] @dataProvider providerIsCoreCompatible | ||
| ProjectCoreCompatibilityTest::testSetProjectCoreCompatibilityRanges | public | function | @covers ::setReleaseMessage[[api-linebreak]] @dataProvider providerSetProjectCoreCompatibilityRanges | ||
| 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. | ||
| RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | |
| UnitTestCase::$root | protected | property | The app root. | 1 | |
| 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 | 357 | ||
| UnitTestCase::setUpBeforeClass | public static | function | |||
| UnitTestCase::__get | public | function | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
