Composer更新不会在Laravel中安装PHPUnit?

时间:2014-05-11 16:16:15

标签: php json laravel-4 phpunit composer-php

我正在尝试通过PHPUnitLaravel安装到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。转储看起来像这样(Bonus Weirdness:这是从命令提示符复制的,如果我执行相同的命令但尝试使用>命令将其写入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的迹象。

2 个答案:

答案 0 :(得分:6)

添加PHPUnit失败的原因是因为你有两个名为" require"在你的composer.json中,这是非法的。最后一个实例覆盖第一个实例 - 它覆盖了添加的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"
        }

}

看到提及"要求"作为JSON中最后一个非常缩进的键?这至少会让Composer感到困惑。我很确定" laravelbook / ardent"依赖于" laravel / framework"还有很多额外的东西,所以你没有看到你的第一个要求密钥被覆盖了。

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

composer require --dev phpunit/phpunit:~4.0

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

答案 1 :(得分:2)

因为我的评论表明phpunit应该在require-dev中不需要,并尝试使用版本4.1。*这是稳定的,而不是4.2,因为它是alpha版本。正如他在评论中提到的那样低调:

  

require和require dev之间的差异不仅仅是在路上   作曲家处理它们。某些依赖项需要下载   require-dev(当然他们应该这样做)。作为一个简短的旁注:我   必须运行"作曲家更新--dev -vvv"在它经过之前三次   没有挂在某处的过程。似乎作曲家可以成为一个   下载一些时候有点不稳定

所以直接的答案是:phpunit应该包含在require-dev not require中,并且最好安装稳定版本而不是beta。