Pregunta

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?

¿Fue útil?

Solución 2

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.

Otros consejos

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=*'

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top