You are here

public static function Composer::upgradePHPUnit in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Composer/Composer.php \Drupal\Core\Composer\Composer::upgradePHPUnit()

Fires the drupal-phpunit-upgrade script event if necessary.

Parameters

\Composer\Script\Event $event:

File

core/lib/Drupal/Core/Composer/Composer.php, line 282

Class

Composer
Provides static functions for composer script events.

Namespace

Drupal\Core\Composer

Code

public static function upgradePHPUnit(Event $event) {
  $repository = $event
    ->getComposer()
    ->getRepositoryManager()
    ->getLocalRepository();

  // This is, essentially, a null constraint. We only care whether the package
  // is present in the vendor directory yet, but findPackage() requires it.
  $constraint = new Constraint('>', '');
  $phpunit_package = $repository
    ->findPackage('phpunit/phpunit', $constraint);
  if (!$phpunit_package) {

    // There is nothing to do. The user is probably installing using the
    // --no-dev flag.
    return;
  }

  // If the PHP version is 7.3 or above and PHPUnit is less than version 7
  // call the drupal-phpunit-upgrade script to upgrade PHPUnit.
  if (!static::upgradePHPUnitCheck($phpunit_package
    ->getVersion())) {
    $event
      ->getComposer()
      ->getEventDispatcher()
      ->dispatchScript('drupal-phpunit-upgrade');
  }
}