如何在PHPUnit中将数组作为参数传递给提供者?

如何在PHPUnit中将数组作为参数传递给提供者?,php,phpunit,Php,Phpunit,我有一个接收数组作为参数的测试方法,我想从数据提供程序方法中提供数据 如何才能做到这一点 public function dataProvider(){ return array(array( 'id'=>1, 'description'=>'', )); } /** * @dataProvider dataProvider */ public function testAddDoc

我有一个接收数组作为参数的测试方法,我想从数据提供程序方法中提供数据

如何才能做到这一点

public function dataProvider(){
        return array(array(
                'id'=>1,
                'description'=>'',
        ));
}

/**
 * @dataProvider dataProvider
 */
public function testAddDocument($data){
// data here shall be an array provided by the data provider
// some test data here
}
发生的情况是它传递'id'键的值…等等


我想传递整个数组

数据提供程序方法必须为要传递给测试方法的每组参数返回一个包含一个数组的数组。要传递数组,请将其与其他参数一起包含。请注意,在示例代码中,您需要另一个封闭数组

下面的示例返回两组数据,每个数据都有两个参数(一个数组和一个字符串)


重要提示:数据提供程序方法必须是非静态的。PHPUnit实例化测试用例以调用每个数据提供程序方法。

我正在测试您的解决方案,但关于非静态的问题,手册本身将其设置为静态:您的链接指向(非常旧的)3.2版本。它在中显示为非静态。哦!谢谢你通知我,非常感谢你的解决方案
public function dataProvider() {
    return array(                       // data sets
        array(                          // data set 0
            array(                      // first argument
                'id' => 1,
                'description' => 'this',
            ),
            'foo',                      // second argument
        ),
        array(                          // data set 1
            array(                      // first argument
                'id' => 2,
                'description' => 'that',
            ),
            'bar',                      // second argument
        ),
    );
}