Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/Composer/Composer.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Composer/Composer.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/lib/Drupal/Core/Composer/Composer.php Mon Apr 23 09:46:53 2018 +0100 @@ -144,6 +144,48 @@ } /** + * Fires the drupal-phpunit-upgrade script event if necessary. + * + * @param \Composer\Script\Event $event + */ + 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.2 or above and PHPUnit is less than version 6 + // call the drupal-phpunit-upgrade script to upgrade PHPUnit. + if (!static::upgradePHPUnitCheck($phpunit_package->getVersion())) { + $event->getComposer() + ->getEventDispatcher() + ->dispatchScript('drupal-phpunit-upgrade'); + } + } + + /** + * Determines if PHPUnit needs to be upgraded. + * + * This method is located in this file because it is possible that it is + * called before the autoloader is available. + * + * @param string $phpunit_version + * The PHPUnit version string. + * + * @return bool + * TRUE if the PHPUnit needs to be upgraded, FALSE if not. + */ + public static function upgradePHPUnitCheck($phpunit_version) { + return !(version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, '7.2') >= 0 && version_compare($phpunit_version, '6.1') < 0); + } + + /** * Remove possibly problematic test files from vendored projects. * * @param \Composer\Installer\PackageEvent $event