Issue #3280589 by Spokje, longwave, Mile23: Deprecate Composer Vendor Cleanup Scripts

merge-requests/2612/head
catch 2022-06-27 21:51:00 +01:00
parent 3b4a427fe1
commit a9c1a68112
4 changed files with 107 additions and 4 deletions

View File

@ -227,9 +227,6 @@
}
},
"scripts": {
"pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
"post-autoload-dump": [
"Drupal\\Core\\Composer\\Composer::ensureHtaccess"
]
"pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump"
}
}

View File

@ -154,8 +154,15 @@ class Composer {
*
* @param \Composer\Script\Event $event
* The event.
*
* @deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. Any
* "scripts" section mentioning this in composer.json can be removed and
* replaced with the drupal/core-vendor-hardening Composer plugin, as needed.
*
* @see https://www.drupal.org/node/3260624
*/
public static function ensureHtaccess(Event $event) {
trigger_error('Calling ' . __METHOD__ . ' from composer.json is deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. Any "scripts" section mentioning this in composer.json can be removed and replaced with the drupal/core-vendor-hardening Composer plugin, as needed. See https://www.drupal.org/node/3260624', E_USER_DEPRECATED);
// The current working directory for composer scripts is where you run
// composer from.
@ -174,8 +181,16 @@ class Composer {
* @param \Composer\Installer\PackageEvent $event
* A PackageEvent object to get the configured composer vendor directories
* from.
*
* @deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. Any
* "scripts" section mentioning this in composer.json can be removed and
* replaced with the drupal/core-vendor-hardening Composer plugin, as needed.
*
* @see https://www.drupal.org/node/3260624
*/
public static function vendorTestCodeCleanup(PackageEvent $event) {
trigger_error('Calling ' . __METHOD__ . ' from composer.json is deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. Any "scripts" section mentioning this in composer.json can be removed and replaced with the drupal/core-vendor-hardening Composer plugin, as needed. See https://www.drupal.org/node/3260624', E_USER_DEPRECATED);
$vendor_dir = $event->getComposer()->getConfig()->get('vendor-dir');
$io = $event->getIO();
$op = $event->getOperation();
@ -231,6 +246,8 @@ class Composer {
*
* @return string|null
* The string key, or NULL if none was found.
*
* @internal
*/
protected static function findPackageKey($package_name) {
$package_key = NULL;
@ -254,8 +271,15 @@ class Composer {
/**
* Removes Composer's timeout so that scripts can run indefinitely.
*
* @deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. There is no
* replacement.
*
* @see https://www.drupal.org/node/3260624
*/
public static function removeTimeout() {
trigger_error('Calling ' . __METHOD__ . ' from composer.json is deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. There is no replacement. See https://www.drupal.org/node/3260624', E_USER_DEPRECATED);
ProcessExecutor::setTimeout(0);
}
@ -267,6 +291,8 @@ class Composer {
*
* @return bool
* TRUE on success or FALSE on failure.
*
* @internal
*/
protected static function deleteRecursive($path) {
if (is_file($path) || is_link($path)) {
@ -291,6 +317,8 @@ class Composer {
*
* @param \Composer\Script\Event $event
* The event.
*
* @internal
*/
public static function upgradePHPUnit(Event $event) {
$repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
@ -324,6 +352,8 @@ class Composer {
*
* @return bool
* TRUE if the PHPUnit needs to be upgraded, FALSE if not.
*
* @internal
*/
public static function upgradePHPUnitCheck($phpunit_version) {
return !(version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, '7.4') >= 0 && version_compare($phpunit_version, '9.0') < 0);

View File

@ -8,6 +8,7 @@ use Drupal\Composer\Composer;
/**
* @group Composer
* @group legacy
* @requires externalCommand composer
* @coversDefaultClass \Drupal\Core\Composer\Composer
*/

View File

@ -0,0 +1,75 @@
<?php
namespace Drupal\Tests\Core\Composer;
use Composer\Config;
use Composer\Composer as ComposerClass;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\Installer\PackageEvent;
use Composer\IO\IOInterface;
use Composer\Package\Package;
use Composer\Script\Event;
use Drupal\Core\Composer\Composer;
use Drupal\Tests\UnitTestCase;
/**
* Tests the deprecations in the Drupal\Core\Composer\Composer class.
*
* @group Composer
* @coversDefaultClass \Drupal\Core\Composer\Composer
*/
class ComposerDeprecationTest extends UnitTestCase {
/**
* @covers ::ensureHtaccess
* @group legacy
*/
public function testEnsureHtaccess() {
$event = $this->prophesize(Event::class);
$composer = $this->prophesize(ComposerClass::class);
$event->getComposer()->willReturn($composer->reveal());
$config = $this->prophesize(Config::class);
$composer->getConfig()->willReturn($config->reveal());
$this->expectDeprecation('Unsilenced deprecation: Calling Drupal\Core\Composer\Composer::ensureHtaccess from composer.json is deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. Any "scripts" section mentioning this in composer.json can be removed and replaced with the drupal/core-vendor-hardening Composer plugin, as needed. See https://www.drupal.org/node/3260624');
Composer::ensureHtaccess($event->reveal());
}
/**
* @covers ::vendorTestCodeCleanup
* @group legacy
*/
public function testVendorTestCodeCleanup() {
$event = $this->prophesize(PackageEvent::class);
$composer = $this->prophesize(ComposerClass::class);
$event->getComposer()->willReturn($composer->reveal());
$config = $this->prophesize(Config::class);
$composer->getConfig()->willReturn($config->reveal());
$operation = $this->prophesize(UpdateOperation::class);
$event->getOperation()->willReturn($operation->reveal());
$package = $this->prophesize(Package::class);
$operation->getTargetPackage()->willReturn($package->reveal());
$io = $this->prophesize(IOInterface::class);
$event->getIO()->willReturn($io->reveal());
$this->expectDeprecation('Unsilenced deprecation: Calling Drupal\Core\Composer\Composer::vendorTestCodeCleanup from composer.json is deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. Any "scripts" section mentioning this in composer.json can be removed and replaced with the drupal/core-vendor-hardening Composer plugin, as needed. See https://www.drupal.org/node/3260624');
Composer::vendorTestCodeCleanup($event->reveal());
}
/**
* @covers ::removeTimeout
* @group legacy
*/
public function testRemoveTimeout() {
$this->expectDeprecation('Unsilenced deprecation: Calling Drupal\Core\Composer\Composer::removeTimeout from composer.json is deprecated in drupal:9.5.0 and is removed from drupal:10.0.0. There is no replacement. See https://www.drupal.org/node/3260624');
Composer::removeTimeout();
}
}