activitypub-php/test/TestConfig/ArrayDataSet.php

49 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2019-02-16 17:51:24 +00:00
namespace ActivityPub\Test\TestConfig;
2019-01-30 16:27:47 +00:00
use InvalidArgumentException;
class ArrayDataSet extends \PHPUnit_Extensions_Database_DataSet_AbstractDataSet
{
/**
* @var array
*/
protected $tables = [];
/**
* @param array $data
*/
2019-02-16 17:51:24 +00:00
public function __construct( array $data )
{
2019-02-16 17:51:24 +00:00
foreach ( $data as $tableName => $rows ) {
$columns = [];
2019-02-16 17:51:24 +00:00
if ( isset( $rows[0] ) ) {
$columns = array_keys( $rows[0] );
}
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 );
2019-02-16 17:51:24 +00:00
foreach ( $rows as $row ) {
$table->addRow( $row );
}
$this->tables[$tableName] = $table;
}
}
2019-02-16 17:51:24 +00:00
public function getTable( $tableName )
{
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." );
}
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 );
}
}