title: Fatal error running unit test in Yii app
body: <p><strong>This Question</strong> is local to my situation and not resolved (yet).  But if you are experiencing this problem, the trouble shooting steps may give you a good path to start on.</p>
  
  <hr>
  
  <p>I want to run a unit test in a Yii web application on localhost, which is running via WampServer 2.1 on Windows 7. </p>
  
  <pre><code>&lt;?php
  class LittleTest extends CTestCase
  {
      public function testApprove()
      {
          $value1 = "1";
          $this-&gt;assertEquals($value1,$value1);
      }
  }
  ?&gt;
  </code></pre>
  
  <p>I receive a fatal error when I try to run the test.  Here is how I run it, on the Windows command line:</p>
  
  <pre><code>C:\wamp\www\app\protected\tests&gt;
  C:\wamp\www\app\protected\tests&gt;cd unit
  C:\wamp\www\app\protected\tests\unit&gt;phpunit LittleTest.php
  </code></pre>
  
  <p>I receive (along with some stack trace lines):</p>
  
  <pre><code>PHP Fatal error:  
  class 'CTestCase' not found in [path to file]\LittleTest.php on line 4
  </code></pre>
  
  <p><strong>Trouble shooting steps to this point:</strong></p>
  
  <p>The app runs.  The default index page of the app looks good and I have used the gii tool to create a model class.</p>
  
  <p>From command line, I can see <code>php</code> and <code>phpunit</code> are available (and I've been over my pear install to make sure it's all good):</p>
  
  <pre><code>C:\wamp\www\app\protected\tests&gt;
  C:\wamp\www\app\protected\tests&gt;phpunit --version
  PHPUnit 3.7.13 by Sebastian Bergmann.
  
  C:\wamp\www\app\protected\tests&gt;
  C:\wamp\www\app\protected\tests&gt;php --version
  PHP 5.3.5 (cli) 
  ... etc
  </code></pre>
  
  <p><code>display_errors</code> is turned on.  <code>display_startup_errors</code> is turned on.</p>
  
  <p>I tried renaming the class so that name did not match the document name:</p>
  
  <pre><code>class LittleTestTweak extends CTestCase 
  </code></pre>
  
  <p>I'm not sure of the precise command that runs the test, so I have tried variants like:</p>
  
  <p><code>php LittleTest.php</code>  </p>
  
  <p>Also I've tried running it various places in the folder structure.  Here is the immediate structure:</p>
  
  <pre><code>/tests
      |   bootstrap.php
      |   my_tree.txt
      |   phpunit.xml
      |   WebTestCase.php
      |   
      |---- /fixtures
      |---- /functional
      |         SiteTest.php
      |       
      |---- /report
      `---- /unit
                LittleTest.php
  </code></pre>
  
  <p>I also checked my <code>php.ini</code> for the path to PEAR; as far as I can tell, it's correct (but how can I test it?):</p>
  
  <pre><code>include_path=".;C:\wamp\bin\php\php5.3.5\PEAR;C:\wamp\www\app
  </code></pre>
  
  <h2>More Info</h2>
  
  <p>In response to this:</p>
  
  <pre><code>cd wamp\www\app\protected\tests
  phpunit unit\LittleTest.php
  </code></pre>
  
  <p>I receive this:</p>
  
  <pre><code>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-&gt;run() 
                 C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:129
          0.0164     698856   4. PHPUnit_TextUI_Command-&gt;handleArguments() 
                 C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:138
          0.0289    1220944   5. PHPUnit_TextUI_Command-&gt;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...
  </code></pre>
  
  <p>The failed requirement is <code>PHPUnit/Extensions/SeleniumTestCase.php</code>.  I wonder if the issue is that PHPUnit is installed locally under <code>C:\wamp</code>.</p>
  
  <p>I opened my <code>php.ini</code> and added to <code>include_path</code>:  <code>C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\Extensions</code>.  Restarted wamp.  No change in error reporting.</p>
  
  <h2>RESOLUTION</h2>
  
  <p><strike>My security setup uses DansGuardian and I had neglected to loosen the settings for banned extension types, which blocks file downloads.  In fact I don't care to ban any types, and modifying that file allows everything to work.</strike> Woops, that's my Linux set.  PHPUnit is working there, and it is working on WAMP also.  Recreating the steps on WAMP is impossible; but I do know I had to <a href="http://www.mydigitallife.info/how-to-open-elevated-command-prompt-with-administrator-privileges-in-windows-vista/" rel="nofollow noreferrer">open cmd.exe as administrator</a> and <code>pear update-channels</code>, <code>pear upgrade-all</code>, etc.  I also had to <a href="http://www.mark-leong.com/installing-php-and-phpunit-on-windows-7/" rel="nofollow noreferrer">clear pear's cache</a> at one point, and I had to <a href="https://stackoverflow.com/a/8496478/122139">overcome an issue with curl</a> recognition to install Selenium:  </p>
  
  <pre><code>pear install --force phpunit/PHPUnit_Selenium
  </code></pre>