无法设置夹具(带dbunit的PHPunit)

无法设置夹具(带dbunit的PHPunit),phpunit,phalcon,fixtures,dbunit,Phpunit,Phalcon,Fixtures,Dbunit,试图为我的Phalcon测试设置夹具,但失败了。 你能找出我的实现出了什么问题吗 用法 法尔康7.2 Docker版本18.09.0-ce-beta1 docker compose 1.22.0版 pH6.5.8 dbunit 3.0.3 现状 使用“getConnection”函数连接到数据库成功 创建数据集(YAML类型) 创建getDataSet函数,但无法设置fixture和cleanup unitTestCase.php 回应 注 当我在getConnection中使用一个真正

试图为我的Phalcon测试设置夹具,但失败了。 你能找出我的实现出了什么问题吗

用法
  • 法尔康7.2
  • Docker版本18.09.0-ce-beta1
  • docker compose 1.22.0版
  • pH6.5.8
  • dbunit 3.0.3
现状
  • 使用“getConnection”函数连接到数据库成功

  • 创建数据集(YAML类型)

  • 创建getDataSet函数,但无法设置fixture和cleanup

unitTestCase.php 回应 注 当我在getConnection中使用一个真正的mysql数据库连接,并调用
$this->getConnection()->getRowCount('testRow')
,结果是正确的。 因此,问题似乎来自加载yaml数据集

补充1
$this->getConnection
的内容是:

(执行
print\r($this->getConnection(),false);

$this->getDataSet()的内容是:

(执行
print\r($this->getDataSet(),false);


Dbunit必须执行一些设置操作,它们在
PHPUnit\Dbunit\TestCaseTracit
setup()
方法中定义(您可以看到更多。当您继承
PHPUnit\Dbunit\TestCase
时,您基本上不必担心它(除了确保从测试用例中调用
parent::setup()
).当直接从trait使用功能时,您必须确保dbunit的设置也被调用。 您可以通过smth实现这一点,如下所示:

<?php
use Phalcon\Test\UnitTestCase as PhalconTestCase;
use PHPUnit\DbUnit\TestCaseTrait;

abstract class UnitTestCase extends PhalconTestCase
{
    use TestCaseTrait {
        setUp as protected dbunitSetUp;
    };

    public function setUp()
    {
        parent::setUp(); // phalcon setup
        $this->dbuintSetUp(); // dbunit setup
    }
}

<?php

namespace Test\Controllers;

use PHPUnit\DbUnit\DataSet\YamlDataSet;

class DatabaseTest extends \UnitTestCase
{
    protected function getDataSet()
    {
        return new YamlDataSet(__DIR__ . "/../DataSet/dataSet.yml");
    }

    public function testsTableRow() {
        $this->assertEquals(1, $this->getConnection()->getRowCount('testRow'), "");
    }
}
testRow:
  -
    id: 1
    name: 'test'
    text: 'hello, world'
Failed asserting that 0 matches expected 1.
(                                                                                                                                             
    [connection:protected] => PDO Object                                                                                                      
        (                                                                                                                                     
        )                                                                                                                                     

    [metaData:protected] => PHPUnit\DbUnit\Database\Metadata\MySQL Object                                                                     
        (                                                                                                                                     
            [schemaObjectQuoteChar:protected] => `                                                                                            
            [pdo:protected] => PDO Object                                                                                                     
                (                                                                                                                             
                )                                                                                                                             

            [schema:protected] => dbname=test                                                                                         
            [truncateCommand:protected] => TRUNCATE                                                                                           
        )
)
(                                                                                                                                             
    [tables:protected] => Array                                                                                                               
        (                                                                                                                                     
            [testRow] => PHPUnit\DbUnit\DataSet\DefaultTable Object                                                                           
                (                                                                                                                             
                    [tableMetaData:protected] => PHPUnit\DbUnit\DataSet\DefaultTableMetadata Object                                           
                        (                                                                                                                     
                            [columns:protected] => Array                                                                                      
                                (                                                                                                             
                                    [0] => id                                                                                                 
                                    [1] => name                                                                                               
                                    [2] => text                                                                                               
                                )                                                                                                             

                            [primaryKeys:protected] => Array                                                                                  
                                (                                                                                                             
                                )                                                                                                             

                            [tableName:protected] => testRow                                                                                  
                        )                                                                                                                     

                    [data:protected] => Array                                                                                                 
                        (                                                                                                                     
                            [0] => Array                                                                                                      
                                (                                                                                                             
                                    [id] => 1                                                                                                 
                                    [name] => test
                                    [text] => hello, world
                                )

                        )

                    [other:PHPUnit\DbUnit\DataSet\AbstractTable:private] =>
                )

        )

    [parser:protected] => PHPUnit\DbUnit\DataSet\SymfonyYamlParser Object
        (
        )

)
<?php
use Phalcon\Test\UnitTestCase as PhalconTestCase;
use PHPUnit\DbUnit\TestCaseTrait;

abstract class UnitTestCase extends PhalconTestCase
{
    use TestCaseTrait {
        setUp as protected dbunitSetUp;
    };

    public function setUp()
    {
        parent::setUp(); // phalcon setup
        $this->dbuintSetUp(); // dbunit setup
    }
}