1

我读到 PHPUnit 可以用 pear 或 composer 安装。因为我在一个带有 WAMPSERVER 和一个用于控制台内容的 cygwin 的 Windows 上并且没有安装 pear,所以我通过 composer 安装了 PHPUnit。而且特别是因为symfony2.1你必须使用composer,所以我选择了这个方法

我将它添加到我的 composer.json

"require-dev": {
    "phpunit/phpunit": "3.7.*"
},

然后做一个

php composer.phar install --dev

//Update1(感谢拆解者)

bin 文件(phpunit 和 phpunit.bat)被复制或链接到应用程序的 bin 目录。但是当我打电话时,bin/phpunit -c app/ 我得到了这个错误:

Fatal error: Cannot redeclare assetic_init() (previously declared in C:\wamp_\www\symfony2.1\vendor\kriswallsmith\assetic\src\functions.php:20) in C:\wamp_\www\symfony2.1\vendor\kriswallsmith\assetic\src\functions.php on line 26

Call Stack:
    0.0005     128056   1. {main}() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\composer\bin\phpunit:0
    0.0095     433520   2. PHPUnit_TextUI_Command::main() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\composer\bin\phpunit:42
    0.0096     436736   3. PHPUnit_TextUI_Command->run() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\TextUI\Command.php:130
    0.0096     436952   4. PHPUnit_TextUI_Command->handleArguments() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\TextUI\Command.php:139
    0.0144     683168   5. PHPUnit_TextUI_Command->handleBootstrap() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\TextUI\Command.php:615
    0.0148     689328   6. PHPUnit_Util_Fileloader::checkAndLoad() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\TextUI\Command.php:787
    0.0152     689448   7. PHPUnit_Util_Fileloader::load() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\Util\Fileloader.php:77
    0.0200    1013688   8. include_once('C:\wamp_\www\symfony2.1\app\bootstrap.php.cache') C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\Util\Fileloader.php:93
    0.0202    1016424   9. require_once('C:\wamp_\www\symfony2.1\app\autoload.php') C:\wamp_\www\symfony2.1\app\bootstrap.php.cache:3
    0.0204    1017424  10. require('C:\wamp_\www\symfony2.1\vendor\autoload.php') C:\wamp_\www\symfony2.1\app\autoload.php:5
    0.0205    1017440  11. ComposerAutoloaderInit::getLoader() C:\wamp_\www\symfony2.1\vendor\autoload.php:7

PHP Fatal error:  Cannot redeclare assetic_init() (previously declared in C:\wamp_\www\symfony2.1\vendor\kriswallsmith\assetic\src\functions.php:20) in C:\wamp_\www\symfony2.1\vendor\kriswallsmith\assetic\src\functions.php on line 26
PHP Stack trace:
PHP   1. {main}() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\composer\bin\phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\composer\bin\phpunit:42
PHP   3. PHPUnit_TextUI_Command->run() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\TextUI\Command.php:130
PHP   4. PHPUnit_TextUI_Command->handleArguments() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\TextUI\Command.php:139
PHP   5. PHPUnit_TextUI_Command->handleBootstrap() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\TextUI\Command.php:615
PHP   6. PHPUnit_Util_Fileloader::checkAndLoad() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\TextUI\Command.php:787
PHP   7. PHPUnit_Util_Fileloader::load() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\Util\Fileloader.php:77
PHP   8. include_once() C:\wamp_\www\symfony2.1\vendor\phpunit\phpunit\PHPUnit\Util\Fileloader.php:93
PHP   9. require_once() C:\wamp_\www\symfony2.1\app\bootstrap.php.cache:3
PHP  10. require() C:\wamp_\www\symfony2.1\app\autoload.php:5
PHP  11. ComposerAutoloaderInit::getLoader() C:\wamp_\www\symfony2.1\vendor\autoload.php:7

为什么会执行这个,我没有定义在这个目录中搜索测试。我尝试删除发生错误的文件,但随后出现类似错误:cannot redeclare另一个类/函数的错误。所以看起来源被加载了两次。

//Update2 phpunit.xml.dist是我安装symfony的时候生成的,我没有修改。

<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
    backupGlobals               = "false"
    backupStaticAttributes      = "false"
    colors                      = "true"
    convertErrorsToExceptions   = "true"
    convertNoticesToExceptions  = "true"
    convertWarningsToExceptions = "true"
    processIsolation            = "false"
    stopOnFailure               = "false"
    syntaxCheck                 = "false"
    bootstrap                   = "bootstrap.php.cache" >

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>../src/*/*Bundle/Tests</directory>
            <directory>../src/*/Bundle/*Bundle/Tests</directory>
        </testsuite>
    </testsuites>

    <!--
    <php>
        <server name="KERNEL_DIR" value="/path/to/your/app/" />
    </php>
    -->

    <filter>
        <whitelist>
            <directory>../src</directory>
            <exclude>
                <directory>../src/*/*Bundle/Resources</directory>
                <directory>../src/*/*Bundle/Tests</directory>
                <directory>../src/*/Bundle/*Bundle/Resources</directory>
                <directory>../src/*/Bundle/*Bundle/Tests</directory>
            </exclude>
        </whitelist>
    </filter>

</phpunit>

当我删除测试套件和过滤器块时,错误仍然存​​在。

4

1 回答 1

1

我刚刚尝试过,并在我的项目bin目录中创建了一个符号链接。所以我能够使用bin/phpunit.

于 2012-09-20T15:05:08.033 回答