Install phpunit on windows without composer won't work - php

I'm trying to install phpunit manually on my windows machine. I don't use composer, so I have to install it manually with a .phar file. I'm following the instructions from the official documentation:
https://phpunit.readthedocs.io/en/latest/installation.html#windows
I've done every step, but it won't work. phpunit --version will throw me the message 'phpunit' is not recognized as an internal or external command, operable program or batch file. Can someone Help me?
I'm using Windows 7 64-bit with XAMPP 3.2.2 and PHP 7.1.1.
EDIT:
My phpunit.cmd file location is C:\xampp\php\phar\phpunit.cmd.
The file contains the code #php "%~dp0phpunit.phar" %*. I've added ;C:xampp\php\phar to my PATH variable.

In order to make Windows recognize any command, you must put the binary's path in the relevant environment variable (PATH). Before that you need to create some kind of file Windows can run natively (i.e. not a .phar – can be a command line / batch file or executable). Here are instructions:
https://phpunit.de/manual/current/en/installation.html#installation.phar.windows
Edit: If following the above instructions, it's also important to make sure that php itself is part of the PATH environment variable, so that it's possible to execute commands like php phpunit.phar.

Related

Git Bash for Windows does not see custom command php8

I have installed on Windows 10, both php 7.4 and php 8.1 in different folders PHP7 and PHP8. I have put C:/PHP7 in the PATH (environment variable) and now when I type php in the terminal (CMD, PowerShell and Git Bash) is running php7.
For php8 I have made a custom command php8 by creating a php8.cmd file with this simple content:
"C:/PHP8/php.exe" %*
I have placed the folder where the file is located in the PATH.
All good. Now when I type php8 in Command Line or PowerShell is running php 8. But if i type php8 in the Git Bash it says bash: php8: command not found
Somehow the Git Bash for Windows does not see the new custom command. I am not sure if I need to make a separate .sh file in which to put the equivalent content from the php8.cmd file or if is just a problem of configuring Git Bash to see the php8.cmd file.
Also I do not know what is the equivalent of "C:/PHP8/php.exe" %* in shell script.
Can anyone help with this?
I am doing this because I have an application based on Laravel8 (using php 7.4) and I want to switch it on Laravel 9 (which requires php 8). So I want to start a separate folder where to test the application using Laravel 9 (to see which changes I need to make to the code base or which dependencies need to upgrade). In my PhpStorm I am using Git Bash as the integrated terminal, and that's why I want that custom command php8 to work in Git Bash, too.
Many thanks!
Add the path to your php8 binaries (executables on Windows) to your environment.
On Linux
For example add php8=/usr/bin/php8 alias to .bash_profile (if using bash) on Linux. You can find out the path by running which php in the shell.
On Windows
Find out the executable's path by running where php.exe in the Terminal/PS. Then add this path to the user's PATH variable in system settings.
You should then be able to use php8 to run php commands in php8.
Also ensure composer uses the correct php version either by adding --ignore-platform-reqs argument or setting the following in composer.json
"config": {
"platform": {
"php": "8.0.0"
}
}

PHP command not found in my shell for windows 10 neither in git bash. I tried all the available solution from here

When I typed php in my command prompt, It results
C:\Users\samsung>php
'php' is not recognized as an internal or external command,
operable program or batch file.
I have installed xampp in my windows 10 and I haven't edited the php.ini file in the settings. Any help to enable this php command would be greatly appreciated because I am stock in my laravel composer setup due to this.
If you are using windows:
Open My Computer Properties
Click on Advance System Setting
Select Environment Variables
Click on Path & Edit
Click new & Add your PHP.exe path (e.g. C:\xampp\php\php.exe)
As shown in the picture
then Restart
Detail Support available here
You should add the php.exe path to PATH environment variable
http://php.net/manual/en/faq.installation.php#faq.installation.addtopath
Install composer, during the installation process allow composer to add php to your path:
https://getcomposer.org/Composer-Setup.exe

'php' is not recognized as an internal or external command, operable program or batch file

I am trying to install Symfony 2.7 as instructed by the manual.
When I open CMD (I am running it as an administrator in Windows 8.1) the default path is C:\Windows\System32. I have tried running the command specified in the documentation there (c:\> php -r "readfile('http://symfony.com/installer');" > symfony), as well as in the root directory, both give me the same error.
I am using WAMP, the appache rewrite module and php_xls are activated.
I've also added the following to the PATH in the environment variables: ;C:\wamp\bin\php\php5.2.5;C:\wamp\bin\mysql\mysql5.0.45\bin
After having added it, I rebooted the computer and still nothing worked. How can I install Symfony 2.7?
Here is the solution to your original problem:
You just have to make sure that the path to your php executable is correct when you add it to your PATH environment variable. This path is probably related to the version of PHP you have. You should be able to find this path by navigating inside your wamp installation and looking for the php folder and binary. In your case, this would be C:\wamp\bin\php\php5.5.12
However, for the new problem you have...
However, I get the error The directory name is invalid when I execute
the following command: c:>projects\ php symfony
You just have to make sure that your PATH is updated with the correct path for your php, and then do this from C:>
php projects\symfony
Note that php is the executable and projects\symfony is the path to the symfony file.

Run PHP everywhere from command line on windows 7

I'm using Yii and a WampServer 2.4 64bit.
I installed PEAR and PHPUnit manually.
I can only run the commands PHP, PEAR or PHPUnit in the install folder:
E:\wamp\bin\php\php5.4.12
But I want to execute the commands PHP and PHPUnit from here:
E:\wamp\www\repo\project\protected\tests
So I added the path to my php.exe to my PATH environment variable like this:
;E:\wamp\www\bin\php\php5.4.12
But I can't call php -v on E:\wamp\www\repo\project\protected\tests without the error message, that the command is unknown.
I followed a lot of tutorials how to add php or PHPUnit to my environment variable PATH but nothing is working.
So I realy realy hope,someone can explain me where my mistake is.
You probably added a "www" that is not needed in your PATH variable
;E:\wamp\bin\php\php5.4.12
seems the correct version to me.

PHP: How can I tweak PHPUnit to use a different PHP interpreter?

My system has two PHP interpreters. One came bundled with the OS and the other I installed via the XAMPP package. All of my PHP extensions are applied to the XAMPP installation but PHPUnit seems to only run the version of PHP that came with my machine.
Does anybody know of a way I can configure or rebuild PHPUnit so that it uses my XAMPP PHP interpreter exclusively?
For Mac/Linux, the first line of the phpunit script with starts with
#!/usr/bin/php
change that to
#!/Applications/XAMPP/xamppfiles/bin/php
or whatever other php interpret you want to use.
Find the folder you installed PHPUnit in. There should be a file called phpunit.bat. It should have a line that reads something like
set PHPBIN="C:\php\php.exe"
%PHPBIN% "C:\php\phpunit" %*
Change it to read
set PHPBIN="C:\xampp\php\php.exe"
%PHPBIN% "C:\xampp\php\phpunit" %*
Or whatever the path to your PHP executable is
Since modifying phpunit file did not work for me because of phar signature errors, I was running phpunit with different php version by calling interpreter explicitly (on Linux):
php7.1 /usr/local/bin/phpunit
php5.6 /usr/local/bin/phpunit
Following the example with XAMPP, full path to php interpreter could be provided:
/Applications/XAMPP/xamppfiles/bin/php /usr/local/bin/phpunit
In agreement with Thomas' statement, additionally there's a line further below
if (strpos('/Applications/MAMP/bin/php5.3/bin/php', '#php_bin') === 0) {
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
}
That I've been told you're also supposed to change to reflect the PHP you're interested in using
(I've set mine to MAMP obviously)
I've switched back and forth from 5.2 and 5.3 a lot recently :)
This applies to phpunit installed using Homebrew on Mac OS 10.9. I’ve editing the file located at /usr/local/Cellar/phpunit/4.2.6/bin as seen below. CAVEAT: I don’t know how Homebrew will handle this on a PhpUnit update, but for now it’s working to be able to select the php version that PhpUnit is using for it's testing.
#!/usr/bin/env bash
php=/Applications/MAMP/bin/php/php5.3.14/bin/php
#php=/Applications/MAMP/bin/php/php5.4.4/bin/php
/usr/bin/env $php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/phpunit/4.2.6/libexec/phpunit-4.2.6.phar $*
On Windows, this may be achieved using a similar approach to the ones mentioned in other replies.
In your /path/to/composer/phpunit directory, open the phpunit file in an editor. The first line should look like this:
#!/usr/bin/env php
Simply download your desired version of PHP for Windows, place the contents of the ZIP file somewhere to your liking, and reference the fully quantified path to the php.exe file, instead of just php. Like so:
#!/usr/bin/env /c/misc/php-5.5.9-nts-Win32-VC11-x86/php.exe
In my case, I put it in /c/misc/php-5.5.9-nts-Win32-VC11-x86/, which corresponds to C:\misc\php-5.5.9-nts-Win32-VC11-x86\ using Windows path syntax.
Remember to verify that the correct php.ini file is being used (php --ini or in a script file php_ini_loaded_file()).

Categories