用phpunit测试zend给我“当前没有安装mysql驱动”

时间:2011-08-30 14:52:13

标签: zend-framework phpunit

我有这个测试类

<?php

class IndexControllerTest extends ControllerTestCase
{
....


    public function testValidLoginShouldGoToProfilePage()
    {
        $this->request->setMethod('POST')
              ->setPost(array(
                  'email' => 'capoarea',
                  'password' => '123456'
              ));
        $this->dispatch('/user/login');
        $this->assertRedirectTo('/index/index');

        $this->resetRequest()
             ->resetResponse();

        $this->request->setMethod('GET')
             ->setPost(array());
        $this->dispatch('/cliente/index');
        $this->assertRoute('default');
        $this->assertModule('default');
        $this->assertController('cliente');
        $this->assertAction('index');
        $this->assertNotRedirect();
    }

}

和这个application.ini

[production]
.....
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.db.params.charset = "utf8"
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = "gestionale"
resources.db.isDefaultTableAdapter = true
autoloaderNamespaces[] = "Gestionale_";serve per caricare il plugin di sotto quando si usa anche ZFdebug
resources.frontController.plugins.acl = "Gestionale_Controller_Plugin_Acl"
resources.db.params.profiler = true


....
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

我收到此错误enter image description here

在应用程序ini 测试扩展生产所以它应该有所有db配置,我做错了什么?

2 个答案:

答案 0 :(得分:4)

您的php命令行解释器很可能使用不同的php.ini文件。

要检查MySQL驱动程序,请打开一个新的shell提示符并运行php -m并检查是否已加载mysql扩展。

> php -m | grep -i sql
mysql
mysqli
mysqlnd
pdo_mysql
pdo_sqlite
SQLite
sqlite3

要查看加载的ini文件,请使用php命令的-i标志

> php -i | grep ini
Configuration File (php.ini) Path => /opt/local/etc/php5
Loaded Configuration File => /opt/local/etc/php5/php.ini
Scan this dir for additional .ini files => /opt/local/var/db/php5
Additional .ini files parsed => /opt/local/var/db/php5/apc.ini,

不知道在Windows上是否有grep之类的命令来过滤输出,如果不是,你必须检查php -mphp -i的所有输出以收集必填行或安装windows grep实用程序

答案 1 :(得分:2)

PHPUnit使用php.ini for Commandline。我认为你必须在那里启用SQL驱动程序。您可以使用(在OsX上测试:-))

检查php.ini的路径
php --ini

<强>结果:

Configuration File (php.ini) Path: /Applications/MAMP/conf/php5.2
Loaded Configuration File:         /Applications/MAMP/conf/php5.2/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)