2
votes

I'm trying to install PHPUnit via composer as in documentation it is said that PEAR installation will be gradually discontinued [1]. here is my composer.json after few hours of adding never-ending dependencies (plus a few other tools that I need):

    {
    "require": {
        "phpunit/phpunit": "4.0.*",
        "phpunit/dbunit": ">=1.2",
        "phpunit/php-invoker": "*",
        "phpunit/phpunit-selenium": ">=1.2",
        "phpunit/phpunit-story": "*",
        "phpunit/phpunit-mock-objects": "*",
        "phpunit/phpunit-story": "*",
        "phpunit/php-code-coverage": "2.*",
        "sebastian/diff": "*",
        "squizlabs/php_codesniffer": "*",
        "phploc/phploc": "*",
        "pdepend/pdepend" : "1.1.0",
        "phpmd/phpmd" : "1.4.*",
        "sebastian/phpcpd": "*",
        "theseer/phpdox": "dev-master"
    }
}

Here is info about my PHP (cli):

php -v
PHP 5.4.26 (cli) (built: Mar 15 2014 21:14:32) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

Now when trying to run some simple tests I receive some exceptions like this:

PHP Warning:  Uncaught exception 'PHPUnit_Framework_Error_Warning' with message 'require(classes/SebastianBergmann\Diff.php): failed to open stream: No such file or directory'

Are there some more dependencies that have to be included?

PS. I tried to just download phar file from the site, but it complains about some other files he cannot find.

UPDATE: Here is my phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"
    bootstrap="tests/bootstrap.php"
         backupGlobals="false"
         backupStaticAttributes="false"
         strict="true"
         verbose="true">
    <testsuites>
        <testsuite name="Test Suite">
            <directory>./tests/</directory>
        </testsuite>
    </testsuites>

    <logging>
     <log type="coverage-html" target="build/coverage"/>
     <log type="coverage-clover" target="build/logs/clover.xml"/>
     <log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
    </logging> 
</phpunit>

If I remove coverage logging part, everything works OK.

<log type="coverage-html" target="build/coverage"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
1

1 Answers

3
votes

All what you need to do is to go into your project folder and add a composer.json file with the following content:

{
    "require-dev": {
        "phpunit/phpunit": "4.0.*"
   }
}

Then type $ composer install into your console window and composer will take care of all the dependencies. Composer creates a folder called vendor with a bin folder in it.

Calling $ vendor/bin/phpunit --version from within you project folder should print the current version of PHPUnit.

To use PHPUnit in your application you need to include the autoload file into your application:

require 'vendor/autoload.php';