【问题标题】:Composer errors on installing phpunit/phpunit because of overriding MAXPATHLENGTH由于覆盖 MAXPATHLENGTH,在安装 phpunit/phpunit 时出现 Composer 错误
【发布时间】:2017-05-27 17:57:19
【问题描述】:

我有一个 PHP 项目,其文件夹结构如下:

C:\Users\Bas\Documents\Web_development\Projects\Back_end\Current\Project_name\Workspace

我已经为这个项目安装了 composer,并且已经安装了一些包。我的 composer.json 看起来像这样:

{
  "name": "Bas/Project_name",
  "description": "...",
  "minimum-stability": "stable",
  "license": "MIT",
  "authors": [
    {
      "name": "Bas",
      "email": "..."
    }
  ],
  "require": {
    "psr/log": "1.0.2",
    "monolog/monolog": "1.22.0",
    "ip2location/ip2location-php": "8.0.2"
  }
}

当我尝试安装 phpunit/phpunit 版本 5.7.x(最新)软件包时,它给了我 [ErrorException] ZipArchive::extractTo(): Full extraction path exceed MAXPATHLEN (260) 错误。完整的错误消息如下所示:

You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug

Using version ^5.7 for phpunit/phpunit
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing symfony/yaml (v3.2.1)
    Loading from cache

  - Installing sebastian/version (2.0.1)
    Loading from cache

  - Installing sebastian/resource-operations (1.0.0)
    Loading from cache

  - Installing sebastian/recursion-context (2.0.0)
    Loading from cache

  - Installing sebastian/object-enumerator (2.0.0)
    Loading from cache

  - Installing sebastian/global-state (1.1.1)
    Loading from cache

  - Installing sebastian/exporter (2.0.0)
    Loading from cache

  - Installing sebastian/environment (2.0.0)
    Loading from cache

  - Installing sebastian/diff (1.4.1)
    Loading from cache

  - Installing sebastian/comparator (1.2.2)
    Loading from cache

  - Installing doctrine/instantiator (1.0.5)
    Loading from cache

  - Installing phpunit/php-text-template (1.2.1)
    Loading from cache

  - Installing phpunit/phpunit-mock-objects (3.4.3)
    Downloading: 100%

Installation failed, reverting ./composer.json to its original content.


  [ErrorException]                                                       
  ZipArchive::extractTo(): Full extraction path exceed MAXPATHLEN (260)  


require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-autho
ritative] [--] [<packages>]...

我正在使用composer require phpunit/phpunit 命令安装包。

我对这个问题做了一些研究,这是由于目录结构过长造成的,但是当计算我当前的目录结构时,它只有87个字符。

我尝试使用--prefer-source 参数运行composer installcomposer update 命令。这两个都不起作用,给了我同样的错误。

我目前正在运行 Windows 10 64 位。

这个问题是怎么发生的?因为我在MAXPATHLEN (260) 变量下有一个目录结构。

有什么方法可以在不改变我的目录结构的情况下解决这个问题?

【问题讨论】:

    标签: php phpunit composer-php


    【解决方案1】:

    你的路很长。是否过长取决于你项目中目录结构的深度。

    请记住,使用 Composer 会创建子文件夹。至少您将创建vendor/phpunit/phpunit(22 个字符),以及在此之上的所有 PHPUnit 本身的子文件夹。我以这条路径为例:src/Framework/Constraint/JsonMatches/ErrorMessageProvider.php(另外 62 个字符)。

    添加更多目录分隔符,我们至少有 87 + 22 + 2 + 62 = 173 个字符长。这比您想象的要接近最大值 260。

    解压模拟对象组件时会出现您的问题。我发现了这条有趣的路径:tests/MockObject/Generator/namespaced_class_implementing_interface_dont_call_parent_constructor.phpt - 101 个字符。结合供应商文件夹vendor/phpunit/phpunit-mock-objects(36 个字符)和另外两个目录分隔符,我们达到 87 + 36 + 2 + 101 = 226 个字符 - 越来越接近最大值。现在您只需要另外 34 个来自任何地方的字符,也许在解压过程中创建了一个临时文件名,而您已经达到了限制。

    缩短您现有的路径,它会起作用。

    【讨论】:

    • 只有Windows有这个问题吗?我需要更长的目录路径,因为我要处理很多文件。
    猜你喜欢
    • 2014-04-21
    • 2013-09-12
    • 2017-11-10
    • 2011-09-29
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    • 1970-01-01
    相关资源
    最近更新 更多