phpunit在一个基本项目中工作正常,但当我尝试在yii功能测试中使用时,会出现以下错误:
php致命错误:调用第95行~/phpunit/vendor/phpunit/phpunit selenium/phpunit/extensions/seleniumbrowsersuite.php中的未定义方法phpunit_framework_warning::setupSpecificBrowser()
我用composer安装了phpunit。版本:Sebastian Bergmann的phpunit 4.0.17。
硒版本:2.41.0
我运行这样的硒:Java- jar硒服务器标准-1 2.41.0.jar
我运行这样的测试类:~/phpunit/vendor/bin/phpunit functional/sitetest.php
在基本项目代码中:
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://www.example.com/');
}
public function testTitle()
{
$this->url('http://www.example.com/');
$this->assertEquals('Title string', $this->title());
}
}
彝语编码:
class WebTestCase extends CWebTestCase
{
protected function setUp()
{
parent::setUp();
$this->setBrowserUrl(Yii::app()->params['url']['base']);
}
}
另外,cWebTestCase类扩展了phpunit_seleniumtestcase类,而不是phpunit_selenium2testcase扩展。
最佳答案
这可能取决于phpunit的版本。我知道yi1.1.x有问题,最新版本的phpunit,你必须安装一个旧的。
你可以用两种方法:
梨(已弃用):
sudo pear config-set auto_discover 1
sudo pear channel-discover pear.phpunit.de
sudo pear install phpunit/PHPUnit-3.7.1
sudo pear install phpunit/DbUnit
sudo pear install phpunit/PHPUnit_Selenium
sudo pear install phpunit/PHPUnit_Story
sudo pear install phpunit/PHP_Invoker
作曲家(更好):
创建一个
composer.json
文件,将其放入包含以下内容的protected
中:{
"require" : {
"phpunit/phpunit": "3.7.x-dev"
"phpunit/dbunit": "1.3.*@dev",
"phpunit/phpunit-selenium": "dev-master",
"phpunit/phpunit-story": "dev-master",
"phpunit/php-invoker": "dev-master"
}
}
然后运行
composer install
。如果您选择composer,请记住必须在类中添加
require_once('../vendor/autoload.php');
,并且phpunit二进制文件将位于protecte/vendor/bin