符号2.1的PHPUnit-无法重新声明xyz()



我读到PHPUnit可以与pear或composer一起安装。因为我在一个带有WAMPSERVER和cygwin的控制台上,并且没有安装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_wwwsymfony2.1vendorkriswallsmithasseticsrcfunctions.php:20) in C:wamp_wwwsymfony2.1vendorkriswallsmithasseticsrcfunctions.php on line 26
Call Stack:
0.0005     128056   1. {main}() C:wamp_wwwsymfony2.1vendorphpunitphpunitcomposerbinphpunit:0
0.0095     433520   2. PHPUnit_TextUI_Command::main() C:wamp_wwwsymfony2.1vendorphpunitphpunitcomposerbinphpunit:42
0.0096     436736   3. PHPUnit_TextUI_Command->run() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitTextUICommand.php:130
0.0096     436952   4. PHPUnit_TextUI_Command->handleArguments() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitTextUICommand.php:139
0.0144     683168   5. PHPUnit_TextUI_Command->handleBootstrap() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitTextUICommand.php:615
0.0148     689328   6. PHPUnit_Util_Fileloader::checkAndLoad() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitTextUICommand.php:787
0.0152     689448   7. PHPUnit_Util_Fileloader::load() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitUtilFileloader.php:77
0.0200    1013688   8. include_once('C:wamp_wwwsymfony2.1appbootstrap.php.cache') C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitUtilFileloader.php:93
0.0202    1016424   9. require_once('C:wamp_wwwsymfony2.1appautoload.php') C:wamp_wwwsymfony2.1appbootstrap.php.cache:3
0.0204    1017424  10. require('C:wamp_wwwsymfony2.1vendorautoload.php') C:wamp_wwwsymfony2.1appautoload.php:5
0.0205    1017440  11. ComposerAutoloaderInit::getLoader() C:wamp_wwwsymfony2.1vendorautoload.php:7
PHP Fatal error:  Cannot redeclare assetic_init() (previously declared in C:wamp_wwwsymfony2.1vendorkriswallsmithasseticsrcfunctions.php:20) in C:wamp_wwwsymfony2.1vendorkriswallsmithasseticsrcfunctions.php on line 26
PHP Stack trace:
PHP   1. {main}() C:wamp_wwwsymfony2.1vendorphpunitphpunitcomposerbinphpunit:0
PHP   2. PHPUnit_TextUI_Command::main() C:wamp_wwwsymfony2.1vendorphpunitphpunitcomposerbinphpunit:42
PHP   3. PHPUnit_TextUI_Command->run() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitTextUICommand.php:130
PHP   4. PHPUnit_TextUI_Command->handleArguments() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitTextUICommand.php:139
PHP   5. PHPUnit_TextUI_Command->handleBootstrap() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitTextUICommand.php:615
PHP   6. PHPUnit_Util_Fileloader::checkAndLoad() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitTextUICommand.php:787
PHP   7. PHPUnit_Util_Fileloader::load() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitUtilFileloader.php:77
PHP   8. include_once() C:wamp_wwwsymfony2.1vendorphpunitphpunitPHPUnitUtilFileloader.php:93
PHP   9. require_once() C:wamp_wwwsymfony2.1appbootstrap.php.cache:3
PHP  10. require() C:wamp_wwwsymfony2.1appautoload.php:5
PHP  11. ComposerAutoloaderInit::getLoader() C:wamp_wwwsymfony2.1vendorautoload.php:7

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

//更新2phpunit.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>

当我删除testsuites和filter块时,错误仍然存在。

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

相关内容

  • 没有找到相关文章

最新更新