我刚刚开始使用PHPUnit
。我有一个用于数据提供程序的.csv
文件,并且具有一个数据提供程序功能来从csv
获取值。
我的数据提供者功能是
public function testDataProvider()
{
if (!$this->dataset) {
$this->data = new Data();
$this->dataset = $this->data->get_data('testfile.csv');
}
$x = $this->dataset['testRow1Values'];
return $x;
}
我想获取一些值作为测试函数中的数组,并将其与我从上述数据提供程序函数中获取的日期进行比较。这个概念就像
public function testValuesGetting()
{
//get values from query as array
//Compare these values with the row from the data provider
}
我不确定该怎么做。请帮忙。
答案 0 :(得分:2)
您可以使用$this->assertEquals($data, $expectedData);
因此在您的测试案例中,我们可以:
public function testValuesGetting()
{
$expectedData = ['expected', 'array'];
$dataFromCsv = testDataProvider();
$this->assertEquals($dataFromCsv, $expectedData);
}