I get Cannot open file "FooTest.php"
I am using PHP 5.4.0 and PHPUnit 3.6 on Windows
I have traced the issue back to PHPUnit\Util\Filesystem.php when it calls get_include_path which contains "." and the location to pear.
For some reason it doesn't resolve . to where the tests are as it resolves it locally to the PHPUnit location.
How do I get phpunit to recognise the location of the tests.
First make also sure your PHPUnit installation and all dependencies are up-to-date:
pear upgrade phpunit/PHPUnit --alldeps
In case your pear installation is messed up you can also obtain it from the github repository.
Depending on how your project and enviroment is set up make sure your current directory is your projects directory.
cd /your/projects/home/directory/
The common syntax to invoke phpunit is either
phpunit [switches] <your_unit_test.php>
or
phpunit [switches] <directory>
So, basically in case your tests are stored within directory YourUnitTests the easiest way to start it would be just to use
phpunit YourUnitTests
Related
I'm working with Symfony 5 and I installed phpunit-bridge with the command included in the documentation : composer require --dev symfony/phpunit-bridge.
When I run phpunit with this command, php bin/phpunit, I have this error :
PHP Fatal error : Uncaught Error: Call to undefined method
PHPUnit\TextUI\TestRunner::doRun()
I'll try to guess.
You also have a bundle like liip/functional-test-bundle or other, which require PHPUnit in requirements (or even you require PHPUnit directly in your composer.json together with phpunit-bridge).
As a result you have two different version of PHPUnit installed in project, with two different api.
If installed liip/functional-test-bundle is your case and you do not want to remove it, you need to install by bridge same PHPUnit version as installed by Liip bundle dependency. You can set version through SYMFONY_PHPUNIT_VERSION env variable or directly in bin/phpunit file. Or you can redefine path to already installed PHPUnit version (in vendors/) through SYMFONY_PHPUNIT_DIR env or directly in bin/phpunit.
Note: you can not set SYMFONY_PHPUNIT_VERSION or SYMFONY_PHPUNIT_DIR through .env.* files, since bin/phpunit not read this files. So it should be real env vars.
I had a similar issue with symfony 5.1. I tried upgrading all dev packages related to testing but it didn't work.
Once I completely remove all dev (testing related) packages and reinstalling the symfony phpunit bridge package it worked.
You have to remove the phpunit file inside the root/bin directory
Steps to follow
Remove all dev test packages (Eg: composer remove symfony/browser-kit)
Remove if there are following packages : phpunit/phpunit, symfony/phpunit-bridge, symfony/css-selector, symfony/browser-kit
Install the brdge package again by running composer require --dev symfony/phpunit-bridge
I have the latest PhpStorm (2016.2) and PHPUnit phar (5.5.4). For some reason when I run a PHPUnit test in my project in PhpStorm, it is adding on --teamcity to the run command, resulting in a failure:
Testing started at 12:52 PM ...
Unit test suite invoked with a path to a non-unit test: --teamcity
Process finished with exit code 1
I have no idea where this --teamcity option is coming from, it happens no matter what test I run, and even when starting from a blank configuration. I also do NOT have the TeamCity plugin installed, I don't even use TeamCity.
Here's what the full command appears as:
/usr/local/Cellar/php70/7.0.9/bin/php /Users/name/bin/phpunit-5.5.4.phar --configuration /path/to/config/my-phpunit.xml ClassNameTest /Users/name/PhpstormProjects/path/to/tests/unit/app/ClassNameTest.php --teamcity
(sensitive information swapped out)
All I want to do is get rid of this --teamcity option, everything works if I run in a separate terminal window without that option. This only recently started happening, maybe after a PhpStorm update.
tl;dr
I only could resolve this by removing the system installed phpunit instance from my system (Linux):
sudo apt remove phpunit-*
Details
Even if the setting in PhpStorm was to use composer autoloader:
for some reason it ended up using TeamCity from /usr/share/php/PHPUnit/Util/Log/TeamCity.php:
Project's local PHPUnit was 6.2 while the system default was 5.1 -> they're incompatible.
I spent half a day struggling with this. The underlying issue is switching between PHPUnit versions (6.x.x -> 4.x.x). (Happened to me by switching branches)
A click on the refresh button in the PHPUnit preferences fixes it.
(Languages & Frameworks > PHP > PHPUnit)
Make sure the version of PHPUnit it thinks you have matches the one it reports.
This --teamcity option is used by PHPStorm to output tests result.
What you're facing is an issue caused by PHP7 and an old version of PHPUnit.
Remove your PHPUnit 5 and install the latest one (currently 6.2) with composer and use PHPUnit namespaces instead.
More info on this bug: https://github.com/sebastianbergmann/phpunit/issues/2460
Problem was internal to the project. PHPUnit does not contain that error message. Sorry!
I am trying to use PHPUnit in PhpStorm (on a Mac). Therefore I tried adding the pear path and phpunit path to the include path of PhpStorm (the ones I found through which pear on the command line) - it tells me that phpunit was not found.
I also tried to use PHPUnit with the custom autoloader generated by composer (the phpunit package is installed), I then receive another error:
Fatal error: Class 'PHP_CodeCoverage_Filter' not found
If I run phpunit on the console normally everything works:
phpunit --bootstrap vendor/autoload.php tests/*Test.php
What am I doing wrong?
The problem was that I used the default php interpreter which phpStorm suggested to me. This was version PHP 5.5 though and not the 5.6 version in my terminal.
After changing the interpreter to an up-to-date php version (5.6 or 7.0) it worked with the PHAR Option.
I've downloaded the current version of PHPUnit from Github and made a small customization. I now want to create my own phar archive for it. I see there is a build.xml file included with PHPUnit that looks like it contains the directives needed for creation of the phar archive, but after reading up on phar for a bit, it's still not clear to me what the commands are to make it happen for PHPUnit. Any advise is appreciated!
Cloning the repo. I guess you have this already but to be complete
$ git clone https://github.com/sebastianbergmann/phpunit
Change into it
$ cd phpunit
A build.xml files means (mostly) that Ant is used as build management system. To figure out which targets the project (-p) provides just ask ant itself:
$ ant -p
Then you should get this output:
Buildfile: /private/tmp/phpunit/build.xml
Main targets:
clean Cleanup build artifacts
composer Install dependencies with Composer
pdepend Calculate software metrics using PHP_Depend
pear Create PEAR package of PHPUnit and all its dependencies (release)
phar Create PHAR archive of PHPUnit and all its dependencies (release)
phar-alpha Create PHAR archive of PHPUnit and all its dependencies (alpha)
phar-beta Create PHAR archive of PHPUnit and all its dependencies (beta)
phpab Generate autoloader script
phpcpd Find duplicate code using PHPCPD
phpcs Find coding standard violations using PHP_CodeSniffer
phpcs-ci Find coding standard violations using PHP_CodeSniffer
phpdox Generate software project documentation using phpDox
phploc Measure project size using PHPLOC
phpmd Perform project mess detection using PHPMD
phpmd-ci Perform project mess detection using PHPMD
phpunit Run unit tests with PHPUnit
prepare Prepare for build
Default target: build
The rest is simple - just type
$ ant phar
The task will install Composer (even if you already have it, but copies it into the current folder) and downloads all dependencies.
I've installed PHPUnit and everything seems to be working fine as when I run phpunit from the root php directory C:\wamp\bin\php\php5.4.16 it runs as expected.
However, the problem I am having is running PHPUnit from elsewhere within the command line, so I cannot run any tests because of this. I get the error
phpunit' is not recognized as an internal or external
command, operable program or batch file.
My path is set correctly C:\wamp\bin\php\php5.4.16 which is where php.exe is installed.
I have also tried re-installing, and am running version 3.7.24.
Anyone have any tips on what I may be doing wrong?
PHPUnit is not set in the PATH global variable. Try installing PHPUnit using PEAR. For win7 use this tutorial: http://designbyjeeba.blogspot.ro/2012/12/easy-way-to-install-pear-and-phpunit-in.html
If PEAR doesn't find any package to install (when trying to install anything using it) clear PEAR's cache:
pear clear-cache
I dont know the way you installed it, but i did it this way and it works fine for me.
Also i recommend installing DBUnit and PHPUnit selenium. Use the following commands:
pear install phpunit/PHPUnit_Selenium
pear install phpunit/DbUnit
For Linux use the commands given by PHP at the following link:
http://phpunit.de/manual/3.7/en/installation.html