5
votes

Phpunit is working correctly in a basic project but when I try to use in yii functional test, I get this error: PHP Fatal error: Call to undefined method PHPUnit_Framework_Warning::setupSpecificBrowser() in ~/phpunit/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumBrowserSuite.php on line 95

I installed phpunit using composer. Version: PHPUnit 4.0.17 by Sebastian Bergmann. Selenium version: 2.41.0

I run selenium like this: java -jar selenium-server-standalone-2.41.0.jar

I run test class like this: ~/phpunit/vendor/bin/phpunit functional/SiteTest.php

In basic project code:

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());
    }

}

Yii code:

class WebTestCase extends CWebTestCase
{
    protected function setUp()
    {
        parent::setUp();
        $this->setBrowserUrl(Yii::app()->params['url']['base']);
    }
}

Also CWebTestCase class exteds PHPUnit_Extensions_SeleniumTestCase class, not PHPUnit_Extensions_Selenium2TestCase.

2

2 Answers

0
votes

It may depends on the version of PHPUnit. I know that Yii 1.1.x has problems with latest versions of PHPUnit and you have to install an old one.

You can do it in two ways:

PEAR (deprecated):

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 (better):

create a composer.json file, put it in protected with this content:

{                                                                                                                                        
  "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"
  }
}

and run composer install.

If you go for composer, remember that you have to add require_once('../vendor/autoload.php'); in your classes and that PHPUnit binaries will be in protecte/vendor/bin

0
votes

I got the same error for a different reason. My test file contained a private method whose name started with "test". I changed the method name to something else (because it wasn't meant to be a phpunit/selenium test) and it worked fine. It also ran fine when I set it to public.

It doesn't look like this was the problem for the original poster, but I figured I'd put this here in case anyone else had my same problem.