I'm having trouble getting phpunit to work on my vagrant box. I provisioned it with puphpet and manage my laravel project with composer.
The problem is that when I require-dev phpunit, i can only run it as sudo vendor/bin/phpunit. Without sudo I get permission denied (chmod doesn't seem to change the permissions) and simply typing phpunit throws a not found error.
My composer.json:
"require-dev": {
"phpunit/phpunit": "4.3.*"
},
Ultimately I want to use phpunit with phpstorm but if I can't get it to work on my VM, that nice integration is still somewhat out of reach.
Can't you install phpunit as a programm on your box? Like with
sudo apt-get install phpunit
Then you can call it from any directory.
Related
I have configuration:
Open Server 5.2.8 (WAMP)
PhpStorm 2017.3.4
Yii 2.0.14 basic
I added to the %PATH% path to PHP and to the Codeception folder:
In the PhpStorm terminal I launched the codecept run command and everything looks good. But the Windows terminal does not maintain colors therefore I wanted to launch tests through PhpStorm.
I made such settings for PHPUnit and Codeception (from Yii2\vendor):
But for some reason I receive such error:
You are missing the dependency for phpunit, add the following to your composer.json
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
and run
composer update
Answers here and here. Thanks to #panosru.
Just download new version PHPStorm 2017.3.6.
I am currently learning about Docker, and using it for 2 weeks. Now i have a very simple task, installing PHP Libraries via Composer. That is usually, when working without Docker:
composer install
Now since i am using Docker, i found there is a Docker Container, that is holding composer for me:
docker run --rm -v $(pwd):/app composer/composer install
This is working pretty good, but there is some libraries out there, that require specific php libraries to be installed, like bcmath, so i add this to my Dockerfile
FROM php:7.0-apache
RUN docker-php-ext-install bcmath <-- added this line
COPY . /var/www/html
WORKDIR /var/www/html
EXPOSE 80
When i rebuild my container, this code returns true
var_dump(extension_loaded('bcmath'))
Hooray! BCMath is installed correctly, but composer does not recognize it, because the library is not installed in the composer container!
Now i could ignore that by using
docker run --rm -v $(pwd):/app composer/composer install --ignore-platform-reqs
but this is, in my opinion, a dirty workound, and composer can not validate my platform. Is there any clean solution, besides downloading composer in my Dockerfile and not reusing an existing container?
You may use platform settings to mimic your PHP container configuration. This will work similar to --ignore-platform-reqs switch (it will use PHP and extensions configured in composer.json instead of real info from current PHP installation), but it gives you more granular control. Instead of "ignore all platform requirements checks" you may say "I really have bcmath installed, trust me". All other requirements will be checked, so you still be warned if new requirement will pop-up.
"config": {
"platform": {
"php": "7.1",
"ext-bcmath": "*"
}
},
You need PHP + PHP Extensions + Composer in the same(!) container = DevContainer.
Simply install Composer using the command provided here.
Since the phpunit channel was shut down in 2014, I am looking for a way to install phpunit version 3.5.x without pear. The only answers that I have found explain how to use it with composer, but version 3.5.x does not exist as a composer package.
I do have the 3.5.10 source code for PHPUnit, but I am struggling on how to install it so that I can use it as a command line tool.
PHPUnit 3.7 was the first version to support Composer and PHAR. With PHPUnit 3.5 you are out of luck.
I use phpunit 4.8.* it supports composer and is very easy to install it. Using netbeans makes it even more easy because netbeans creates tests for you.
Put the following lines in the composer.json
"require-dev": {
"phpunit/phpunit-skeleton-generator": "*",
"phpunit/phpunit": "4.8.*"
},
Now update the composer via command and it will install. Using git it will be something like this.
composer update
composer install
To get the composer.phar
curl -sS https://getcomposer.org/installer | php
Now configure phpunit and you're good to go.
I am trying to run unit tests in a new laravel 5 application, using the phpunit framework. In the root path of my laravel application I ru the following command:
./vendor/bin/phpunit /tests/ExampleTest.php
And then I get the following message:
You need to set up the project dependencies using the following commands:
wget http://getcomposer.org/composer,phar
php composer.phar install
I already have composer installed in may system and I install Laravel 5 using composer. Isn't phpunit installed when I install a new laravel 5 application? If not, how can I install it in a existent laravel 5 application?
I known that I can also install phpunit globaly and resolve the problem. But maybe it will be a duplication since I have all the phpunit code already in may laravel application.
I had the same problem and it had a specific solution that may apply to other people. I store my files in Dropbox, and the vendor/bin/phpunit file should be an symlink like this
$ ls -lo vendor/bin/phpunit
lrwxr-xr-x vendor/bin/phpunit -> ../phpunit/phpunit/phpunit
However, Dropbox will occasionally replace symlinks with the original file, and this will cause the error above. The behaviour is inconsistent, and with relative symlinks seems to break when 2 machines are accessing Dropbox at the same time. Fixing the symlink worked for me or you could make a new symlink directly to the vendor/phpunit/phpunit/phpunit outside of Dropbox and run that.
Edit: Nowadays I exclude Vendor and node_modules from Dropbox - and simply run composer install when necessary. This works really well, and also deals with the hassle of syncing so many files on Dropbox. What you can do is go into the folder and delete all the files. Wait for Dropbox to sync. Then mark the folder as excluded. Finally, run composer install and you get the contents as you need. (Delete + composer install often solves other issues too).
Running composer install did nothing in my case. However, removing vendor folder and then calling composer install fixed it.
You need to have Composer installed and run composer install or composer update in your application to install the different packages listed in your composer.json.
When you install your Laravel application it doesn't install the packages right away.
You can verify the packages are installed by looking in the vendor directory of your application and check that phpunit is in there.
did you install phpunit globally? I recommend you do it.
just type in your laravel's root directory (e.g. /var/www)
cd /var/www
phpunit
if you what to test just one file, you can do something like this:
phpunit tests/ExampleTest.php
Unit Test:
D:\xampp\htdocs\Samplemed\vendor\bin>
phpunit ../../tests/Unit/Company/CompanyUnitTest
Feature Test:
D:\xampp\htdocs\Samplemed\vendor\bin>phpunit
../../tests/Feature/Company/CompanyFeatureTest
Please try this. its working fine.
I have project on Symfony 2 and i would like use PHPUNIT on Windows 7.
On githut phpunit is:
Composer
Simply add a dependency on phpunit/phpunit to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPUnit 3.7:
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
For a system-wide installation via Composer, you can run:
composer global require 'phpunit/phpunit=3.7.*'
Make sure you have ~/.composer/vendor/bin/ in your path.
First i use system-wide installation but i dont know when this installed.
Next i add to my composer.json require-dev.
This installed phpunit in C:/wamp/www/myproject/vendor/symfony. Next i try commands:
composer install --dev
And i can't use phpunit. In cmd.exe i enter "phpunit" and i have error:
'phpunit' is not recognized as an internal or external command operable program or batch file
How can i use phpunit? I have Windows 7, Wamp server and php 5.4.12.
When you install PHP-Unit in windows via composer, the global installation will create files in
C:\Users\YOUR_USERNAME\AppData\Roaming\Composer
To execute phpunit easily via command line you need to add path of phpunit.bat file in windows Environment Variables. For this:
Right click My Computer
Go to Properties -> Advance system settings and
Click Environment variables from the Advance tab.
Now add C:\Users\YOUR_USERNAME\AppData\Roaming\Composer\vendor\bin to the windows PATH.
You can now run the phpunit from command. Note that you may need to restart your command prompt for the changes to take effect.
The bin file of packages are put in the configured bin directory. By default, this is vendor/bin and when you use the symfony standard edition, this is the bin folder.
To execute this bin file, run ./bin/phpunit (or ./vendor/bin/phpunit when not using the Symfony Standard Edition)
Windows users have to put this in double quotes: "bin/phpunit" (or "vendor/bin/phpunit")
composer require --dev phpunit/phpunit ^7
The above example assumes, composer is already on your $PATH variable.
You composer.json should look similar to;
{
"name": "vendor_name/package_name",
"description": "This project is for practicing writing php unit tests",
"minimum-stability": "stable",
"license": "proprietary",
"authors": [
{
"name": "Umair Anwar",
"email": "umair.anwar#gmail.com"
}
],
"autoload": {
"classmap": [
"src/"
]
},
"require-dev": {
"phpunit/phpunit": "^7",
"phpunit/dbunit": "^4.0"
}
}
Easiest way to install phpunit via composer is to run from project root.
$ composer require phpunit/phpunit
What this would do is, it will create a phpunit folder inside vendor/bin
and you can run unit tests like this..
$ ./vendor/bin/phpunit
Too simple operation on Windows with composer and works for me following way:
Install composer
https://getcomposer.org/doc/00-intro.md#installation-windows Go to
your symphony folder e.g C:\wamp64\www\symfony\UserManagement where is
composer.json and run this command.
Should be register with global to not have issue $phpunit bash: phpunit: command not found
//old version is 5.7 new 6.4 or put newest version.
composer global require --dev phpunit/phpunit ^5.7
I remember futzing around with the composer dependency stuff for phpunit and never could get it to work.
Instead, from your git bash shell:
mkdir ~/bin
cd ~/bin
curl https://phar.phpunit.de/phpunit.phar > phpunit
chmod +x phpunit
exit out of bash and then start a new bash session.
And you should be good to go. You can echo $PATH to verify you have a path to ~/bin but one seems to added by default.
https://phar.phpunit.de/phpunit.phar
I also came across the same issue and find out the solution by following steps
To run PHPUnit in Windows 7 under WAMP installation
Composer Install
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
Simply Set Environment Variable
The php unit will be install in a vendor dir in vendor/bin
Path : C:\wamp\www\myproject\vendor\bin;
Open a new Command Prompt
C:\Users\guny >phpunit --version
PHPUnit 3.7.30 by Sebastain Bergmann