• 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

77.5
/src/DataSet/XmlDataSet.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\RuntimeException;
15

16
/**
17
 * The default implementation of a data set.
18
 */
19
class XmlDataSet extends AbstractXmlDataSet
20
{
21
    protected function getTableInfo(array &$tableColumns, array &$tableValues): void
22
    {
23
        if ($this->xmlFileContents->getName() !== 'dataset') {
1✔
24
            throw new RuntimeException('The root element of an xml data set file must be called <dataset>');
×
25
        }
26

27
        foreach ($this->xmlFileContents->xpath('/dataset/table') as $tableElement) {
1✔
28
            if (empty($tableElement['name'])) {
1✔
29
                throw new RuntimeException('Table elements must include a name attribute specifying the table name.');
×
30
            }
31

32
            $tableName = (string) $tableElement['name'];
1✔
33

34
            if (!isset($tableColumns[$tableName])) {
1✔
35
                $tableColumns[$tableName] = [];
1✔
36
            }
37

38
            if (!isset($tableValues[$tableName])) {
1✔
39
                $tableValues[$tableName] = [];
1✔
40
            }
41

42
            $tableInstanceColumns = [];
1✔
43

44
            foreach ($tableElement->xpath('./column') as $columnElement) {
1✔
45
                $columnName = (string) $columnElement;
1✔
46

47
                if (empty($columnName)) {
1✔
48
                    throw new RuntimeException(
×
49
                        "Missing <column> elements for table $tableName. Add one or more <column> elements to the <table> element."
×
50
                    );
×
51
                }
52

53
                if (!\in_array($columnName, $tableColumns[$tableName], true)) {
1✔
54
                    $tableColumns[$tableName][] = $columnName;
1✔
55
                }
56

57
                $tableInstanceColumns[] = $columnName;
1✔
58
            }
59

60
            foreach ($tableElement->xpath('./row') as $rowElement) {
1✔
61
                $rowValues = [];
1✔
62
                $index = 0;
1✔
63
                $numOfTableInstanceColumns = \count($tableInstanceColumns);
1✔
64

65
                foreach ($rowElement->children() as $columnValue) {
1✔
66
                    if ($index >= $numOfTableInstanceColumns) {
1✔
67
                        throw new RuntimeException(
×
68
                            "Row contains more values than the number of columns defined for table {$tableName}."
×
69
                        );
×
70
                    }
71

72
                    switch ($columnValue->getName()) {
1✔
73
                        case 'value':
1✔
74
                            $rowValues[$tableInstanceColumns[$index]] = (string) $columnValue;
1✔
75
                            $index++;
1✔
76

77
                            break;
1✔
78
                        case 'null':
1✔
79
                            $rowValues[$tableInstanceColumns[$index]] = null;
1✔
80
                            $index++;
1✔
81

82
                            break;
1✔
83
                        default:
84
                            throw new RuntimeException("Unknown element {$columnValue->getName()} in a row element.");
×
85
                    }
86
                }
87

88
                $tableValues[$tableName][] = $rowValues;
1✔
89
            }
90
        }
91
    }
92
}
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