This question is local to my situation and is not resolved (yet). But if you run into this problem, troubleshooting steps can give you a good way to start.
I want to run unit test in a Yii web application on localhost, which works through WampServer 2.1 on Windows 7.
<?php class LittleTest extends CTestCase { public function testApprove() { $value1 = "1"; $this->assertEquals($value1,$value1); } } ?>
I get a fatal error when I try to run a test. This is how I run it on a windows command prompt:
C:\wamp\www\app\protected\tests> C:\wamp\www\app\protected\tests>cd unit C:\wamp\www\app\protected\tests\unit>phpunit LittleTest.php
I get (along with several trace lines):
PHP Fatal error: class 'CTestCase' not found in [path to file]\LittleTest.php on line 4
Troubleshooting steps:
The application starts. By default, the application index page looks good, and I used the gii tool to create the model class.
From the command line, I see that php and phpunit are available (and I was on my pear installation to make sure all this is good):
C:\wamp\www\app\protected\tests> C:\wamp\www\app\protected\tests>phpunit --version PHPUnit 3.7.13 by Sebastian Bergmann. C:\wamp\www\app\protected\tests> C:\wamp\www\app\protected\tests>php --version PHP 5.3.5 (cli) ... etc
display_errors turned on. display_startup_errors on.
I tried renaming the class so that the name does not match the name of the document:
class LittleTestTweak extends CTestCase
I'm not sure about the exact command that runs the test, so I tried the options:
php LittleTest.php
I also tried to run it in different places in the folder structure. Here is the closest structure:
/tests | bootstrap.php | my_tree.txt | phpunit.xml | WebTestCase.php | |---- /fixtures |---- /functional | SiteTest.php | |---- /report `---- /unit LittleTest.php
I also checked my php.ini for the path to PEAR; as far as I can tell, this is correct (but how can I check it?):
include_path=".;C:\wamp\bin\php\php5.3.5\PEAR;C:\wamp\www\app
More details
In response to this:
cd wamp\www\app\protected\tests phpunit unit\LittleTest.php
I get this:
Warning: require_once(PHPUnit/Extensions/SeleniumTestCase.php): failed to open stream: No such file or directory in C:\wamp\www\yii\framework\test\CWebTestCase.php on line 12 Call Stack: 0.0007 339624 1. {main}() C:\wamp\bin\php\php5.3.5\phpunit:0 0.0164 698440 2. PHPUnit_TextUI_Command::main() C:\wamp\bin\php\php5.3.5\phpunit:46 0.0164 698856 3. PHPUnit_TextUI_Command->run() C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:129 0.0164 698856 4. PHPUnit_TextUI_Command->handleArguments() C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:138 0.0289 1220944 5. PHPUnit_TextUI_Command->handleBootstrap() C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:606 0.0300 1233328 6. PHPUnit_Util_Fileloader::checkAndLoad() C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:778 0.0330 1233424 7. PHPUnit_Util_Fileloader::load() C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\Util\Fileloader.php:76 0.0334 1238096 8. include_once ('C:\wamp\www\app\protected\tests\bootstrap.php') C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\Util\Fileloader.php:92 0.0412 1520256 9. require_once ('C:\wamp\www\app\protected\tests\WebTestCase.php') C:\wamp\www\app\protected\tests\bootstrap.php:8 0.0413 1520520 10. YiiBase::autoload() C:\wamp\www\yii\framework\YiiBase.php:0 0.0423 1543904 11. include('C:\wamp\www\yii\framework\test\CWebTestCase.php') C:\wamp\www\yii\framework\YiiBase.php:395 Fatal error: require_once(): Failed opening required 'PHPUnit/Extensions/SeleniumTestCase.php' (include_path='.;C:\wamp\bin\php\php5.3.5\PEAR\pear;C:\wamp\bin\php\php5.3.5\pear') in C:\wamp\www\yii\framework\test\CWebTestCase.php on line 12 Call Stack: 0.0007 339624 1. {main}() C:\wamp\bin\php\php5.3.5\phpunit:0 0.0164 698440 2. PHPUnit_TextUI_Command::main() ...et cetera...
The defective requirement is PHPUnit/Extensions/SeleniumTestCase.php . Interestingly, the problem is that PHPUnit is installed locally in C:\wamp .
I opened my php.ini and added to include_path : C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\Extensions . Restarted howl. No change in error messages.
Decision
My security setting uses DansGuardian, and I forgot to loosen the settings for forbidden extension types that block file downloads. Actually, I donβt want to forbid any types, and changing this file allows everyone to work. Woops that my Linux is installed. PHPUnit works there, and it works with WAMP. Re-creating steps on WAMP is not possible; but I know that I had to open cmd.exe as an administrator and pear update-channels , pear upgrade-all , etc. I also had to clear the cache cache at some point, and I had to overcome the twist problem by installing Selenium:
pear install