Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 618
Alan Avatar asked May 09 '14 15:05

Alan


2 Answers

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=*'
like image 92
Manquer Avatar answered Oct 04 '22 06:10

Manquer


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.

like image 30
Alan Avatar answered Oct 04 '22 08:10

Alan