PHPUnit complains about Selenium - php

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.

Related

ERROR: Your system is not ready to run Symfony projects

I've downloaded a Symfony application and then checked it using php -f ./app/check.php. However, I get:
[ERROR]
Your system is not ready to run Symfony projects
Fix the following mandatory requirements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Vendor libraries must be installed
> Vendor libraries are missing. Install composer following
> instructions from http://getcomposer.org/. Then run "php
> composer.phar install" to install them.
However, there is no composer.phar file in this application. e.g.
php composer.phar install
Could not open input file: composer.phar
Note: I already have composer installed.
Any suggestions?
The answer is right there in the error message you received.
Install composer following instructions from http://getcomposer.org/
Instead of composer.phar run:
php composer install
I think that's what you need. If you install Composer, then you probably renamed it to composer, and that's the bin you run.

PHPUnit not working with Laravel 5

I just installed a fresh Laravel 5 project, my first one on this version. PHPUnit is supposed to be out of the box with the framework and every tutorials I saw just say to type phpunit within the project folder to launch the Unit Tests.
I checked and PHPUnit is in the composer.json, I also did a composer install and composer update just in case it wouldn't be here
website(master)$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing phpunit/phpunit (4.6.1)
- Installing phpunit/phpunit (4.6.2)
Downloading: 100%
But it just doesn't work phpunit isn't recognized at all
website(master)$ phpunit
-bash: phpunit: command not found
Seems like nobody got this problem before as I Googled it. I hope I'm not doing any stupid mistake. Any idea or suggestion ? Thanks guys ;)
I didn't install PHPUnit globally and didn't define the path. So for anyone who would have same problem :
composer global require phpunit/phpunit
composer global require phpunit/dbunit
Then you add this to you ~/.bash_profile or ~/.profile
export PATH=~/.composer/vendor/bin:$PATH
This occurs when you don't have phpunit installed globally.
Run this command to use the local version (installed with composer):
vendor/bin/phpunit
in windows machine the command is different please use this command
php vendor/phpunit/phpunit/phpunit
orignal source
You can run this command in cmd before running phpunit command:
doskey phpunit="vendor/bin/phpunit"
And if you are lazy as I am, you can run this one:
doskey pu="vendor/bin/phpunit"
for people who have WINDOWS 7, use the .\vendor\bin\phpunit command instead of ./vendor/bin/phpunit
Run the command
composer config --list --global | grep -w home
You can find the find the [home] with composer path, similar to this one.
[home] /home/example_username/.config/composer
The path ~/.config/composer is where composer global packages are installed. Next run the command...
export PATH=~/.config/composer/vendor/bin:$PATH
I made a permanent link to my phpunit like this
echo 'alias phpunit=vendor/bin/phpunit' >> ~/.bash_aliases
now phpunit is working by itself and stays even after I restart the terminal
Include this line on your composer.json
"phpunit/phpunit": "4.0.*",
Run composer update.
You should be able to run the following command on your Laravel directory.
vendor/bin/phpunit

PHPUnit and Ubuntu - Issues with include path after Installation with PEAR

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).

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

phpunit - wrong path

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

Categories