I read that PHPUnit can be installed with pear or with 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. And especially since symfony2.1 you must use composer, so I choose this method.
I add this into my composer.json
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
And then do a
php composer.phar install --dev
//Update1 (thanks to theunraveler)
The bin files (phpunit and phpunit.bat) are copied or linked to the bin directory of the app. But when I call bin/phpunit -c app/
I get this error:
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. 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.
<?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. So I was able to run PHPUnit with bin/phpunit
.