phpunit - wrong path - php

Does anybody know what I'm doing wrong?
I've installed phpunit, and everything is fine when I'm in the /opt/local/PEAR directory, so if I go to /opt/local/PEAR directory and run phpunit I get:
PHPUnit 3.5.11 by Sebastian Bergmann.
Usage: phpunit [switches] UnitTest [UnitTest.php]
phpunit [switches]
blablabla
but if I am on some other path I get:
Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/local/bin/phpunit on line 38
Fatal error: require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='.:/usr/lib/php') in /usr/local/bin/phpunit on line 38
I know that is something wrong with my PATH. How can I fix it?

Try adding /opt/local/PEAR to your php.ini file include_path.
//Before:
include_path='.:/usr/lib/php'
//After:
include_path='.:/usr/lib/php:/opt/local/PEAR'
You may also need to restart your web server afterwards for the changes to take effect.
And as RobertPitt comments, this can also be done at runtime without access to the php.ini file.
<?php
$path = '/opt/local/PEAR';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
?>

The PEAR channel (pear.phpunit.de) that is used to distribute PHPUnit needs to be registered with the local PEAR environment. Furthermore, component that PHPUnit depends upon are hosted on additional PEAR channels.
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:
pear install phpunit/PHPUnit

In Ubuntu, I used
pear config-set auto_discover 1
pear install pear.phpunit.de/PHP_CodeCoverage

For Ubuntu edit this php.ini for CLI:
/usr/local/lib/php.ini
add /usr/local/lib/php/ to your include line
include_path= "/opt/zend/library/:/var/www/library/:/usr/local/bin/pear/:/usr/local/lib/php/"
Took me a day to figure it out. Bingo.
If this does not work, try this, it will give you a hint where your PHP libs are located.
$ locate PHP_CodeCoverage

as far as I know PEAR installation method comes to his end, this is what's says about it on the github repository.
https://github.com/sebastianbergmann/phpunit/wiki/End-of-Life-for-PEAR-Installation-Method

Related

PHPUnit complains about Selenium

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.

Trouble with Pear in XAMPP

I'm trying to install PhpDocumentor 2, and after following the steps for the installation through PEAR, I get the following message:
PEAR_Config::writeConfigFile fopen('C:\Windows\pear.ini','w') failed
(fopen(C:\Windows\pear.ini): failed to open stream: Permission denied)
So I checked the pear configuarion: $ pear config-show and see that things are all over the place. Any idea on how to correct this?
Also, the pear.ini file is nowhere to be found.
You cannot fix the pear.ini-in-c:\windows problem unfortunately.
A solution is to run the terminal as administrator, and run the pear install command in it.
If you want to modify the locations, use pear config-set key value.

Install phpunit on windows

How to install phpunit?
I read documentation https://github.com/sebastianbergmann/phpunit, but have an error:
>pear upgrade PEAR
Nothing to upgrade
>pear config-set auto_discover 1
config-set succeeded
>pear install pear.phpunit.de/PHPUnit
No releases available for package "pear.phpunit.de/PHPUnit"
install failed
How can I fix this error?
Try the following instructions:
In the command prompt, switch to the directory that you installed PHP to by running cd C:\php\
Then install PEAR by running php go-pear.phar
Press Enter to accept the default when it asks you “Are you installing a system-wide PEAR or a local copy?”
Press Enter again to accept the file layout.
Press Enter to finish.
Run the following commands (they may take a while to update, be patient):
pear channel-update pear.php.net
pear upgrade-all
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear update-channels
Clear your pear cache pear clear-cache
To install PHPUnit, run pear install --alldeps --force phpunit/PHPUnit
To test that PHPUnit was successfully installed, run phpunit -v
Old answer (2014):
It's said that phpunit will not be available via PEAR since December 2014.
So it's easy to install it using composer:
composer global require "phpunit/phpunit=4.1.*"
Update 2019: it should be installed as a local (for your project) development package:
composer require --dev phpunit/phpunit ^8
Update 2020: it should be installed as a local (for your project) development package:
composer require --dev phpunit/phpunit ^9.3
As said by #Wilt Installation via pear doesn't works any longer. Follow below steps instead
Step I: Create a directory named bin in C drive.
Step II: Now add the path C:\bin to your environment.
To do this click on Windows icon and right click on Computer and then
select Properties.
Then click on Advanced system settings -> Advanced
-> Environment Variables.
In the System variables section scroll down and select the line where the Variable column value is Path. Click on
Edit.
Now add (append at the end) ;C:\bin at the end.
Step III: Download phpunit phar file to C:\bin folder.
If you are PHP 7 then download the phar file from
https:// phar.phpunit.de/phpunit-6.2.phar.
Else if you are using PHP
5.6 then download the phar file from https:// phar.phpunit.de/phpunit-5.7.phar.
Once downloaded rename the
file to phpunit.phar and move it to C:\bin folder.
Step IV: Create a batch script phpunit.cmd
Open command prompt. Type cd C:\bin and hit enter.
Then type
echo #php "%~dp0phpunit.phar" %* > phpunit.cmd and hit enter.
To verify PHPUnit has been installed type phpunit --version in command prompt. You should get something like PHPUnit x.y.z by Sebastian Bergmann and contributors.
Reference: https://perials.com/installing-phpunit-windows/
I use Windows XP.
I wasted a lot of time trying to use pear (the proscribed method to get MakeGood working with Eclipse IDE), only to discover the repository for phpunit is no longer available. This information should be nearer the top of this page so people do not waste their time too.
I installed phpunit via the download at https://phpunit.de/ and following the accompanying instructions. By adding the path to the command file to PATH I can now run phpunit from the command line. I have not however got phpunit running in MakeGood/Eclipse. Much of the information on that is out-of-date as it requires pear.
Try this in Windows Subsystem for Linux (wsl):
sudo apt install phpunit

Getting codeception & phpunit working on MAMP with OS X Lion

Running:
MAMP 2.0.5
PHP 5.3.6 (bundled with MAMP)
Mac OS X Lion 10.7.2
My goal is to get the Codeception testing framework to work and use within my MAMP project. I'm following the instructions here on how to install it.
Pear is installed and working fine. I am able to get Codeception installed with these commands:
$ pear channel-discover codeception.com/pear
$ pear install codeception/Codeception
Once installed when I try to run the codecept commands I get the following error:
Warning: require_once(Codeception/autoload.php): failed to open stream: No such file or directory in /usr/bin/codecept on line 12
Fatal error: require_once(): Failed opening required 'Codeception/autoload.php' (include_path='.:') in /usr/bin/codecept on line 12
I think that the issue is caused by either:
A conflict between MAMP's PHP installation in the one bundled with OS X
An issue with the include_path in my php.ini or somewhere else
Also of interest
When I run the $ phpunit command from inside my project folder I get -bash: phpunit: command not found but if I run it as $ /Applications/MAMP/bin/php/php5.3.6/bin/phpu
nit it works just fine.
I would expect there to be a codecept file in /Applications/MAMP/bin/php/php5.3.6/bin/ but there isn't - there is however a Codeception folder in /Applications/MAMP/bin/php/php5.3.6/lib/php
I've tried a few different ways to install it, and I guess one of the ways installed Codeception in Lion's copy of php (as opposed to MAMP's) - so I do have a codecept file in /usr/bin/ as well as the Codeception folder in /usr/lib/php/pear/
For reference:
PHP lives here: /Applications/MAMP/bin/php/php5.3.6/bin/php
Pear lives here: /Applications/MAMP/bin/php/php5.3.6/bin/pear
PHPUnit lives here: /Applications/MAMP/bin/php/php5.3.6/bin/phpunit
Any Help? Suggestions?
Thanks to Davert's help - I was able to confirm that this is a conflict with MAMP's copy of PHP and Lion's built-in copy of PHP. To solve the issue I created a new php.ini file in /etc that was a duplicate of php.ini.default and changed the include_path to /Applications/MAMP/bin/php/php5.3.6/lib/php
I think the problem is: your PEAR command was executed from bundled PHP. So your primary MAMP PHP libraries in (/Applications/MAMP/bin/php/php5.3.6/bin/pear) were not updated. I suggest you should find the second PEAR were the Codeception was exctually stored. And add path to it into 'include_path' in php.ini.
Yes, PEAR is quite buggy. In next releases a Composer installator will be added.
Also, you can try to use Phar executable.
In this case a Codeception should be executed with:
php codecept.phar
One solution that worked for me was to edit /Applications/MAMP/bin/php5.3/bin/codecept and replace /usr/bin/php at the first line by /Applications/MAMP/bin/php5.3/bin/php

Zend - cannot find PHPUnit/framework.php

I am running OSX Lion with an installation of XAMPP. Setting up PEAR with XAMPP has proven to be difficult, but I got it work and installed PHPUnit. When I look in the XAMPP pear directory I see a folder called 'PHPUnit', and when I look in that folder, I see the following files:
Assert.php
RepeatedTest.php
TestCase.php
TestFailure.php
TestResult.php
GUI
Skeleton.php
TestDecorator.php
TestListener.php
TestSuite.php
When I run zf create project myproject, I get the following message:
Warning: require_once(PHPUnit/Framework.php): failed to open stream: No such file or directory in /Users/frankie/Websites/Libraries/ZendFramework-1.11.10/library/Zend/Test/PHPUnit/ControllerTestCase.php on line 29
I have no idea where to get this Framework.php file or how to fix this. Any help is appreciated.
Zend Framework requires you to run PHPUnit 3.5.x and I assume you have installed PHPUnit 3.6.x from pear.
Check out the guide on how to downgrade-phpunit-3-6-to-3-5-15 to fix your issue when running the ZF1 tests
Check your bootstrap.php and disable fallback autoloader:
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(false);
I also had to uninstall phing and replace it by an older version:
sudo pear uninstall phing/phing
sudo pear install phing/phing-2.3.3

Categories