PK ]BM/; .travis.ymlnu W+A language: php
sudo: false
php:
- 7.1
- 7.2
- master
services:
- mysql
env:
matrix:
- DEPENDENCIES="high"
- DEPENDENCIES="low"
global:
- DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest"
before_install:
- composer self-update
- composer clear-cache
- mysql -e 'CREATE DATABASE IF NOT EXISTS dbunit;'
install:
- if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi
- if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi
script:
- ./vendor/bin/phpunit --configuration phpunit-travis.xml
notifications:
email: false
PK ]BM˫w phive.xmlnu W+A
PK ]BMtZԪ README.mdnu W+A [This extension is no longer maintained](https://github.com/sebastianbergmann/dbunit/issues/217)
# DbUnit
[PHPUnit](https://phpunit.de/) extension for database interaction testing.
## Installation
### Composer
If you use [Composer](https://getcomposer.org/) to manage the dependencies of your project then you can add DbUnit as a development-time dependency to your project:
```
$ composer require --dev phpunit/dbunit
```
### PHP Archive (PHAR)
You can download a PHAR of DbUnit:
```
$ wget https://phar.phpunit.de/dbunit.phar
```
The example below shows how to configure PHPUnit to load all `*.phar` files found in a given directory (`tools/phpunit.d` in this example):
```xml
```
PK ]BM; ;
.gitignorenu W+A /.idea
/.php_cs.cache
/composer.lock
/build
/vendor
/tools
PK ]BM phpunit.xmlnu W+A
tests/Constraint
tests/DataSet
tests/Operation
tests/DB
src
PK ]BM9 src/DatabaseListConsumer.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit;
/**
* An interface for classes that require a list of databases to operate.
*/
interface DatabaseListConsumer
{
/**
* Sets the database for the spec
*
* @param array $databases
*/
public function setDatabases(array $databases);
}
PK ]BM9I I " src/Exception/RuntimeException.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit;
class RuntimeException extends \RuntimeException implements Exception
{
}
PK ]BM=Y Y * src/Exception/InvalidArgumentException.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit;
class InvalidArgumentException extends \InvalidArgumentException implements Exception
{
}
PK ]BMb^\ src/Exception/Exception.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit;
interface Exception
{
}
PK ]BMz src/DataSet/DefaultTable.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
use PHPUnit\DbUnit\InvalidArgumentException;
/**
* Provides default table functionality.
*/
class DefaultTable extends AbstractTable
{
/**
* Creates a new table object using the given $tableMetaData
*
* @param ITableMetadata $tableMetaData
*/
public function __construct(ITableMetadata $tableMetaData)
{
$this->setTableMetaData($tableMetaData);
$this->data = [];
}
/**
* Adds a row to the table with optional values.
*
* @param array $values
*/
public function addRow($values = []): void
{
$this->data[] = \array_replace(
\array_fill_keys($this->getTableMetaData()->getColumns(), null),
$values
);
}
/**
* Adds the rows in the passed table to the current table.
*
* @param ITable $table
*/
public function addTableRows(ITable $table): void
{
$tableColumns = $this->getTableMetaData()->getColumns();
$rowCount = $table->getRowCount();
for ($i = 0; $i < $rowCount; $i++) {
$newRow = [];
foreach ($tableColumns as $columnName) {
$newRow[$columnName] = $table->getValue($i, $columnName);
}
$this->addRow($newRow);
}
}
/**
* Sets the specified column of the specied row to the specified value.
*
* @param int $row
* @param string $column
* @param mixed $value
*/
public function setValue($row, $column, $value): void
{
if (isset($this->data[$row])) {
$this->data[$row][$column] = $value;
} else {
throw new InvalidArgumentException('The row given does not exist.');
}
}
}
PK ]BM[Q src/DataSet/IYamlParser.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
/**
* An interface for parsing YAML files.
*/
interface IYamlParser
{
/**
* @param string $yamlFile
*
* @return array parsed YAML
*/
public function parseYaml($yamlFile);
}
PK ]BM=. . src/DataSet/XmlDataSet.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
use PHPUnit\DbUnit\RuntimeException;
/**
* The default implementation of a data set.
*/
class XmlDataSet extends AbstractXmlDataSet
{
protected function getTableInfo(array &$tableColumns, array &$tableValues): void
{
if ($this->xmlFileContents->getName() != 'dataset') {
throw new RuntimeException('The root element of an xml data set file must be called ');
}
foreach ($this->xmlFileContents->xpath('/dataset/table') as $tableElement) {
if (empty($tableElement['name'])) {
throw new RuntimeException('Table elements must include a name attribute specifying the table name.');
}
$tableName = (string) $tableElement['name'];
if (!isset($tableColumns[$tableName])) {
$tableColumns[$tableName] = [];
}
if (!isset($tableValues[$tableName])) {
$tableValues[$tableName] = [];
}
$tableInstanceColumns = [];
foreach ($tableElement->xpath('./column') as $columnElement) {
$columnName = (string) $columnElement;
if (empty($columnName)) {
throw new RuntimeException("Missing elements for table $tableName. Add one or more elements to the element.");
}
if (!\in_array($columnName, $tableColumns[$tableName])) {
$tableColumns[$tableName][] = $columnName;
}
$tableInstanceColumns[] = $columnName;
}
foreach ($tableElement->xpath('./row') as $rowElement) {
$rowValues = [];
$index = 0;
$numOfTableInstanceColumns = \count($tableInstanceColumns);
foreach ($rowElement->children() as $columnValue) {
if ($index >= $numOfTableInstanceColumns) {
throw new RuntimeException("Row contains more values than the number of columns defined for table $tableName.");
}
switch ($columnValue->getName()) {
case 'value':
$rowValues[$tableInstanceColumns[$index]] = (string) $columnValue;
$index++;
break;
case 'null':
$rowValues[$tableInstanceColumns[$index]] = null;
$index++;
break;
default:
throw new RuntimeException('Unknown element ' . $columnValue->getName() . ' in a row element.');
}
}
$tableValues[$tableName][] = $rowValues;
}
}
}
}
PK ]BM}@| src/DataSet/ReplacementTable.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
/**
* Allows for replacing arbitrary strings in your data sets with other values.
*
* @todo When setTableMetaData() is taken out of the AbstractTable this class should extend AbstractTable.
*/
class ReplacementTable implements ITable
{
/**
* @var ITable
*/
protected $table;
/**
* @var array
*/
protected $fullReplacements;
/**
* @var array
*/
protected $subStrReplacements;
/**
* Creates a new replacement table
*
* @param ITable $table
* @param array $fullReplacements
* @param array $subStrReplacements
*/
public function __construct(ITable $table, array $fullReplacements = [], array $subStrReplacements = [])
{
$this->table = $table;
$this->fullReplacements = $fullReplacements;
$this->subStrReplacements = $subStrReplacements;
}
public function __toString()
{
$columns = $this->getTableMetaData()->getColumns();
$lineSeperator = \str_repeat('+----------------------', \count($columns)) . "+\n";
$lineLength = \strlen($lineSeperator) - 1;
$tableString = $lineSeperator;
$tableString .= '| ' . \str_pad($this->getTableMetaData()->getTableName(), $lineLength - 4, ' ', STR_PAD_RIGHT) . " |\n";
$tableString .= $lineSeperator;
$tableString .= $this->rowToString($columns);
$tableString .= $lineSeperator;
$rowCount = $this->getRowCount();
for ($i = 0; $i < $rowCount; $i++) {
$values = [];
foreach ($columns as $columnName) {
$values[] = $this->getValue($i, $columnName);
}
$tableString .= $this->rowToString($values);
$tableString .= $lineSeperator;
}
return "\n" . $tableString . "\n";
}
/**
* Adds a new full replacement
*
* Full replacements will only replace values if the FULL value is a match
*
* @param string $value
* @param string $replacement
*/
public function addFullReplacement($value, $replacement): void
{
$this->fullReplacements[$value] = $replacement;
}
/**
* Adds a new substr replacement
*
* Substr replacements will replace all occurances of the substr in every column
*
* @param string $value
* @param string $replacement
*/
public function addSubStrReplacement($value, $replacement): void
{
$this->subStrReplacements[$value] = $replacement;
}
/**
* Returns the table's meta data.
*
* @return ITableMetadata
*/
public function getTableMetaData()
{
return $this->table->getTableMetaData();
}
/**
* Returns the number of rows in this table.
*
* @return int
*/
public function getRowCount()
{
return $this->table->getRowCount();
}
/**
* Returns the value for the given column on the given row.
*
* @param int $row
* @param int $column
*/
public function getValue($row, $column)
{
return $this->getReplacedValue($this->table->getValue($row, $column));
}
/**
* Returns the an associative array keyed by columns for the given row.
*
* @param int $row
*
* @return array
*/
public function getRow($row)
{
$row = $this->table->getRow($row);
return \array_map([$this, 'getReplacedValue'], $row);
}
/**
* Asserts that the given table matches this table.
*
* @param ITable $other
*/
public function matches(ITable $other)
{
$thisMetaData = $this->getTableMetaData();
$otherMetaData = $other->getTableMetaData();
if (!$thisMetaData->matches($otherMetaData) ||
$this->getRowCount() != $other->getRowCount()
) {
return false;
}
$columns = $thisMetaData->getColumns();
$rowCount = $this->getRowCount();
for ($i = 0; $i < $rowCount; $i++) {
foreach ($columns as $columnName) {
$thisValue = $this->getValue($i, $columnName);
$otherValue = $other->getValue($i, $columnName);
if (\is_numeric($thisValue) && \is_numeric($otherValue)) {
if ($thisValue != $otherValue) {
return false;
}
} elseif ($thisValue !== $otherValue) {
return false;
}
}
}
return true;
}
protected function rowToString(array $row)
{
$rowString = '';
foreach ($row as $value) {
if (\is_null($value)) {
$value = 'NULL';
}
$rowString .= '| ' . \str_pad(\substr($value, 0, 20), 20, ' ', STR_PAD_BOTH) . ' ';
}
return $rowString . "|\n";
}
protected function getReplacedValue($value)
{
if (\is_scalar($value) && \array_key_exists((string) $value, $this->fullReplacements)) {
return $this->fullReplacements[$value];
}
if (\count($this->subStrReplacements) && isset($value)) {
return \str_replace(\array_keys($this->subStrReplacements), \array_values($this->subStrReplacements), $value);
}
return $value;
}
}
PK ]BMǔ src/DataSet/YamlDataSet.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
/**
* Creates YamlDataSets.
*
* You can incrementally add YAML files as tables to your datasets
*/
class YamlDataSet extends AbstractDataSet
{
/**
* @var array
*/
protected $tables = [];
/**
* @var IYamlParser
*/
protected $parser;
/**
* Creates a new YAML dataset
*
* @param string $yamlFile
* @param IYamlParser $parser
*/
public function __construct($yamlFile, $parser = null)
{
if ($parser == null) {
$parser = new SymfonyYamlParser();
}
$this->parser = $parser;
$this->addYamlFile($yamlFile);
}
/**
* Adds a new yaml file to the dataset.
*
* @param string $yamlFile
*/
public function addYamlFile($yamlFile): void
{
$data = $this->parser->parseYaml($yamlFile);
foreach ($data as $tableName => $rows) {
if (!isset($rows)) {
$rows = [];
}
if (!\is_array($rows)) {
continue;
}
if (!\array_key_exists($tableName, $this->tables)) {
$columns = $this->getColumns($rows);
$tableMetaData = new DefaultTableMetadata(
$tableName,
$columns
);
$this->tables[$tableName] = new DefaultTable(
$tableMetaData
);
}
foreach ($rows as $row) {
$this->tables[$tableName]->addRow($row);
}
}
}
/**
* Creates an iterator over the tables in the data set. If $reverse is
* true a reverse iterator will be returned.
*
* @param bool $reverse
*
* @return ITableIterator
*/
protected function createIterator($reverse = false)
{
return new DefaultTableIterator(
$this->tables,
$reverse
);
}
/**
* Creates a unique list of columns from all the rows in a table.
* If the table is defined another time in the Yaml, and if the Yaml
* parser could return the multiple occerrences, then this would be
* insufficient unless we grouped all the occurences of the table
* into onwe row set. sfYaml, however, does not provide multiple tables
* with the same name, it only supplies the last table.
*
* @params all the rows in a table.
*
* @param mixed $rows
*/
private function getColumns($rows)
{
$columns = [];
foreach ($rows as $row) {
$columns = \array_merge($columns, \array_keys($row));
}
return \array_values(\array_unique($columns));
}
}
PK ]BMaau$ $ src/DataSet/CompositeDataSet.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
use PHPUnit\DbUnit\InvalidArgumentException;
/**
* Creates Composite Datasets
*
* Allows for creating datasets from multiple sources (csv, query, xml, etc.)
*/
class CompositeDataSet extends AbstractDataSet
{
protected $motherDataSet;
/**
* Creates a new Composite dataset
*
* You can pass in any data set that implements PHPUnit_Extensions_Database_DataSet_IDataSet
*
* @param string $delimiter
* @param string $enclosure
* @param string $escape
*/
public function __construct(array $dataSets = [])
{
$this->motherDataSet = new DefaultDataSet();
foreach ($dataSets as $dataSet) {
$this->addDataSet($dataSet);
}
}
/**
* Adds a new data set to the composite.
*
* The dataset may not define tables that already exist in the composite.
*
* @param IDataSet $dataSet
*/
public function addDataSet(IDataSet $dataSet): void
{
foreach ($dataSet->getTableNames() as $tableName) {
if (!\in_array($tableName, $this->getTableNames())) {
$this->motherDataSet->addTable($dataSet->getTable($tableName));
} else {
$other = $dataSet->getTable($tableName);
$table = $this->getTable($tableName);
if (!$table->getTableMetaData()->matches($other->getTableMetaData())) {
throw new InvalidArgumentException("There is already a table named $tableName with different table definition");
}
$table->addTableRows($dataSet->getTable($tableName));
}
}
}
/**
* Creates an iterator over the tables in the data set. If $reverse is
* true a reverse iterator will be returned.
*
* @param bool $reverse
*
* @return ITableIterator
*/
protected function createIterator($reverse = false)
{
if ($reverse) {
return $this->motherDataSet->getReverseIterator();
}
return $this->motherDataSet->getIterator();
}
}
PK ]BMy y " src/DataSet/ReplacementDataSet.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
/**
* Allows for replacing arbitrary values or portions of values with new data.
*
* A usage for this is replacing all values == '[NULL'] with a true NULL value
*/
class ReplacementDataSet extends AbstractDataSet
{
/**
* @var IDataSet
*/
protected $dataSet;
/**
* @var array
*/
protected $fullReplacements;
/**
* @var array
*/
protected $subStrReplacements;
/**
* Creates a new replacement dataset
*
* You can pass in any data set that implements PHPUnit_Extensions_Database_DataSet_IDataSet
*
* @param string $delimiter
* @param string $enclosure
* @param string $escape
*/
public function __construct(IDataSet $dataSet, array $fullReplacements = [], array $subStrReplacements = [])
{
$this->dataSet = $dataSet;
$this->fullReplacements = $fullReplacements;
$this->subStrReplacements = $subStrReplacements;
}
/**
* Adds a new full replacement
*
* Full replacements will only replace values if the FULL value is a match
*
* @param string $value
* @param string $replacement
*/
public function addFullReplacement($value, $replacement): void
{
$this->fullReplacements[$value] = $replacement;
}
/**
* Adds a new substr replacement
*
* Substr replacements will replace all occurances of the substr in every column
*
* @param string $value
* @param string $replacement
*/
public function addSubStrReplacement($value, $replacement): void
{
$this->subStrReplacements[$value] = $replacement;
}
/**
* Creates an iterator over the tables in the data set. If $reverse is
* true a reverse iterator will be returned.
*
* @param bool $reverse
*
* @return ITableIterator
*/
protected function createIterator($reverse = false)
{
$innerIterator = $reverse ? $this->dataSet->getReverseIterator() : $this->dataSet->getIterator();
return new ReplacementTableIterator($innerIterator, $this->fullReplacements, $this->subStrReplacements);
}
}
PK ]BMAb
b
src/DataSet/QueryTable.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
use PDO;
use PHPUnit\DbUnit\Database\Connection;
/**
* Provides the functionality to represent a database table.
*/
class QueryTable extends AbstractTable
{
/**
* @var string
*/
protected $query;
/**
* @var Connection
*/
protected $databaseConnection;
/**
* @var string
*/
protected $tableName;
/**
* Creates a new database query table object.
*
* @param string $table_name
* @param string $query
* @param Connection $databaseConnection
* @param mixed $tableName
*/
public function __construct($tableName, $query, Connection $databaseConnection)
{
$this->query = $query;
$this->databaseConnection = $databaseConnection;
$this->tableName = $tableName;
}
/**
* Returns the table's meta data.
*
* @return ITableMetadata
*/
public function getTableMetaData()
{
$this->createTableMetaData();
return parent::getTableMetaData();
}
/**
* Checks if a given row is in the table
*
* @param array $row
*
* @return bool
*/
public function assertContainsRow(array $row)
{
$this->loadData();
return parent::assertContainsRow($row);
}
/**
* Returns the number of rows in this table.
*
* @return int
*/
public function getRowCount()
{
$this->loadData();
return parent::getRowCount();
}
/**
* Returns the value for the given column on the given row.
*
* @param int $row
* @param int $column
*/
public function getValue($row, $column)
{
$this->loadData();
return parent::getValue($row, $column);
}
/**
* Returns the an associative array keyed by columns for the given row.
*
* @param int $row
*
* @return array
*/
public function getRow($row)
{
$this->loadData();
return parent::getRow($row);
}
/**
* Asserts that the given table matches this table.
*
* @param ITable $other
*/
public function matches(ITable $other)
{
$this->loadData();
return parent::matches($other);
}
protected function loadData(): void
{
if ($this->data === null) {
$pdoStatement = $this->databaseConnection->getConnection()->query($this->query);
$this->data = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);
}
}
protected function createTableMetaData(): void
{
if ($this->tableMetaData === null) {
$this->loadData();
// if some rows are in the table
$columns = [];
if (isset($this->data[0])) {
// get column names from data
$columns = \array_keys($this->data[0]);
} else {
$columns = $this->databaseConnection->getMetaData()->getTableColumns($this->tableName);
}
// create metadata
$this->tableMetaData = new DefaultTableMetadata($this->tableName, $columns);
}
}
}
PK ]BMv5 src/DataSet/ArrayDataSet.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
use PHPUnit\DbUnit\InvalidArgumentException;
/**
* Implements the basic functionality of data sets using a PHP array.
*/
class ArrayDataSet extends AbstractDataSet
{
/**
* @var array
*/
protected $tables = [];
/**
* Constructor to build a new ArrayDataSet with the given array.
* The array parameter is an associative array of tables where the key is
* the table name and the value an array of rows. Each row is an associative
* array by itself with keys representing the field names and the values the
* actual data.
* For example:
* array(
* "addressbook" => array(
* array("id" => 1, "name" => "...", "address" => "..."),
* array("id" => 2, "name" => "...", "address" => "...")
* )
* )
*
* @param array $data
*/
public function __construct(array $data)
{
foreach ($data as $tableName => $rows) {
$columns = [];
if (isset($rows[0])) {
$columns = \array_keys($rows[0]);
}
$metaData = new DefaultTableMetadata($tableName, $columns);
$table = new DefaultTable($metaData);
foreach ($rows as $row) {
$table->addRow($row);
}
$this->tables[$tableName] = $table;
}
}
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];
}
protected function createIterator($reverse = false)
{
return new DefaultTableIterator($this->tables, $reverse);
}
}
PK ]BMˌeP P src/DataSet/TableFilter.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet;
use PHPUnit\DbUnit\InvalidArgumentException;
/**
* A table decorator that allows filtering out table columns from results.
*/
class TableFilter extends AbstractTable
{
/**
* The table meta data being decorated.
*
* @var ITable
*/
protected $originalTable;
/**
* Creates a new table filter using the original table
*
* @param $originalTable ITable
* @param $excludeColumns array @deprecated, use the set* methods instead
*/
public function __construct(ITable $originalTable, array $excludeColumns = [])
{
$this->originalTable = $originalTable;
$this->setTableMetaData(new TableMetadataFilter($originalTable->getTableMetaData()));
$this->addExcludeColumns($excludeColumns);
}
/**
* Returns the an associative array keyed by columns for the given row.
*
* @param int $row
*
* @return array
*/
public function getRow($row)
{
$this->loadData();
return parent::getRow($row);
}
/**
* Returns the number of rows in this table.
*
* @return int
*/
public function getRowCount()
{
$this->loadData();
return parent::getRowCount();
}
/**
* Returns the value for the given column on the given row.
*
* @param int $row
* @param int $column
*/
public function getValue($row, $column)
{
if (\in_array($column, $this->getTableMetaData()->getColumns())) {
return $this->originalTable->getValue($row, $column);
}
throw new InvalidArgumentException("The given row ({$row}) and column ({$column}) do not exist in table {$this->getTableMetaData()->getTableName()}");
}
/**
* Sets the columns to include in the table.
*
* @param array $includeColumns
*/
public function addIncludeColumns(array $includeColumns): void
{
$this->tableMetaData->addIncludeColumns($includeColumns);
}
/**
* Clears the included columns.
*/
public function clearIncludeColumns(): void
{
$this->tableMetaData->clearIncludeColumns();
}
/**
* Sets the columns to exclude from the table.
*
* @param array $excludeColumns
*/
public function addExcludeColumns(array $excludeColumns): void
{
$this->tableMetaData->addExcludeColumns($excludeColumns);
}
/**
* Clears the included columns.
*/
public function clearExcludeColumns(): void
{
$this->tableMetaData->clearExcludeColumns();
}
/**
* Checks if a given row is in the table
*
* @param array $row
*
* @return bool
*/
public function assertContainsRow(array $row)
{
$this->loadData();
return parent::assertContainsRow($row);
}
/**
* Loads data into local data table if it's not already loaded
*/
protected function loadData(): void
{
if ($this->data === null) {
$data = [];
for ($row = 0; $row < $this->originalTable->getRowCount(); $row++) {
$tRow = [];
foreach ($this->getTableMetaData()->getColumns() as $col) {
$tRow[$col] = $this->getValue($row, $col);
}
$data[$row] = $tRow;
}
$this->data = $data;
}
}
}
PK ]BM([ [ % src/DataSet/Specification/FlatXml.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet\Specification;
use PHPUnit\DbUnit\DataSet\FlatXmlDataSet;
/**
* Creates a FlatXML dataset based off of a spec string.
*
* The format of the spec string is as follows:
*
*
*
* The filename should be the location of a flat xml file relative to the
* current working directory.
*/
class FlatXml implements Specification
{
/**
* Creates Flat XML Data Set from a data set spec.
*
* @param string $dataSetSpec
*
* @return FlatXmlDataSet
*/
public function getDataSet($dataSetSpec)
{
return new FlatXmlDataSet($dataSetSpec);
}
}
PK ]BM\h h + src/DataSet/Specification/Specification.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet\Specification;
use PHPUnit\DbUnit\DataSet\IDataSet;
/**
* Provides an interface for creating data sets from data set spec strings.
*/
interface Specification
{
/**
* Creates a data set from a data set spec string.
*
* @param string $dataSetSpec
*
* @return IDataSet
*/
public function getDataSet($dataSetSpec);
}
PK ]BM7iԒd d # src/DataSet/Specification/Table.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\DbUnit\DataSet\Specification;
use PHPUnit\DbUnit\Database\DefaultConnection;
use PHPUnit\DbUnit\DatabaseListConsumer;
use PHPUnit\DbUnit\DataSet\IDataSet;
use ReflectionClass;
/**
* Creates a database dataset based off of a spec string.
*
* This spec class requires a list of databases to be set to the object before
* it can return a list of databases.
*
* The format of the spec string is as follows:
*
* ::
*
* The db label should be equal to one of the keys in the array of databases
* passed to setDatabases().
*
* The schema should be the primary schema you will be choosing tables from.
*
* The tables should be a comma delimited list of all tables you would like to
* pull data from.
*
* The sql is the query you want to use to generate the table columns and data.
* The column names in the table will be identical to the column aliases in the
* query.
*/
class Table implements Specification, DatabaseListConsumer
{
/**
* @var array
*/
protected $databases = [];
/**
* Sets the database for the spec
*
* @param array $databases
*/
public function setDatabases(array $databases): void
{
$this->databases = $databases;
}
/**
* Creates a DB Data Set from a data set spec.
*
* @param string $dataSetSpec
*
* @return IDataSet
*/
public function getDataSet($dataSetSpec)
{
[$dbLabel, $schema, $tables] = \explode(':', $dataSetSpec, 3);
$databaseInfo = $this->databases[$dbLabel];
$pdoRflc = new ReflectionClass('PDO');
$pdo = $pdoRflc->newInstanceArgs(\explode('|', $databaseInfo));
$dbConnection = new DefaultConnection($pdo, $schema);
return !empty($tables) ? $dbConnection->createDataSet(\explode(',', $tables)) : $dbConnection->createDataSet();
}
}
PK ]BM &