How do I solve this error: "Class PHPUnit_Extensions_SeleniumTestCase could not be found"
Asked Answered
M

10

12

I am trying to run a SeleniumTestCase with phpunit but I cannot get it to run with the phpunit.bat script.

My goal is to use phpunit with Selenium RC in CruiseControl & phpUnderControl. This is what the test looks like:

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class WebTest extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setBrowser('*firefox');
        $this->setBrowserUrl('http://www.example.com/');
    }

    public function testTitle()
    {
        $this->open('http://www.example.com/');
        $this->assertTitleEquals('Example Web Page');
    }
}

I also got PEAR in the include_path and PHPUnit installed with the Selenium extension. I installed these with the pear installer so I guess that's not the problem.

Any help would be very much appreciated.

Thanks, Remy

Modeling answered 16/9, 2008 at 22:15 Comment(1)
for what ever reason I can not find PHPUnit_Extensions_SeleniumTestCase in /PEAR/PHPUnit/Extensions/SeleniumTestCase.php, isn't it supposed to be there?Battled
B
16

hopefully this is a more definitive answer then the ones given here (which did not solve me problem). If you are getting this error, check your PEAR folder and see if the "SeleniumTestCase.php" file is actually there:

/PEAR/PHPUnit/Extensions/SeleniumTestCase.php

If it is NOT, the easiest thing to do is to uninstall and reinstall PHPUnit using PEAR ...

pear uninstall phpunit/PHPUnit

pear uninstall phpunit/PHPUnit_Selenium

pear install phpunit/PHPUnit

After doing the above and doing just the single install, PHPUnit_Selenium was also auto installed, I'm not sure if this is typical, so some might have to do...

pear install phpunit/PHPUnit_Selenium

Also see http://www.phpunit.de/manual/3.5/en/installation.html for PEAR channel info if needed...

Battled answered 15/12, 2010 at 23:39 Comment(4)
This is what I needed to do in order to fix this, thanks farinspace.Enamor
well that uninstalled phpunit but now it says no releases available...greatBignonia
using pear install phpunit/PHPUnit gave this error : invalid package name/package file phpunit/PHPUnit```Michaels
while I have not used phpunit in some time, i think the best way going forward would be to use the phar package, see github.com/sebastianbergmann/phpunitBattled
A
6

Here is the deal:

If you have a "Class PHPUnit_Extensions_SeleniumTestCase could not be found in (testcase file name)" problem, you have to do the following two things:

1. Rename the file of test case to the name of the class it contains 2. You should launch phpunit from the folder with your tests.

This should fix your problem.

Andrew

Artis answered 23/1, 2009 at 11:4 Comment(0)
E
1

I found that the following sample from PHPUnit tutorial was working while the same error appeared in the test that I had written. The solution was a surprise. Ensure that your class is inside a <?php .. ?> block and not a <? .. ?> block in the script.

<?php
require_once 'PHPUnit/Framework.php';

class StackTest extends PHPUnit_Framework_TestCase
{
    public function testPushAndPop()
    {
        $stack = array();
        $this->assertEquals(0, count($stack));

        array_push($stack, 'foo');
        $this->assertEquals('foo', $stack[count($stack)-1]);
        $this->assertEquals(1, count($stack));

        $this->assertEquals('foo', array_pop($stack));
        $this->assertEquals(0, count($stack));
    }
}
?>
Earwitness answered 16/9, 2008 at 22:15 Comment(1)
Also, try the flag --syntax-check for PHPUnit on the command line. Otherwise, PHPUnit may silently ignore the errors in your program.Earwitness
C
1

Have a look at one of the comments in the require_once entry in the php manual..

http://ie.php.net/manual/en/function.require-once.php#62838

"require_once (and include_once for that matters) is slow

Furthermore, if you plan on using unit tests and mock objects (i.e. including mock classes before the real ones are included in the class you want to test), it will not work as require() loads a file and not a class."

Carbazole answered 16/9, 2008 at 22:30 Comment(0)
M
1

I just renamed the file my test was in to "WebTest.php" (the name of the class it contains) and the test runs fine now.

Modeling answered 16/9, 2008 at 22:43 Comment(0)
T
1

Do not presume that the pear install occurred without problems.

I had installed phpunit through pear but despite it saying the install went fine when I looked inside the folder, I had all these files starting with .tmp, eg PHPUnit/Util/.tmpErrorHandler.php so naturally when i ran a test for the 1st time it gave me the same error as above. After checking that indeed the file wasn't there I did a manual install of PHPUnit to the same folder as pear and alas, all was fine. I'm in Mac/leopard.

About Selenim RC don't forget to start it by running in terminal java -jar /path/to/file/selenium-server.jar

Tallage answered 26/2, 2009 at 14:30 Comment(0)
E
1

Here is how i solved this problem:

  1. Make sure that curl extension for php is installed, e.g for ubuntu sudo apt-get install php5-curl
  2. Enter sudo pear install phpunit/PHPUnit_Selenium

After that you should have the missing file installed

Happy coding...

Eulogize answered 30/1, 2012 at 5:31 Comment(0)
L
1

Try:

class WebTest extends \PHPUnit_Extensions_Selenium2TestCase

It can be namespace issue, as it was for me.

Laurelaureano answered 1/10, 2014 at 15:53 Comment(0)
O
0

Well when I use inline command : if lauching test from PhPunit dir i have the error while whent launching it from test dir I havne't the error ...

but I still haven't any acces to selenium server ... shall I have to launch it before or not.

If Yes it's strange that we havne't to specify any handle to PhPUnit ...

Overrate answered 8/1, 2009 at 17:3 Comment(0)
B
0

When it fails it doesn't always print out the most verbose error messages.

Always remember to start Selenium too prior to running test.

java -jar selenium-server-standalone-2.39.0.jar

Here is an example of code that was working for myself. http://www.siteconsortium.com/h/p1.php?id=php002. Obviously there are a lot of different way to write the test suite, and launch the test case but I used the set_class_path to get rid of class issues at first.

Baillargeon answered 5/2, 2014 at 3:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.