Cant get PHPUnit and selenium working correctly

Hopefully someone will be able to help me with this because I’ve been pulling my hair out for hours on this one…

Background:

I am reading the Agile Web Application Development Book and I’m up to the part about testing. In this book they recommend installing Selenium and PHPUnit

I have successfully installed Selenium R C

I’m running WAMP server 2.0 on Windows Vista

Problem:

I have tried to install PHPUnit 2 ways.

  1. The first way was through PEAR. PEAR managed to download it and install it okay…but when I try to run phpunit I get the following error message.

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

As far as I can tell this means that the phpunit executable file does not exist in my PATH environment variable. Trouble is, I cant find ANY phpunit executable file. It just doesn’t seem to exist…

  1. So I tried another way of installing it. I downloaded directly from GITHUB and extracted the archive to my computer. This time, I had more luck, I can get phpunit running (ie: There is an executable) but when I run it on a test case I get these error messages…

The command I ran


c:\wamp\www\yii\agile\protected\tests>phpunit functional/SiteTest.php

The error message


PHP Warning:  require_once(PHPUnit/Extensions/SeleniumTestCase.php): failed to o

pen stream: No such file or directory in C:\wamp\www\yii\framework\test\CWebTest

Case.php on line 11


Warning: require_once(PHPUnit/Extensions/SeleniumTestCase.php): failed to open s

tream: No such file or directory in C:\wamp\www\yii\framework\test\CWebTestCase.

php on line 11

PHP Fatal error:  require_once(): Failed opening required 'PHPUnit/Extensions/Se

leniumTestCase.php' (include_path='C:\wamp\bin\php\php5.3.0\PEAR;.;C:\wamp\bin\p

hp\php5.3.0\pear') in C:\wamp\www\yii\framework\test\CWebTestCase.php on line 11




Fatal error: require_once(): Failed opening required 'PHPUnit/Extensions/Seleniu

mTestCase.php' (include_path='C:\wamp\bin\php\php5.3.0\PEAR;.;C:\wamp\bin\php\ph

p5.3.0\pear') in C:\wamp\www\yii\framework\test\CWebTestCase.php on line 11

I have tried searching for that file (ie:SeleniumTestCase.php) on the net but can barely find any information on it. I can’t find it on my HD so where do I get a copy of it?

Does anyone know how to fix this problem? I’m completely stumped and I would be so grateful if someone could help me out.

Thanks heaps

Tom

SeleniumTestCase.php should be in the PHPUnit folder - "PHPUnit/Extensions/SeleniumTestCase.php".

I think you need to add the folder with PHPUnit to the PATH.

I managed to install and run php unit and Selenium on Windows, so it is definitely possible.

But now developing on Ubuntu where I just run




  pear channel-discover pear.phpunit.de

  pear install phpunit/PHPUnit



Thanks for your reply Seb,

That’s what I would expect…but it’s not. I’ve even uninstalled and reinstalled several times and it’s just not in there…

When you installed in Windows did you do so via PEAR or direct download?

Unfortunately I don’t remember how exactly I installed it.

But is seems that SeleniumTestCase goes from the separate package "PHPUnit_Selenium", see description here.

Thanks for your help Seb,

I have got it working now…

For anyone else who is having the same problem…

Using the pear installer doesn’t seem to work very well.

So I downloaded PHPUnit_Selenium and PHPUnit packages from pear.phpunit.de/

These are tgz files so you just unzip them to your include directory as specified in php.ini Make sure the phpunit_selenium file/folder structure is merged with the phpunit file/folder structure.

Then you should be good to go!

I’ve just been getting exactly the same error. I had removed phpunit using pear, then installed it using apt-get because I wanted an older version, then decided that version was too old, so I removed the version from the repos and installed an older version using pear. Because the selenium stuff is a dependency, but lives inside phpunit, and pear lets you uninstall phpunit without uninstalling the selenium stuff first the pear uninstall of phpunit breaks the pear installed PHPUnit_Selenium, but it remains installed. So that’s the root of the problem.

The fix is to uninstall them both, then reinstall phpunit which will then reinstall selenium.

For example… (I downgraded to 3.5.6 because I want --verbose to work like it used to.)


#sudo pear uninstall phpunit/PHPUnit_Selenium

uninstall ok: channel://pear.phpunit.de/PHPUnit_Selenium-1.0.2

#sudo pear install phpunit/PHPUnit-3.5.6

phpunit/PHPUnit can optionally use PHP extension "dbus"

downloading PHPUnit-3.5.6.tgz ...

Starting to download PHPUnit-3.5.6.tgz (112,204 bytes)

.........................done: 112,204 bytes

downloading PHPUnit_Selenium-1.0.2.tgz ...

Starting to download PHPUnit_Selenium-1.0.2.tgz (16,412 bytes)

...done: 16,412 bytes

install ok: channel://pear.phpunit.de/PHPUnit_Selenium-1.0.2

install ok: channel://pear.phpunit.de/PHPUnit-3.5.6

#

If this isn’t exactly the same problem as you had it is at least the same symptom…


PHP Warning:  require_once(PHPUnit/Extensions/SeleniumTestCase.php): failed to open stream: No such file or directory in...

I’m doing it on Debian 6.0.

Also had this issue windows 7 64bit after updating phpunit 3.5.14

I just downloaded the PHPUnit_Selenium files manually from Tommo’s link added it into the PHPUnit directory under pear and that did the trick.

In my case, PHPUnit was already installed. Trying


pear install phpunit/phpunit_selenium

returned


phpunit/phpunit_selenium is already installed and is the same as the released version 1.0.3

install failed



So I did


pear upgrade -f phpunit/phpunit_selenium

And it worked. PHPUnit runs without the error now.

In my windows experience:

First: it’s a batch file error. Goto PHP dir, find phpunit.bat and edit path in the file.

Second, the phpunit.bat must be in the executable path. Check path in command line in CMD windows.

Third, don’t fill anything in open_basedir in php.ini. Or you get open stream error in the php log.

Fourth, download and run selenium server in seperate windows:

 example: java -jar c:\php\bin\selenium-server-standalone-2.5.0.jar

and don’t close it unitl your test is done.

Finally, read the Agile book. The chapter 3 is working fine. Don’t miss any paragraphs. Don’t lost in space.

Hi, i have the error




PHP Fatal error:  require_once(): Failed opening required 'PHPUnit/Extensions/SeleniumTestCase.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/yiiTest/framework/test/CWebTestCase.php on line 11




if i do


pear install phpunit/phpunit_selenium

i have this error




PHPUnit 3.6.7 by Sebastian Bergmann.


Cannot open file "functional/PostTest.php".



i have ubuntu server 11.10

Thanks!

Google for it. phpunit seems to be broken on Ubuntu in the latest releases. Try this:

http://askubuntu.com/questions/40674/phpunit-stop-working-after-upgrade-to-11-04

Well Guys I’m also in same book and same chapter first I had following error :

[b]E:\xampp\htdocs\YiiRoot\protected\tests>phpunit functional/SiteTest.php

PHP Warning: require_once(PHPUnit/Extensions/SeleniumTestCase.php): failed to o

pen stream: No such file or directory in E:\xampp\htdocs\yii\framework\test\CWeb

TestCase.php on line 11

Warning: require_once(PHPUnit/Extensions/SeleniumTestCase.php): failed to open s

tream: No such file or directory in E:\xampp\htdocs\yii\framework\test\CWebTestC

ase.php on line 11

PHP Fatal error: require_once(): Failed opening required 'PHPUnit/Extensions/Se

leniumTestCase.php’ (include_path=’.;E:\xampp\php\PEAR’) in E:\xampp\htdocs\yii\

framework\test\CWebTestCase.php on line 11

Fatal error: require_once(): Failed opening required 'PHPUnit/Extensions/Seleniu

mTestCase.php’ (include_path=’.;E:\xampp\php\PEAR’) in E:\xampp\htdocs\yii\frame

work\test\CWebTestCase.php on line 11[/b]

and then following this forum user Tommo given some instructions to follow when did as it is I extracted the files from PHPUnit packages from pear.phpunit.de version 1.2.6 (stable) and copied to E:\xampp\php\PEAR\PHPUnit\Extensions to folder now when I execute the following line

E:\xampp\htdocs\YiiRoot\protected\tests>phpunit functional/SiteTest.php

I get this :

[b]

Configuration read from E:\xampp\htdocs\YiiRoot\protected\tests\phpunit.xml

PHP Warning: include(SiteTest: Firefox.php): failed to open stream: No such fil

e or directory in E:\xampp\htdocs\yii\framework\YiiBase.php on line 338

Warning: include(SiteTest: Firefox.php): failed to open stream: No such file or

directory in E:\xampp\htdocs\yii\framework\YiiBase.php on line 338

PHP Warning: include(): Failed opening ‘SiteTest: Firefox.php’ for inclusion (i

nclude_path=’.;E:\xampp\htdocs\YiiRoot\protected\components;E:\xampp\htdocs\YiiR

oot\protected\models;E:\xampp\php\PEAR’) in E:\xampp\htdocs\yii\framework\YiiBas

e.php on line 338

Warning: include(): Failed opening ‘SiteTest: Firefox.php’ for inclusion (includ

e_path=’.;E:\xampp\htdocs\YiiRoot\protected\components;E:\xampp\htdocs\YiiRoot\p

rotected\models;E:\xampp\php\PEAR’) in E:\xampp\htdocs\yii\framework\YiiBase.php

on line 338

SSSPHP Warning: include(SiteTest: Firefox.php): failed to open stream: No such

file or directory in E:\xampp\htdocs\yii\framework\YiiBase.php on line 338

Warning: include(SiteTest: Firefox.php): failed to open stream: No such file or

directory in E:\xampp\htdocs\yii\framework\YiiBase.php on line 338

PHP Warning: include(): Failed opening ‘SiteTest: Firefox.php’ for inclusion (i

nclude_path=’.;E:\xampp\htdocs\YiiRoot\protected\components;E:\xampp\htdocs\YiiR

oot\protected\models;E:\xampp\php\PEAR’) in E:\xampp\htdocs\yii\framework\YiiBas

e.php on line 338

Warning: include(): Failed opening ‘SiteTest: Firefox.php’ for inclusion (includ

e_path=’.;E:\xampp\htdocs\YiiRoot\protected\components;E:\xampp\htdocs\YiiRoot\p

rotected\models;E:\xampp\php\PEAR’) in E:\xampp\htdocs\yii\framework\YiiBase.php

on line 338

Time: 5 seconds, Memory: 5.00Mb

OK, but incomplete or skipped tests!

Tests: 3, Assertions: 0, Skipped: 3.

[/b]

please advice how to fix this problem.

I’m having the same probelm, did you ever find solution for this ?

I solved this problem simply by uninstalling all java programs through control panel and reinstalled java SDK, then redownloaded selenium RC server moved it to Java SDK installation folder / bin and started server from cmd: java -jar selenium.jar

code was throwing error because selenium wasn’t working correctly (couldn’t start browser)

install selenium after install phpunit with tuhis step:

C:\xampp\php>PEAR install phpunit/DbUnit

Open "php.in" (C:\xampp\php) and uncomment "extension=php_curl.dll"

C:\xampp\php>pear install phpunit/PHPUnit_Selenium

see following link for more info:

Latest PHPUnit-3.6.10 and Selenium server issue

Thanks a lot Sebastian, your


pear upgrade -f phpunit/phpunit_selenium

helped me lot to solve this problem.

It didn’t help me. I tried to reinstall all including Java SDK, PEAR, PHPUnit, Selenium… Several times. Tried all the ways I could find in Google. My configuration: Win7 x64, Apache 2.4.2, PHP 5.3.13, PEAR 1.9.4, PHPUnit 3.6.11 , PHPUnit_Selenium 1.2.7, selenium-server-standalone-2.22.0.jar, Yii 1.1.10.

It’s interesting that PHPUnit is working, tests are passing. But every time I see the next warnings in my console:

“Warning: include(): Failed opening ‘SigupTest: Firefox.php’ for inclusion (include_path=.;C:\{path_to_yii_application}\protected\components;C:\{path_to_yii_application}\protected\models;C:\usr\local\php\PEAR\pear;C:\usr\local\php\includes’) in C:\{path_to_yii_application}\framework\YiiBase.php on line 418”

Anybody knows the reason?

I am sure you already thought about that one but shouldn’t “SigupTest: Firefox.php” be “SignupTest: Firefox.php” Maybe this is a simple typo thing

I finally managed to setup phpUnit and Selenium on both Win7 and Ubuntu 12.04 with Netbeans.

Many of the problems mentioned above seem to be with how phpUnit was installed.

I found it only works properly if you use Pear.

However you installed it, if it’s still not working, uninstall and reinstall like this:




sudo pear channel-discover pear.phpunit.de


sudo pear uninstall phpunit/PHPUnit


sudo pear uninstall phpunit/PHPUnit_Selenium


sudo pear install phpunit/PHPUnit


// make sure curl is installed before the next command.


sudo pear install phpunit/PHPUnit_Selenium



Ignore the ‘sudo’ part if your Linux distro doesn’t need it or if using Windows.

If you’re using Netbeans, you will need to make sure you have the Selenium plugins installed. You don’t need the ‘Maven’ or ‘Ant’ plugins though.

I still have to figure out what the problem is with this:


"Warning: include(): Failed opening 'MyTest: Firefox.php' for inclusion..."

"Warning: include(): Failed opening 'MyTest: Chrome.php' for inclusion..."

The tests work regardless so no biggie.

Well after reviewing your problem i get one solution. I think you need to add the folder with PHPUnit to the PATH.