作曲家 - [意外值异常] 无法分析版本约束 README.md:版本字符串"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相同。

相关内容

  • 没有找到相关文章

最新更新