• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

misantron / dbunit / 4562384438

pending completion
4562384438

push

github

Aleksandr Ivanov
Fix build status badge display

635 of 1200 relevant lines covered (52.92%)

5.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.38
/src/DataSet/TableFilter.php
1
<?php
2

3
/*
4
 * This file is part of DbUnit.
5
 *
6
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
namespace PHPUnit\DbUnit\DataSet;
13

14
use PHPUnit\DbUnit\Exception\InvalidArgumentException;
15

16
/**
17
 * A table decorator that allows filtering out table columns from results.
18
 */
19
class TableFilter extends AbstractTable
20
{
21
    /**
22
     * The table meta data being decorated.
23
     *
24
     * @var ITable
25
     */
26
    protected $originalTable;
27

28
    /**
29
     * Creates a new table filter using the original table
30
     *
31
     * @param $originalTable ITable
32
     * @param $excludeColumns array @deprecated, use the set* methods instead
33
     */
34
    public function __construct(ITable $originalTable, array $excludeColumns = [])
35
    {
36
        $this->originalTable = $originalTable;
4✔
37
        $this->setTableMetaData(new TableMetadataFilter($originalTable->getTableMetaData()));
4✔
38
        $this->addExcludeColumns($excludeColumns);
4✔
39
    }
40

41
    /**
42
     * Returns the an associative array keyed by columns for the given row.
43
     *
44
     * @param int $row
45
     *
46
     * @return array
47
     */
48
    public function getRow(int $row): array
49
    {
50
        $this->loadData();
×
51

52
        return parent::getRow($row);
×
53
    }
54

55
    /**
56
     * Returns the number of rows in this table.
57
     *
58
     * @return int
59
     */
60
    public function getRowCount(): int
61
    {
62
        $this->loadData();
4✔
63

64
        return parent::getRowCount();
4✔
65
    }
66

67
    /**
68
     * Returns the value for the given column on the given row.
69
     *
70
     * @param int $row
71
     * @param string $column
72
     */
73
    public function getValue(int $row, string $column)
74
    {
75
        if (\in_array($column, $this->getTableMetaData()->getColumns(), true)) {
4✔
76
            return $this->originalTable->getValue($row, $column);
4✔
77
        }
78

79
        throw new InvalidArgumentException(
×
80
            "The given row ({$row}) and column ({$column}) do not exist in table {$this->getTableMetaData()->getTableName()}"
×
81
        );
×
82
    }
83

84
    /**
85
     * Sets the columns to include in the table.
86
     *
87
     * @param array $includeColumns
88
     */
89
    public function addIncludeColumns(array $includeColumns): void
90
    {
91
        $this->tableMetaData->addIncludeColumns($includeColumns);
2✔
92
    }
93

94
    /**
95
     * Clears the included columns.
96
     */
97
    public function clearIncludeColumns(): void
98
    {
99
        $this->tableMetaData->clearIncludeColumns();
×
100
    }
101

102
    /**
103
     * Sets the columns to exclude from the table.
104
     *
105
     * @param array $excludeColumns
106
     */
107
    public function addExcludeColumns(array $excludeColumns): void
108
    {
109
        $this->tableMetaData->addExcludeColumns($excludeColumns);
4✔
110
    }
111

112
    /**
113
     * Clears the included columns.
114
     */
115
    public function clearExcludeColumns(): void
116
    {
117
        $this->tableMetaData->clearExcludeColumns();
×
118
    }
119

120
    /**
121
     * Checks if a given row is in the table
122
     *
123
     * @param array $row
124
     *
125
     * @return bool
126
     */
127
    public function assertContainsRow(array $row): bool
128
    {
129
        $this->loadData();
×
130

131
        return parent::assertContainsRow($row);
×
132
    }
133

134
    /**
135
     * Loads data into local data table if it's not already loaded
136
     */
137
    protected function loadData(): void
138
    {
139
        if ($this->data === null) {
4✔
140
            $data = [];
4✔
141

142
            for ($row = 0; $row < $this->originalTable->getRowCount(); $row++) {
4✔
143
                $tRow = [];
4✔
144

145
                foreach ($this->getTableMetaData()->getColumns() as $col) {
4✔
146
                    $tRow[$col] = $this->getValue($row, $col);
4✔
147
                }
148
                $data[$row] = $tRow;
4✔
149
            }
150
            $this->data = $data;
4✔
151
        }
152
    }
153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc