Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Phpunit从未知位置抓取Doctrine2配置_Php_Doctrine Orm_Zend Framework2_Phpunit - Fatal编程技术网

Phpunit从未知位置抓取Doctrine2配置

Phpunit从未知位置抓取Doctrine2配置,php,doctrine-orm,zend-framework2,phpunit,Php,Doctrine Orm,Zend Framework2,Phpunit,我使用的是ZF2+Doctrine2+PHPUNIT,在设置PHPUNIT时,它可以很好地用于基本测试,但是只要我尝试运行调用Doctrine2的测试,我就会得到: PDOException: SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES) 但是,我从未指定“用户名”或“本地主机”或任何类型的密码。事实上,我的应用程序运行得非常好,我的配置指定了完全不同的设置

我使用的是ZF2+Doctrine2+PHPUNIT,在设置PHPUNIT时,它可以很好地用于基本测试,但是只要我尝试运行调用Doctrine2的测试,我就会得到:

PDOException: SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)
但是,我从未指定“用户名”或“本地主机”或任何类型的密码。事实上,我的应用程序运行得非常好,我的配置指定了完全不同的设置

那么PHPUnit从哪里获得这些设置以及如何修复它呢

My global.php:

'doctrine' => array(
    'connection' => array(
        'orm_default' => array(
            'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
            'params' => array(
                'host' => '127.0.0.1',
                'port' => '3306',
                'user' => 'sbapp',
                'password' => 'myp@ss',
                'dbname' => 'root'
            )
        )
    ),
测试:

class ApplicationControllerTest extends AbstractHttpControllerTestCase
{
    protected $traceError = true;

    public function setUp()
    {
        $this->setApplicationConfig(
            include '../../../config/application.config.php'
        );

        parent::setUp();
    }

    public function testAuthActionCanBeAccessed()
    {
        $postData = new \stdClass();
        $postData->username = "someAppUser";
        $postData->password = "12345";
        $postData = json_decode(json_encode($postData),true);

        $this->dispatch('/auth', 'POST', $postData);

        $response = $this->getResponse();

        $this->assertResponseStatusCode(200);
        $this->assertActionName('auth');
    }
}

如果设置时配置中使用的相对路径不正确,可能会严重影响实体的加载等。所以我一直在沿着正确的道路追。。从根目录..或供应商..或从测试文件夹内等调用phpunit时

解决方案:

从项目根调用它,并保持路由与主项目完全相同