致命错误:找不到类“PHPUnit_Extensions_Database_TestCase”

时间:2014-06-02 01:16:38

标签: php phpunit

我跟随documentation of PHPUnit;我尝试以下示例;但它一直给我以下错误:

  

"致命错误:Class" PHPUnit_Extensions_Database_TestCase"没找到!

它适用于PHPUnit_Framework_TestCase!我还添加了

require_once 'PHPUnit/Autoload.php';

但仍然是同样的错误!

<?php
class MyGuestbookTest extends PHPUnit_Extensions_Database_TestCase
{
    /**
     * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
     */
    public function getConnection()
    {
        $pdo = new PDO('sqlite::memory:');
        return $this->createDefaultDBConnection($pdo, ':memory:');
    }

    /**
     * @return PHPUnit_Extensions_Database_DataSet_IDataSet
     */
    public function getDataSet()
    {
        return $this->createFlatXMLDataSet(dirname(__FILE__).'/_files/guestbook-seed.xml');
    }
}
?>

更新:

实际上我对PHPUnit测试很新:

我使用了PHP的Slim框架:我还没有开始测试;只是试图通过阅读文档来理解逻辑;我有一个composer.json文件,如下所示:(现在我添加了#34; phpunit / dbunit&#34;:&#34;&gt; = 1.2&#34;在require / require-dev中,但没有他们解决了这个问题!):

{
    "name": "slim/slim",
    "type": "library",
    "description": "Slim Framework, a PHP micro framework",
    "keywords": ["microframework","rest","router"],
    "homepage": "http://github.com/codeguy/Slim",
    "license": "MIT",
    "authors": [
        {
            "name": "Josh Lockhart",
            "email": "info@joshlockhart.com",
            "homepage": "http://www.joshlockhart.com/"
        }
    ],
    "require": {        
        "php": ">=5.3.0"
    }
    ,"require-dev": {        
        "phpunit/dbunit": ">=1.2"
    },
    "suggest": {
        "ext-mcrypt": "Required for HTTP cookie encryption"
    },
    "autoload": {
        "psr-0": { "Slim": "." }
    }
}

如果您需要更多说明,请提前告知我并提前感谢。

1 个答案:

答案 0 :(得分:8)

如果您使用的是Composer,请务必添加DBUnit可选包。

所有功劳都归功于Phil的评论!