Commit e22bcf1f authored by catch's avatar catch
Browse files

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

(cherry picked from commit a9c1a681)
parent 9d6aed91
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -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"
    }
}
+30 −0
Original line number Diff line number Diff line
@@ -154,8 +154,15 @@ public static function preAutoloadDump(Event $event) {
   *
   * @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 @@ public static function ensureHtaccess(Event $event) {
   * @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 @@ public static function vendorTestCodeCleanup(PackageEvent $event) {
   *
   * @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 @@ protected static function findPackageKey($package_name) {

  /**
   * 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 @@ public static function removeTimeout() {
   *
   * @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 @@ protected static function deleteRecursive($path) {
   *
   * @param \Composer\Script\Event $event
   *   The event.
   *
   * @internal
   */
  public static function upgradePHPUnit(Event $event) {
    $repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
@@ -324,6 +352,8 @@ public static function upgradePHPUnit(Event $event) {
   *
   * @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);
+1 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

/**
 * @group Composer
 * @group legacy
 * @requires externalCommand composer
 * @coversDefaultClass \Drupal\Core\Composer\Composer
 */
+75 −0
Original line number Diff line number Diff line
<?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();
  }

}