使用PHPUnit -Selenium Framework的数据库

时间:2017-01-10 09:21:22

标签: php phpunit

有人能为我提供一个完整的PHPUnit数据库测试源吗? 目前我指的是这个 Source

通过这样做我得到了这个错误:

PHP Warning:  require_once(ArticleDAO.php): failed to open stream: No such file or directory in /var/www/html/testing/ArticleDAOTest.php on line 3
PHP Stack trace:
PHP   1. {main}() /var/www/html/testing/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /var/www/html/testing/vendor/phpunit/phpunit/phpunit:52
PHP   3. PHPUnit_TextUI_Command->run() /var/www/html/testing/vendor/phpunit/phpunit/src/TextUI/Command.php:100
PHP   4. PHPUnit_Runner_BaseTestRunner->getTest() /var/www/html/testing/vendor/phpunit/phpunit/src/TextUI/Command.php:123
PHP   5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /var/www/html/testing/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:67
PHP   6. PHPUnit_Runner_StandardTestSuiteLoader->load() /var/www/html/testing/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:123
PHP   7. PHPUnit_Util_Fileloader::checkAndLoad() /var/www/html/testing/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php:39
PHP   8. PHPUnit_Util_Fileloader::load() /var/www/html/testing/vendor/phpunit/phpunit/src/Util/Fileloader.php:38
PHP   9. include_once() /var/www/html/testing/vendor/phpunit/phpunit/src/Util/Fileloader.php:56
PHP Fatal error:  require_once(): Failed opening required 'ArticleDAO.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/testing/ArticleDAOTest.php on line 3
PHP Stack trace:
PHP   1. {main}() /var/www/html/testing/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /var/www/html/testing/vendor/phpunit/phpunit/phpunit:52
PHP   3. PHPUnit_TextUI_Command->run() /var/www/html/testing/vendor/phpunit/phpunit/src/TextUI/Command.php:100
PHP   4. PHPUnit_Runner_BaseTestRunner->getTest() /var/www/html/testing/vendor/phpunit/phpunit/src/TextUI/Command.php:123
PHP   5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /var/www/html/testing/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:67
PHP   6. PHPUnit_Runner_StandardTestSuiteLoader->load() /var/www/html/testing/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:123
PHP   7. PHPUnit_Util_Fileloader::checkAndLoad() /var/www/html/testing/vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php:39
PHP   8. PHPUnit_Util_Fileloader::load() /var/www/html/testing/vendor/phpunit/phpunit/src/Util/Fileloader.php:38
PHP   9. include_once() /var/www/html/testing/vendor/phpunit/phpunit/src/Util/Fileloader.php:56

虽然我已将该文件包含在第3行。 我的完整源代码是:

<?php
require_once "PHPUnit/Autoload.php";
require_once "ArticleDAO.php";

class ArticleDAOTest extends PHPUnit_Extensions_Database_TestCase implements IArticleDAO
{
    public function getConnection() {
        $db = new PDO(
            "mysql:host=localhost;dbname=bulletproof", 
            "root", "password");
        return $this->createDefaultDBConnection($db, "bulletproof");
    }

    public function getDataSet() {
        return $this->createXMLDataSet("seed.xml");
    }
    public function getArticles($sectionId, $isHome) {
        $db = new PDO(
            "mysql:host=localhost;dbname=bulletproof", 
            "root", "password");

        $result = $db->query("SELECT a.id, a.title FROM features f LEFT JOIN articles a ON f.article_id = a.id AND f.section_id = 1");
        $articles = array();
        while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
            $articles[] = $row;
        }
        $result->closeCursor();

        return $articles;
    }
    public function testGetArticlesNonHome() {
        $articleDAO = new ArticleDAO();
        $articles = $articleDAO->getArticles(1, false);
        $this->assertEquals(
            array(
                array("id" => 1, "title" => "Android vs iOS"),
                array("id" => 2, "title" => "Android vs Wp7"),
                array("id" => 3, "title" => "iOS 5")),
            $articles);
    }
}

我的ArticleDAO.php文件

<?php
interface IArticleDAO
{
    public function getArticles($sectionId, $isHome);
}

0 个答案:

没有答案