2018-11-19 12:14:58 +00:00
|
|
|
<?php
|
2019-02-16 17:51:24 +00:00
|
|
|
|
2019-01-20 03:37:07 +00:00
|
|
|
namespace ActivityPub\Test\TestConfig;
|
2018-11-19 12:14:58 +00:00
|
|
|
|
2019-01-30 16:27:47 +00:00
|
|
|
use InvalidArgumentException;
|
2018-11-19 12:14:58 +00:00
|
|
|
|
2019-02-07 03:48:00 +00:00
|
|
|
class ArrayDataSet extends \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
|
2018-11-19 12:14:58 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $tables = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
2019-02-16 17:51:24 +00:00
|
|
|
public function __construct( array $data )
|
2018-11-19 12:14:58 +00:00
|
|
|
{
|
2019-02-16 17:51:24 +00:00
|
|
|
foreach ( $data as $tableName => $rows ) {
|
2018-11-19 12:14:58 +00:00
|
|
|
$columns = [];
|
2019-02-16 17:51:24 +00:00
|
|
|
if ( isset( $rows[0] ) ) {
|
|
|
|
$columns = array_keys( $rows[0] );
|
2018-11-19 12:14:58 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 17:51:24 +00:00
|
|
|
$metaData = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData( $tableName, $columns );
|
|
|
|
$table = new \PHPUnit_Extensions_Database_DataSet_DefaultTable( $metaData );
|
2018-11-19 12:14:58 +00:00
|
|
|
|
2019-02-16 17:51:24 +00:00
|
|
|
foreach ( $rows as $row ) {
|
|
|
|
$table->addRow( $row );
|
2018-11-19 12:14:58 +00:00
|
|
|
}
|
|
|
|
$this->tables[$tableName] = $table;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-16 17:51:24 +00:00
|
|
|
public function getTable( $tableName )
|
2018-11-19 12:14:58 +00:00
|
|
|
{
|
2019-02-16 17:51:24 +00:00
|
|
|
if ( !isset( $this->tables[$tableName] ) ) {
|
|
|
|
throw new InvalidArgumentException( "$tableName is not a table in the current database." );
|
2018-11-19 12:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->tables[$tableName];
|
|
|
|
}
|
2019-02-16 17:51:24 +00:00
|
|
|
|
|
|
|
protected function createIterator( $reverse = false )
|
|
|
|
{
|
|
|
|
return new \PHPUnit_Extensions_Database_DataSet_DefaultTableIterator( $this->tables, $reverse );
|
|
|
|
}
|
2018-11-19 12:14:58 +00:00
|
|
|
}
|