Phpunit: Composer install doesn't work

Created on 12 Nov 2014  ·  4Comments  ·  Source: sebastianbergmann/phpunit

Installing by adding phpunit to the require-dev section of composer.json does not seem to work.

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

This currently attempts to pull in phpunit 4.3.5. The composer.json file specifies that there is a binary for phpunit in the bin-dir (bin/phpunit), but the code for phpunit in GitHub does not contain such a directory, much less a phpunit file in that directory. Thus, when it attempts to symlink it into bin/phpunit on the project level, it fails since there is no file to symlink in the first place.

This is on an Ubuntu Linux system, using the latest composer PHAR, as the ErrorException thrown is on line 246 of src/Composer/Installer/LibraryInstaller.php, and the error message is "file_put_contents(/xxxxxx/bin/phpunit): failed to open stream: No such file or directory" (the project directory path is not xxxxxx, it has been redacted).

Thanks.

Most helpful comment

Thank you very much for the bug report though, as I ran into the exact same issue today and was able to resolve it by removing the bin dir…

All 4 comments

Not sure what your problem is:

$ cat composer.json 
{
    "require-dev": {
        "phpunit/phpunit": "4.3.*"
    }
}

$ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing sebastian/version (1.0.3)
    Loading from cache

  - Installing sebastian/exporter (1.0.2)
    Loading from cache

  - Installing sebastian/environment (1.2.0)
    Loading from cache

  - Installing sebastian/diff (1.2.0)
    Loading from cache

  - Installing sebastian/comparator (1.0.1)
    Loading from cache

  - Installing symfony/yaml (v2.5.6)
    Loading from cache

  - Installing doctrine/instantiator (1.0.4)
    Loading from cache

  - Installing phpunit/php-text-template (1.2.0)
    Loading from cache

  - Installing phpunit/phpunit-mock-objects (2.3.0)
    Loading from cache

  - Installing phpunit/php-timer (1.0.5)
    Loading from cache

  - Installing phpunit/php-file-iterator (1.3.4)
    Loading from cache

  - Installing phpunit/php-token-stream (1.3.0)
    Loading from cache

  - Installing phpunit/php-code-coverage (2.0.11)
    Loading from cache

  - Installing phpunit/phpunit (4.3.5)
    Downloading: 100%         

phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files

$ ./vendor/bin/phpunit --version
PHPUnit 4.3.5 by Sebastian Bergmann.

My apologies on the assumption of the need for the bin directory in your project. I did notice this morning the phpunit file in the root of the phpunit repository, so my assumption there is not correct; many apologies. However, I am still encountering the same problem. However, since you are able to get it installed properly using composer install, I will close this ticket, as the basis for it is an incorrect assumption. If I resolve my problem and discover the source of it, I will open or reopen as appropriate if the issue is in fact related to phpunit. Thanks.

I think I have discovered the source of my problem. composer.json had an entry as follows:

"require-dev": {
    "phpunit/phpunit": "~3.7"
}

And bin/phpunit was a symlink that pointed to ../vendor/phpunit/phpunit/composer/bin/phpunit.

composer install was not updating that symlink, and when it tried to update the contents of bin/phpunit, which was a broken symlink, it failed and then tried to update via using the createUnixyProxy method, which also failed due to the broken symlink. It appears that the change in where the phpunit binary from 3.7 to 4.0 potentially confused composer, though I think composer should be able to gracefully handle the need to update a broken symlink in the bin folder better than what it does currently.

Thanks, and I'm sorry for the false report.

Thank you very much for the bug report though, as I ran into the exact same issue today and was able to resolve it by removing the bin dir…

Was this page helpful?
0 / 5 - 0 ratings