I have installed phpunit by opening gitbash of my windows system and running the following command.
composer require --dev phpunit/phpunit ^9
It installed successfully and when I type following command
./vendor/bin/phpunit --version
it returns PHPUnit 9.5.21 . I think phpunit is installed in this location
C:\Users\ERIKSON\vendor\phpunit
Now I have a project in my xampp folder
C:\xampp\htdocs\erikson-project\wp-content\plugins\youtube-plugin
when I open GitBash in this project location and run the command PHPUnit it says
bash: phpunit: command not found
. How can I solve this ? Please help.
I have composer.json file inside youtube-plugin folder and the code is
C:\xampp\htdocs\erikson-project\wp-content\plugins\youtube-plugin\composer.json
{
"require-dev": {
"phpunit/phpunit": "9.5"
}
}
Do I need to add anything in my windows system environment variable?
I've got a problem with PhpStorm, composer and PHPUnit.
Windows 8.1 Pro (64 bit)
PhpStorm is up to date: 2018.2.2
Tried different PHP interpreters like XAMPP and a clean PHP for win
PHPUnit is required by composer with: "phpunit/phpunit": "^7.3.3".
PHPUnit is successfully installed via composer to the vendor directory as well.
PHPUnit is recognized from PhpStorm:
My test class extends the PhpUnit\Framework\TestCase class and when you run the test, the following happens:
First it seems like PhpStorm loads the old PHPUnit (3.7.21) from XAMPP's PHP and not the recognized PHPUnit (7.3.3) as setup in the PhpStorm settings / installed to the vendor folder.
But I don't think so.
I think PhpStorm tries to load the PhpUnit\Framework\TestCase class by the autoloader, but I don't know why it doesn't find the PHPUnit...
Thanks in advance!
The whole project could be minimized to this simple test class:
The composer.json looks like the following:
"autoload": {
"psr-4": {
"Flo\\Newsletter\\": "src/"
}
},
"require": {
"php": "^7.1"
},
"require-dev": {
"phpunit/phpunit": "^7.3.3"
}
Namespaces are case-sensitive. Please change PhpUnit to PHPUnit in the import.
Although PhpStorm could really detect that. Here's a feature request for that: https://youtrack.jetbrains.com/issue/WI-38140
I installed phpunit-selenium using composer according to here; https://phpunit.de/manual/3.7/en/selenium.html
The problem is that I only have selenium 2 for phpunit. PHPUnit_Extensions_Selenium2TestCase.php is there. But the file PHPUnit_Extensions_SeleniumTestCase.php does not exist in the extension map where it supposed to be. So selenium 1 function can not be used.
How can I get selenium 1 for php unit using composer (on a windows machine)?
I know there is an answer involving pear; How do I solve this error: "Class PHPUnit_Extensions_SeleniumTestCase could not be found"
But pear is not preferred because composer is shared with the team. It would save installing it.
Solved it. I needed to move back a version in phpunit-selenium:
"require-dev": {
"phpunit/phpunit-selenium": "1.4.*"
}
instead of using the latest version which probably only works with selenium 2.
"require-dev": {
"phpunit/phpunit-selenium": ">=1.2"
}
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.
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