Alexein
Alexein

Reputation: 686

PHP - Fatal error: Class 'PHPUnit_Framework_Test

So I have started to use PHPUnit to test my programs.

I have this problem where I get an error when I try to test a program where the program is gonna control if a webpage exists.

The code:

<?php
class RemoteConnect  
{  
    public function connectToServer($serverName=null)  
    {  
        if($serverName==null){  
          throw new Exception("That's not a server name!");  
        }  
        $fp = fsockopen($serverName,80);  
        return ($fp) ? true : false;  
    }  
    public function returnSampleObject()  
    {  
      return $this;  
    }  
}  
?>

And the test code to it:

<?php  
require_once('RemoteConnect.php');  
class RemoteConnectTest extends PHPUnit_Framework_TestCase  
{  
  public function setUp(){ }  
  public function tearDown(){ }  
  public function testConnectionIsValid()  
  {  
    // test to ensure that the object from an fsockopen is valid  
    $connObj = new RemoteConnect();  
    $serverName = 'www.google.com';  
    $this->assertTrue($connObj->connectToServer($serverName) !== false);  
  }  
}  
?> 

They are in the same directory named: PHPUnit inside the www (C:\wamp\www\PHPUnit)

But I don't understand why i get the error (Fatal error: Class 'PHPUnit_Framework_TestCase' not found in C:\wamp\www\PHPUnit\RemoteConnectTest.php on line 5)

My PHPUnit package path is (C:\wamp\bin\php\php5.3.10\pear\PHPUnit)

I have tried making a program MailSender, where it sends a mail with a text content in it, that was just for using PEAR. And it succeded, but I don't understand why this doesn't work.

Regards Alex

Upvotes: 2

Views: 4376

Answers (1)

Boby
Boby

Reputation: 822

Don't you need to have the PHPUnit_Framework_TestCase class available in RemoteConnectTest.php?

Add the following on top of the file:

require_once 'PHPUnit/Autoload.php';

Upvotes: 3

Related Questions