ArrayDataSet.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\test\lib;
12 
13 //\PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
14 
15 class ArrayDataSet extends \PHPUnit_Extensions_Database_DataSet_AbstractDataSet {
16  protected $tables = [];
17 
18  /**
19  * @param array $data
20  */
21  public function __construct(array $data) {
22  foreach ($data AS $tableName => $rows) {
23  $columns = [];
24  if (isset($rows[0])) {
25  $columns = array_keys($rows[0]);
26  }
27 
28  $metaData = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
29  $table = new \PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
30 
31  foreach ($rows AS $row) {
32  $table->addRow($row);
33  }
34  $this->tables[$tableName] = $table;
35  }
36  }
37 
38  protected function createIterator($reverse = FALSE) {
39  return new \PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse);
40  }
41 
42  public function getTable($tableName) {
43  if (!isset($this->tables[$tableName])) {
44  throw new InvalidArgumentException("$tableName is not a table in the current database.");
45  }
46 
47  return $this->tables[$tableName];
48  }
49 }
50 ?>
createIterator($reverse=FALSE)
Test support classes.
Definition: namespaces.php:100