2

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

2
  • I'll be back in about 1 hour, cya soon! Commented May 8, 2012 at 14:40
  • thanks for telling me that, I thought that others did that for me, thanks tho!! Commented May 8, 2012 at 18:58

1 Answer 1

3

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';
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for that, but then I come into another problem Parse error: syntax error, unexpected T_REQUIRE_ONCE in C:\wamp\www\PHPUnit\RemoteConnectTest.php on line 3
do I need maybe the absolute path for Autoload.php??
check your php.ini include_path, you should have PEAR included. See Verifying the include path from the PEAR manual.
and don't forget to add the semicolon ";" after the require_once

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.