簡體   English   中英

作曲者-[UnexpectedValueException]無法解析版本約束README.md:無效的版本字符串“ README.md”

[英]composer - [UnexpectedValueException] Could not parse version constraint README.md: Invalid version string “README.md”

我正在嘗試開始使用PHPunit。 我使用composer init命令創建了一個新的composer.json文件。 看起來像這樣:

{
    "name": "connor11528/stitch-labs-woo-shipment-sync",
    "authors": [
        {
            "name": "Connor Leech",
            "email": "connor@stitchlabs.com"
        }
    ],
    "require": {}
}

當我嘗試安裝PHPunit軟件包時,出現錯誤:

[UnexpectedValueException]                                                        
  Could not parse version constraint README.md: Invalid version string "README.md" 

我正在按照PHPunit入門( 此處 )中概述的說明安裝軟件包:

$ php -v
$ PHP 7.1.13 (cli) (built: Jan  5 2018 15:31:15) ( NTS )
$ composer self-update
$ composer require --dev phpunit/phpunit ^7

我的文件結構是:

- my-file.php
- composer.json
- README.md

如何克服此錯誤並安裝PHPunit軟件包?

看來您的Shell(可能是zsh)將^7理解為命令。 我建議您用引號將命令包裝起來 喜歡:

$ composer require --dev 'phpunit/phpunit ^7'

我只是想重現您的問題,沒有問題。

首先,我的Dockerfile用於測試:

FROM php:7.1-cli

# Installing prerequisites
RUN apt-get update && apt-get install -y nano zip git

# Installing composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php && rm composer-setup.php

# Creating test directory for sample project
RUN mkdir test
WORKDIR test

# Adding files like in your example
RUN touch composer.json && touch my-file.php && touch README.md

# Adding composer.json content
RUN echo '\n\
{\n\
    "name": "connor11528/stitch-labs-woo-shipment-sync",\n\
    "authors": [\n\
        {\n\
            "name": "Connor Leech",\n\
            "email": "connor@stitchlabs.com"\n\
        }\n\
    ],\n\
    "require": {}\n\
}\n'\
>> composer.json

RUN cat composer.json

# Running composer update/require
RUN /composer.phar self-update && /composer.phar require --dev phpunit/phpunit ^7
RUN ls -al

# Looking for installed packages
CMD ["/composer.phar", "show", "-i"]

然后,構建此映像並運行它:

ivkalita@localhost $ docker build .
Sending build context to Docker daemon   2.56kB
Step 1/11 : FROM php:7.1-cli
 ---> 07ee18085f34
Step 2/11 : RUN apt-get update && apt-get install -y nano zip git
 ...
Step 3/11 : RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php && rm composer-setup.php
...
Composer (version 1.6.3) successfully installed to: //composer.phar
Use it: php composer.phar
Step 4/11 : RUN mkdir test
...
Step 5/11 : WORKDIR test
...
Step 6/11 : RUN touch composer.json && touch my-file.php && touch README.md
 ...
Step 7/11 : RUN echo '\n{\n    "name": "connor11528/stitch-labs-woo-shipment-sync",\n    "authors": [\n        {\n            "name": "Connor Leech",\n            "email": "connor@stitchlabs.com"\n        }\n    ],\n    "require": {}\n}\n'>> composer.json
...
Step 8/11 : RUN cat composer.json
{
    "name": "connor11528/stitch-labs-woo-shipment-sync",
    "authors": [
        {
            "name": "Connor Leech",
            "email": "connor@stitchlabs.com"
        }
    ],
    "require": {}
}
Step 9/11 : RUN /composer.phar self-update && /composer.phar require --dev phpunit/phpunit ^7
 ---> Running in fce698c0ebc1
You are already using composer version 1.6.3 (stable channel).
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 28 installs, 0 updates, 0 removals
  - Installing sebastian/version (2.0.1): Downloading (100%)
  - Installing sebastian/resource-operations (1.0.0): Downloading (100%)
  - Installing sebastian/recursion-context (3.0.0): Downloading (100%)
  - Installing sebastian/object-reflector (1.1.1): Downloading (100%)
  - Installing sebastian/object-enumerator (3.0.3): Downloading (100%)
  - Installing sebastian/global-state (2.0.0): Downloading (100%)
  - Installing sebastian/exporter (3.1.0): Downloading (100%)
  - Installing sebastian/environment (3.1.0): Downloading (100%)
  - Installing sebastian/diff (3.0.0): Downloading (100%)
  - Installing sebastian/comparator (2.1.3): Downloading (100%)
  - Installing doctrine/instantiator (1.1.0): Downloading (100%)
  - Installing phpunit/php-text-template (1.2.1): Downloading (100%)
  - Installing phpunit/phpunit-mock-objects (6.0.1): Downloading (100%)
  - Installing phpunit/php-timer (2.0.0): Downloading (100%)
  - Installing phpunit/php-file-iterator (1.4.5): Downloading (100%)
  - Installing theseer/tokenizer (1.1.0): Downloading (100%)
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Downloading (100%)
  - Installing phpunit/php-token-stream (3.0.0): Downloading (100%)
  - Installing phpunit/php-code-coverage (6.0.1): Downloading (100%)
  - Installing webmozart/assert (1.3.0): Downloading (100%)
  - Installing phpdocumentor/reflection-common (1.0.1): Downloading (100%)
  - Installing phpdocumentor/type-resolver (0.4.0): Downloading (100%)
  - Installing phpdocumentor/reflection-docblock (4.3.0): Downloading (100%)
  - Installing phpspec/prophecy (1.7.5): Downloading (100%)
  - Installing phar-io/version (1.0.1): Downloading (100%)
  - Installing phar-io/manifest (1.0.1): Downloading (100%)
  - Installing myclabs/deep-copy (1.7.0): Downloading (100%)
  - Installing phpunit/phpunit (7.0.2): Downloading (100%)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.6.0)
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)
phpunit/phpunit suggests installing ext-xdebug (*)
Writing lock file
Generating autoload files
 ---> cfec9fc34a03
Removing intermediate container fce698c0ebc1
Step 10/11 : RUN ls -al
 ---> Running in dd8a9df7a1fe
total 68
drwxr-xr-x  1 root root  4096 Mar  1 21:07 .
drwxr-xr-x  1 root root  4096 Mar  1 21:08 ..
-rw-r--r--  1 root root     0 Mar  1 21:06 README.md
-rw-r--r--  1 root root   264 Mar  1 21:07 composer.json
-rw-r--r--  1 root root 51871 Mar  1 21:07 composer.lock
-rw-r--r--  1 root root     0 Mar  1 21:06 my-file.php
drwxr-xr-x 13 root root  4096 Mar  1 21:07 vendor
 ---> 99a0d8b44662
Removing intermediate container dd8a9df7a1fe
Step 11/11 : CMD /composer.phar show -i
 ---> Running in f50592b9f772
 ---> c59d4c1beca4
Removing intermediate container f50592b9f772
Successfully built c59d4c1beca4


ivkalita@localhost $ docker run c59d4c1beca4
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
...
phpunit/php-code-coverage          6.0.1 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator          1.4.5 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template          1.2.1 Simple template engine.
phpunit/php-timer                  2.0.0 Utility class for timing
phpunit/php-token-stream           3.0.0 Wrapper around PHP's tokenizer extension.
phpunit/phpunit                    7.0.2 The PHP Unit Testing framework.
phpunit/phpunit-mock-objects       6.0.1 Mock Object library for PHPUnit

請確保使用與問題中描述的命令相同的命令以及相同的composer.json

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM