gpt4 book ai didi

php - Composer 更新未在 Laravel 中安装 PHPUnit?

转载 作者:行者123 更新时间:2023-12-02 21:56:19 25 4
gpt4 key购买 nike

我正在尝试安装PHPUnit进入Laravel框架通过 Composer

问题是运行composer update后没有下载所需的文件。

我的流程如下所示:

首先,我在 composer.json 中插入 PHPUnit 要求。整个文件如下所示:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"laravelbook/ardent": "dev-master",
"phpunit/phpunit": "4.2.*" // i have also tried with 3.7 and 3.8
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/filters"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable",
"require": {
"laravelbook/ardent": "dev-master"
}

}

接下来,我运行 composer update -vvv。转储看起来像这样(额外的奇怪之处:这是从命令提示符复制的,如果我执行相同的命令但尝试使用 > 命令将其写入 txt 文件,则过程会在 Downloading https:///packagist.org/packages.json 行)

C:\wamp\www\Dropbox\ltest>composer update -vvv
Reading ./composer.json
Executing command (CWD): git describe --exact-match --tags
Executing command (CWD): git branch --no-color --no-abbrev -v
Loading composer repositories with package information
Downloading https://packagist.org/packages.json
Writing C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/packages
.json into cache
Updating dependencies (including require-dev)
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/p-provid
er-active.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/p-provid
er-archived.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/p-provid
er-latest.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/p-provid
er-stale.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-laravelbook$ardent.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-laravel$laravel.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-psr$log.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$http-foundation.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$http-kernel.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-stack$builder.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$event-dispatcher.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$debug.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-predis$predis.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-phpseclib$phpseclib.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-nesbot$carbon.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-monolog$monolog.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-nikic$php-parser.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-jeremeamia$superclosure.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-jeremeamia$functionparser.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-ircmaxell$password-compat.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-filp$whoops.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-d11wtq$boris.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$console.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$filesystem.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$finder.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-classpreloader$classpreloader.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-patchwork$utf8.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-swiftmailer$swiftmailer.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$browser-kit.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$css-selector.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$dom-crawler.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$process.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$routing.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$security.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$translation.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-laravel$framework.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-doctrine$dbal.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-doctrine$common.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-doctrine$inflector.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-doctrine$cache.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-doctrine$collections.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-doctrine$lexer.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-doctrine$annotations.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$support.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$database.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$validation.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$container.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$events.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$auth.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$cache.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$config.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$console.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$cookie.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$encryption.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$exception.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$filesystem.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$foundation.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$hashing.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$html.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$http.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$log.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$mail.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$pagination.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$queue.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$redis.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$routing.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$session.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$translation.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$view.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-illuminate$workbench.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$security-acl.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$security-core.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$security-csrf.json from cache
Reading C:/Users/aske/AppData/Local/Composer/repo/https---packagist.org/provider
-symfony$security-http.json from cache
Nothing to install or update
Reading ./composer.lock
Generating autoload files
Executing command (CWD): php artisan clear-compiled
Executing command (CWD): php artisan optimize
Generating optimized class loader

最终所需的文件没有添加到 vendor/bin/ 中。据我所知,此时应该已经放置了一个名为 phpunit.php 的文件,但没有任何迹象。

Here is my composer.lock作为奖励信息,运行更新后没有任何 phpunit 的迹象。

最佳答案

添加PHPUnit失败的原因是你的composer.json中有两个名为“require”的键,这是非法的。最后一个实例会覆盖第一个实例 - 这会覆盖添加的 PHPUnit 要求。

只有将其更改为“require-dev”(这是一个不同的键)后,Composer 才能检测到您需要 PHPUnit。

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"laravelbook/ardent": "dev-master",
"phpunit/phpunit": "4.2.*" // i have also tried with 3.7 and 3.8
},

// deleted lines here...

"minimum-stability": "stable",
"require": {
"laravelbook/ardent": "dev-master"
}

}

看到“require”作为 JSON 中最后一个缩进严重的键了吗?这至少会让 Composer 感到困惑。我很确定“laravelbook/ardent”依赖于“laravel/framework”和大量其他内容,因此您没有看到您的第一个 require 键被覆盖。

建议:始终使用命令行添加内容 - 这更容易,而且您不必注意正确的 JSON 格式:

composer require --dev phpunit/phpunit:~4.0

这会将依赖项添加到composer.json文件中,如果没有冲突,则立即下载它。它还将编写一个新的、格式清晰的composer.json 文件。如果 Composer 有机会删除双键,您就会很快发现错误。

关于php - Composer 更新未在 Laravel 中安装 PHPUnit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23594970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com