I am trying to work with Visual PHPUnit.
When I am using phpunit command its running nicely. No error occurs and my tests running successfully. Output of phpunit --version is as follows:
PHPUnit 4.0.14 by Sebastian Bergmann.
I installed phpunit using PEAR. Output of which pear is as follows:
/usr/bin/pear
On Line #9 of app/config/bootstrap.php of Visual PHPUnit, I set /usr/bin/pear as pear_path.
It shows the following errors when I try to run VPU from browser...
Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in /path_to_vpu/app/config/bootstrap.php on line 83
Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.:/usr/share/php:/usr/bin/pear:/path_to_vpu:/usr/share/php') in /path_to_vpu/app/config/bootstrap.php on line 83
Output of which php is as follows:
/usr/bin/php
My Server is Ubuntu 13.10 Saucy. Output of php -v is as follows:
PHP 5.5.3-1ubuntu2.2 (cli) ....
Output of pear list -c phpunit is as follows:
INSTALLED PACKAGES, CHANNEL PEAR.PHPUNIT.DE:
============================================
PACKAGE VERSION STATE
DbUnit 1.3.1 stable
File_Iterator 1.3.4 stable
PHPUnit 4.0.14 stable
PHPUnit_Selenium 1.3.3 stable
PHPUnit_Story 1.0.2 stable
PHPUnit_TicketListener_GitHub 1.0.0 stable
PHP_CodeCoverage 1.2.17 stable
PHP_Invoker 1.1.3 stable
PHP_Timer 1.0.5 stable
PHP_TokenStream 1.2.2 stable
Text_Template 1.2.0 stable
My question is, why I can't include PHPUnit/Autoload.php?
Edit
My php.ini files (both cli and web) has the following:
include_path = ".:/usr/share/php:/usr/share/pear"
Your include path is probably not setup correctly.
Follow the instructions in the PEAR manual, section "Verifying the include path".
This is what happened to me after PHPUnit upgrade with PEAR. Before upgrade, VPU was working. Also I could not downgrade it via PEAR. After some tweaking, it worked again.
I installed PHPUnit under VPU web directory using composer. Place this composer.json file in VPU web directory.
composer.json
{
"require-dev": {
"phpunit/phpunit": "4.1.*"
}
}
and run composer install. After this, a small change in app/config/bootstrap.php file is needed;
//require_once 'PHPUnit/Autoload.php';
//require_once 'PHPUnit/Util/Log/JSON.php';
// this should be absolute path
require_once '/var/www/.... vpu web path ..../vendor/autoload.php';
and it will work.
Related
I followed the instructions on the official PHPUnit page to install PHPUnit 6.
composer require --dev phpunit/phpunit ^6.0
However, If I go to the project folder and execute phpunit --version then I get PHPUnit 3.7.21 by Sebastian Bergmann..
Why is PHPUnit 3.7.21 installed instead of PHPUnit 6?
I suppose you have xampp installed? It comes with PHPUnit 3.x.x preinstalled with PEAR which strangely can not be uninstalled with pear uninstall. And since its config is in php root folder, that 3-ish version has priority when running phpunit command (even if you have phpunit installed globally) in CMD or PS. How to fix:
Go to xampp/php folder and delete two files phpunit (with no extension) and phpunit.bat. Usually it's enough to prevent older PHPUnit version from being run but let's be on the safer side:
Go to xampp/php/PEAR dir and delete two folders PHPUnit and PHPUnit2.
Go to Control Panel, then navigate System and Security->System and click "Advanced system settings" link on the left. This will open Advanced tab in System Properties window. Click "Environment Variables" button, then under System Variables select "Path" variable and click "Edit..." button. In the new window, click "New" button and type your path to vendor/bin folder (if you already installed PHPUnit for your project there will be phpunit.bat file). By default for xamp it looks like this: C:\xampp\htdocs\yourprojectname\vendor\bin.
Restart your Command Prompt (or PowerShell) window, then type phpunit --version to see the that it's PHPUnit 6.x.x now.
P.S. (If you want latest PHPUnit do not use ^6.0 in require string, since it will install v6.0.0, write it in composer.lock file that will never update PHPunit to the latest e.g. 6.2.1 version atm). Just use
composer require --dev phpunit/phpunit
to install the latest stable version for your project.
You run your global PHPUnit version which is installed in another folder. To get the installed version you have to go to the vendor/bin folder.
vendor/bin/phpunit --version
PHPUnit 6.0.8 by Sebastian Bergmann and contributors.
In newer versions you can run it with bin/phpunit there should be the executable. When you need another PHP-Version then define it before php74 bin/phpunit.
If you use XAMPP, why don't you update XAMPP version of global PHPUnit to desired.
1.
Read this post, which quickly explains what to do:
StackOverflow post
2.
You can get phar file for version you need here:
proper PHPUnit phar file
3.
Which version of PHPUnit you need depends on your PHP version and you can identify it here:
which phar file version you need
Just click on links: PHPUnit 9 - PHPUnit 8 - PHPUnit 7 - PHPUnit 6 - PHPUnit 5 - PHPUnit 4 and read description explaining which PHP version it works with.
Sorry if this is trivial but I did not find any advice how to fix this.
I am on Ubuntu and need PHPUnit for my Yii project.
I have installed PHPUnit twice, by downloading and moving phpunit.phar to '/usr/local/bin' and by running:
composer global require "phpunit/phpunit=3.7.*"
Now I am trying to execute my Yii PHPUnit test:
phpunit unit/DbTest.php
And what I get is:
PHP Warning: require_once(PHPUnit/Extensions/SeleniumTestCase.php):
failed to open stream: No such file or directory in
/opt/lampp/htdocs/yii-project/framework/test/CWebTestCase.php on line 12
PHP Fatal error: require_once(): Failed opening required
'PHPUnit/Extensions/SeleniumTestCase.php'
(include_path='.:/usr/share/php:/usr/share/pear') in
/opt/lampp/htdocs/yii-project/framework/test/CWebTestCase.php on line 12
So it seems that it can't find PHPUnit extension SeleniumTestCase.php. Then PHPUnit installation manual states that Selenium 'is included in the PHAR distribution of PHPUnit.'.
Can you suggest what do I do to make my Yii test work?
You need to install optional additional packages of phpunit for Yii testing to run
The packages you would need are
PHP_Invoker
DbUnit
PHPUnit_Selenium
phpunit-story
You can install them using composer by adding the following to require-dev
"phpunit/php-invoker": "*",
"phpunit/dbunit": ">=1.2",
"phpunit/phpunit-selenium": ">=1.2",
"phpunit/phpunit-story": "*"
use the following commands to install the respective dependencies
composer global require 'phpunit/phpunit-selenium=*'
composer global require 'phpunit/phpunit-story=*'
composer global require 'phpunit/dbunit=*'
composer global require 'phpunit/php-invoker=*'
What I did to fix this:
1) I have downloaded selenium extensions from:
https://github.com/sebastianbergmann/phpunit-selenium/tree/master/PHPUnit/Extensions
and placed the entire PHPUnit directory under
/opt/lampp/htdocs/yii-project/framework/test
At that point PHPUnit stopped complaining about missing SeleniumTestCase.php.
2) Then I got an error about missing file in
PHPUnit/Runner/Version.php
To fix this I commented out these lines in CTestCase.php:
//require_once('PHPUnit/Runner/Version.php');
//require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11
//require_once('PHPUnit/Autoload.php');
Now I am able to run my tests.
Here is what worked for me
sudo pear config-set auto_discover 1
sudo pear channel-discover pear.phpunit.de
sudo pear install --alldeps pear.phpunit.de/PHP_Invoker
sudo pear install --alldeps pear.phpunit.de/DbUnit
sudo pear install --alldeps pear.phpunit.de/PHPUnit_Selenium
sudo pear install --alldeps pear.phpunit.de/phpunit-story
In time of replying this, it is necessary to little bit amend Manquer's response. It is necessary to edit CWebTestCase and include Selenium2TestCase.php instead of SeleniumTestCase.php and extending PHPUnit_Extensions_Selenium2TestCase instead of PHPUnit_Extensions_SeleniumTestCase. Php-invoker is not possible to install on Windows and it is not necessary.
I'm wandering a jungle of "php oil test" command for few days.
I installed phpunit via pear in windows7.
After the installation, When I execute "php oil test" command, following error occurs.
> php oil test
Uncaught exception Oil\Exception: PHPUnit does not appear to be installed.
However, it looks phpunit is installed correctly because "phpunit --version" command works fine(refer following).
>phpunit --version
PHPUnit 4.0.14 by Sebastian Bergmann.
Of course, "pear list" command shows PHPUnit package.
>pear list
INSTALLED PACKAGES, CHANNEL PEAR.PHPUNIT.DE:
PACKAGE VERSION STATE
File_Iterator 1.2.3 stable
PHPUnit 4.0.14 stable
PHPUnit_SkeletonGenerator 1.2.1 stable
PHP_CodeCoverage 1.0.2 stable
PHP_Timer 1.0.0 stable
PHP_TokenStream 1.2.2 stable
Text_Template 1.2.0 stable
I tried some way listed following page, but cannot still resolve.
Installing PHPUnit via PEAR
Could anyone pl give some advice to run "php oil test" command w/o error?
Any advice is welcomed!!
add my code.
/fuel/core/classes/testcase.php
namespace Fuel\Core;
class TestCase extends \PHPUnit_Framework_TestCase { }
/fuel/app/tests/controller_testcase.php
use Fuel\Core\Log;
use Fuel\Core\DBUtil;
use Fuel\Core\DB;
use Fuel\Core\TestCase;
use Fuel\Core\Config;
use Fuel\Core\Request;
class ControllerTestCase extends TestCase {
public function setUp() {
..
php is installed C:\php and pear.bat & phpunit.bat are also there.
PHPUnit folder does not exist in C:\php\pear folder.
Oil uses the configuration key "oil.phpunit.autoload_path" to find the location of PHPUnit autoloader, and if not defined, it uses "PHPUnit/Autoload.php", in combination with the defined PHP include paths.
It then attempts to include this file, and checks if the class "PHPUnit_Framework_TestCase" is available. If not, it bails out with the error message you see.
It has nothing to do with the PHPUnit binary, which is located using the defined path.
This simply means the location where PHPunit is installed is not in PHP's search paths, and no custom path is configured.
Both Phing and PHPUnit were installed from pear on ubuntu 12.04.
PHPUnit is located at /usr/bin/phpunit and /usr/bin is on the unix path and also on the include_path in PHP.INI
How do I tell Phing where PHPUnit is installed?
webroot#gm3:~/med1/pub$ phing utest
Buildfile: /home/webroot/med1/pub/build.xml
myproject > utest:
[echo] Unittests PHPUnit...
Execution of target "utest" failed for the following reason: /home/webroot/med1/pub/build.xml:8:40: /home/webroot/med1/pub/build.xml:8:40: PHPUnitTask requires PHPUnit to be installed
BUILD FAILED
/home/webroot/med1/pub/build.xml:8:40: /home/webroot/med1/pub/build.xml:8:40: PHPUnitTask requires PHPUnit to be installed
Total time: 0.1148 seconds
Answering my own question, I think the PHP version on this machine could be too old and not be able to handle PHAR archives. Or maybe the PHAR configuration is broken. PHPUnit is installed as PHAR on this machine via PEAR.
A workaround for me was to not use <phpunit> but <exec> in the target, which worked:
<target name="test">
<exec command="phpunit --bootstrap tests/bootstrap.php --configuration tests/phpunit.xml">
...
I am not fixing this for now and I am expecting on newer machines it will work out of the box.
I need to install PHPUnit for a web dev project on my Ubuntu box, but am having serious issues. Using suggestions from various sources, I've installed via pear and tried the following:
Currently, phpunit --version returns
PHPUnit 3.7.20 by Sebastian Bergman
when in /usr/share but throws errors everywhere else.
My include path is
include_path = ".:/usr/share/php:/usr/share/php/PEAR:/usr/share/php/File/Iterator"
I've tried different variations ranging from simple /usr/share/php to the full string above. PEAR is in all caps since that is the folder it is in.
Executing with a test case results in
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream:
No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 64
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. require() /usr/bin/phpunit:43
PHP Fatal error: require_once(): Failed opening required
'File/Iterator/Autoload.php'(include_path='/usr/share/php/libzend-framework-php')
in /usr/share/php/PHPUnit/Autoload.php on line 64
pear list -c phpunit returns
Installed packages, channel pear.phpunit.de:
============================================
Package Version State
File_Iterator 1.3.3 stable
PHPUnit 3.7.20 stable
PHPUnit_MockObject 1.2.3 stable
PHP_CodeCoverage 1.2.10 stable
PHP_Invoker 1.1.2 stable
PHP_Timer 1.0.3 stable
PHP_TokenStream 1.1.5 stable
Text_Template 1.1.2 stable
I've confirmed that Autoload.php exist at both php/PHPUnit/ and php/File/Iterator/
My loaded php.ini file is at `/etc/php5/cli.php.ini1 as verified by
php --info | grep "onfiguration"
Any other suggestions would be appreciated.
Search for a file on your computer that is called Autoload.php and is in a file structure like this:
../File/Iterator/Autoload.php
Now open the file that throws the error (/usr/share/php/PHPUnit/Autoload.php in your case) and include a set_include_path statement that points to the absolute path of that file.
You seem to have a very similar problem to what I experienced on Mac OSX. For more information look at this very similar question. If all of this doesn't help, try to install with Composer, which I have heard doesn't have this issue.
For recent projects, I'm using Composer to install PHPUnit and the other related tools. It's quite easy:
## ... rest of the composer.json file
# "php -f composer.phar update --dev" to install
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
I also then have a shell script to actually run the PHPUnit command-line tool from the ./vendor/bin/ directory where a link to the locally installed script is installed.
Like Alister's answer, relying on Composer,
but I prefer to deploy the updated PHPUnit globally across my projects with:
composer.phar global require "phpunit/phpunit=dev-master"
That way, when I am at the root dir of my Symfony project, I can just run
~/.composer/vendor/bin/phpunit -c app/ -v --filter testFireNotifications |tee phpunit.log
That last bit with --filter was to run something selectively (actually, more for fast web automation via crontab, than testing...)
Even on a current Ubuntu 14.04.2 server, the repo is stuck with an outdated PHPUnit 3.7.28 "stable", so I sidestep the OS-provided one with this custom install that won't conflict (I haven't put ~/.composer/vendor/bin in my PATH).