【问题标题】:PHP - Fatal error: Class 'PHPUnit_Framework_TestPHP - 致命错误:类 'PHPUnit_Framework_Test
【发布时间】:2012-05-17 01:35:34
【问题描述】:

所以我开始使用 PHPUnit 来测试我的程序。

我遇到了这个问题,当我尝试测试一个程序将控制网页是否存在时出现错误。

代码:

<?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;  
    }  
}  
?>

以及它的测试代码:

<?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);  
  }  
}  
?> 

它们在同一个目录下名为:PHPUnit inside the www (C:\wamp\www\PHPUnit)

但我不明白为什么我会收到错误(致命错误:第 5 行的 C:\wamp\www\PHPUnit\RemoteConnectTest.php 中找不到类 'PHPUnit_Framework_TestCase')

我的PHPUnit包路径是(C:\wamp\bin\php\php5.3.10\pear\PHPUnit)

我尝试制作一个程序 MailSender,它发送一封邮件,其中包含文本内容,这只是为了使用 PEAR。它成功了,但我不明白为什么这不起作用。

问候 亚历克斯

【问题讨论】:

  • 我大约 1 小时后回来,很快!
  • 谢谢你告诉我,我以为其他人会为我这样做,谢谢!!

标签: php phpunit pear fatal-error testcase


【解决方案1】:

您不需要在 RemoteConnectTest.php 中提供 PHPUnit_Framework_TestCase 类吗?

在文件顶部添加以下内容:

require_once 'PHPUnit/Autoload.php';

【讨论】:

  • 谢谢你,但后来我遇到了另一个问题解析错误:语法错误,第 3 行 C:\wamp\www\PHPUnit\RemoteConnectTest.php 中的意外 T_REQUIRE_ONCE
  • 我是否需要 Autoload.php 的绝对路径??
  • 检查您的 php.ini include_path,您应该包含 PEAR。请参阅 PEAR 手册中的Verifying the include path
  • 别忘了加分号“;”在 require_once 之后
猜你喜欢
  • 2012-01-12
  • 2013-03-21
  • 1970-01-01
  • 2015-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多