简体   繁体   English

适用于symfony2.1的PHPUnit-无法重新声明xyz()

[英]PHPUnit for symfony2.1 - cannot redeclare xyz()

I read that PHPUnit can be installed with pear or with composer. 我读到PHPUnit可以与pear或composer一起安装。 Because I'm on a windows with WAMPSERVER and a cygwin for console stuff and there is no pear installed, I installed PHPUnit via composer. 因为我在装有WAMPSERVER和cygwin的Windows上用于控制台,并且没有安装pear,所以我通过composer安装了PHPUnit。 And especially since symfony2.1 you must use composer, so I choose this method . 特别是由于symfony2.1必须使用composer,因此我选择了这种方法

I add this into my composer.json 我将其添加到我的composer.json

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

And then do a 然后做一个

php composer.phar install --dev

//Update1 (thanks to theunraveler) // Update1(感谢theunraveler)

The bin files (phpunit and phpunit.bat) are copied or linked to the bin directory of the app. 将bin文件(phpunit和phpunit.bat)复制或链接到应用程序的bin目录。 But when I call bin/phpunit -c app/ I get this error: 但是当我调用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

Why this will be executed, I don't define to search for tests in this directory. 为什么执行此操作,但我没有定义要在此目录中搜索测试。 I try to remove the file where the error occurs, but then I get a similar error: cannot redeclare error for another class/function. 我尝试删除发生错误的文件,但是随后出现类似的错误: cannot redeclare为另一个类/函数cannot redeclare错误。 So it looks like the source is been loaded twice. 因此,看起来源已加载两次。

//Update2 The phpunit.xml.dist was generated when I install symfony, I didn'T modify it. // Update2当我安装symfony时,生成了phpunit.xml.dist,但没有对其进行修改。

<?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>

The errors still there when I delete the testsuites and filter block. 当我删除测试套件和过滤器块时,错误仍然存​​在。

I just tried this, and a symlink was created in my project's bin directory. 我刚刚尝试过,并且在项目的bin目录中创建了一个符号链接。 So I was able to run PHPUnit with bin/phpunit . 因此,我能够使用bin/phpunit运行PHPUnit。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM