Search code examples
phpunitvagrantcomposer-phpsymfony-2.8

Vagrant : phpUnit not found (symfony 2.8)


I'm new to phpUnit. I installed it via composer. My composer.json is the following :

"require": {
    "php": ">=5.5.9",
    "symfony/symfony": "^2.8",
    "doctrine/orm": "^2.5",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/doctrine-cache-bundle": "^1.2",
    "symfony/swiftmailer-bundle": "^2.3",
    "symfony/monolog-bundle": "^2.8",
    "sensio/distribution-bundle": "^5.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "incenteev/composer-parameter-handler": "^2.0",
    "doctrine/mongodb-odm": "~1.0",
    "doctrine/mongodb-odm-bundle": "~3.0",
    "nicmart/tree": "~0.2",
    "jms/serializer-bundle": "^1.1",
    "simple-bus/symfony-bridge": "^4.1",
    "phpunit/phpunit":">=4.2",
    "codeception/codeception": "*",
    "nicolopignatelli/valueobjects": "^4.0"

},
"require-dev": {
    "sensio/generator-bundle": "^3.0",
    "symfony/phpunit-bridge": "^2.7"
    }

during composer update, i recieved
- Installing phpunit/phpunit (5.2.9)

and i see the phpunit directory in my vendors.

now while simply trying to output the phpunit version (or while trying to start testing), i get the following error message :

me@myMachine:root/path/of/symfony$ phpunit -v The program 'phpunit' is currently not installed. To run 'phpunit' please ask your administrator to install the package 'phpunit'

is there any kind of shortcut to create in bash?

UPDATE

like suggested by the 2 current answers, i tried to run me@myMachine:root/path/of/symfony$ ./vendor/bin/phpunit -v

but it returns a permission denied exception despite the fact the current user (me@myMachine) is the fileowner.

furthermore, me@myMachine:root/path/of/symfony$ ls -l ./vendor/bin returns

-rw-rw-rw- 1 me me 612 Mar  1 09:52 codecept
-rw-rw-rw- 1 me me 603 Jan 28 13:50 doctrine
-rw-rw-rw- 1 me me 609 Jan 28 13:50 doctrine-dbal
-rw-rw-rw- 1 me me  607 Jan 28 13:50 doctrine.php
-rw-rw-rw- 1 me me 608 Feb 24 19:20 geotools
-rw-rw-rw- 1 me me 603 Mar  1 09:52 phpunit
-rw-rw-rw- 1 me me 978 Jan 20 12:15 security-checker

and if try to chmod -vR u+x ./vendor/bin it returns as expected a

mode of ‘bin/’ changed from 0777 (rwxrwxrwx) to 0766 (rwxrw-rw-)

mode of ‘bin/phpunit’ changed from 0666 (rw-rw-rw-) to 0766 (rwxrw-rw-)

but me@myMachine:root/path/of/symfony$ ls -l ./vendor/bin returns again

-rw-rw-rw- 1 me me 612 Mar  1 09:52 codecept
-rw-rw-rw- 1 me me 603 Jan 28 13:50 doctrine
-rw-rw-rw- 1 me me 609 Jan 28 13:50 doctrine-dbal
-rw-rw-rw- 1 me me  607 Jan 28 13:50 doctrine.php
-rw-rw-rw- 1 me me 608 Feb 24 19:20 geotools
-rw-rw-rw- 1 me me 603 Mar  1 09:52 phpunit
-rw-rw-rw- 1 me me 978 Jan 20 12:15 security-checker

like the chmod wasnt taken into account.

UPDATE 2

apparently, this issue is related to Vagrant.

I re-installed symfony completly, in 2.8 and 3.0 version, and the problem remains the same.

i found this similar issue and therefore choosed to install phpUnit globally composer global require phpunit/phpunit and then run phpunit -v again. This time, the command is found but i got the following error

me@myMachine:/path/to/symfony/root$ phpunit -v
PHPUnit 4.8.23 by Sebastian Bergmann and contributors.

Runtime:        PHP 5.6.14-1+deb.sury.org~trusty+1
Configuration:  /var/www/public/symfony/sgv3/sgv3/phpunit.xml.dist

.                                                                   1 / 1 (100%)

Time: 6.86 seconds, Memory: 27.75Mb

PHP Fatal error:  Call to undefined method PHPUnit_Framework_TestResult::warningCount() in /home/vagrant/.composer/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php on line 185

Solution

  • If you install PHPUnit via Composer then its binary will be at vendor/bin/phpunit.