2018-11-19 12:14:58 +00:00
|
|
|
<?php
|
2018-11-24 03:25:56 +00:00
|
|
|
namespace ActivityPub\Test\Config;
|
2018-11-19 12:14:58 +00:00
|
|
|
|
|
|
|
use PHPUnit\DbUnit\DataSet\AbstractDataSet;
|
2018-11-21 03:34:39 +00:00
|
|
|
use PHPUnit\DbUnit\DataSet\DefaultTableMetadata;
|
2018-11-19 12:14:58 +00:00
|
|
|
use PHPUnit\DbUnit\DataSet\DefaultTable;
|
|
|
|
use PHPUnit\DbUnit\DataSet\DefaultTableIterator;
|
|
|
|
|
|
|
|
class ArrayDataSet extends AbstractDataSet
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $tables = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
public function __construct(array $data)
|
|
|
|
{
|
|
|
|
foreach ($data as $tableName => $rows) {
|
|
|
|
$columns = [];
|
|
|
|
if (isset($rows[0])) {
|
|
|
|
$columns = array_keys($rows[0]);
|
|
|
|
}
|
|
|
|
|
2018-11-21 03:34:39 +00:00
|
|
|
$metaData = new DefaultTableMetadata($tableName, $columns);
|
2018-11-19 12:14:58 +00:00
|
|
|
$table = new DefaultTable($metaData);
|
|
|
|
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
$table->addRow($row);
|
|
|
|
}
|
|
|
|
$this->tables[$tableName] = $table;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function createIterator($reverse = false)
|
|
|
|
{
|
|
|
|
return new DefaultTableIterator($this->tables, $reverse);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTable($tableName)
|
|
|
|
{
|
|
|
|
if (!isset($this->tables[$tableName])) {
|
|
|
|
throw new InvalidArgumentException("$tableName is not a table in the current database.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->tables[$tableName];
|
|
|
|
}
|
|
|
|
}
|