• 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

56.52
/src/DataSet/MysqlXmlDataSet.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
 * Data set implementation for the output of mysqldump --xml.
18
 */
19
class MysqlXmlDataSet extends AbstractXmlDataSet
20
{
21
    protected function getTableInfo(array &$tableColumns, array &$tableValues): void
22
    {
23
        if ($this->xmlFileContents->getName() != 'mysqldump') {
1✔
24
            throw new RuntimeException('The root element of a MySQL XML data set file must be called <mysqldump>');
×
25
        }
26

27
        foreach ($this->xmlFileContents->xpath('./database/table_data') as $tableElement) {
1✔
28
            if (empty($tableElement['name'])) {
1✔
29
                throw new RuntimeException('<table_data> elements must include a name attribute');
×
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
            foreach ($tableElement->xpath('./row') as $rowElement) {
1✔
43
                $rowValues = [];
1✔
44

45
                foreach ($rowElement->xpath('./field') as $columnElement) {
1✔
46
                    if (empty($columnElement['name'])) {
1✔
47
                        throw new RuntimeException('<field> element name attributes cannot be empty');
×
48
                    }
49

50
                    $columnName = (string) $columnElement['name'];
1✔
51

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

57
                foreach ($tableColumns[$tableName] as $columnName) {
1✔
58
                    $fields = $rowElement->xpath('./field[@name="' . $columnName . '"]');
1✔
59

60
                    if (!isset($fields[0])) {
1✔
61
                        throw new RuntimeException(
×
62
                            sprintf(
×
63
                                '%s column doesn\'t exist in current row for table %s',
×
64
                                $columnName,
×
65
                                $tableName
×
66
                            )
×
67
                        );
×
68
                    }
69

70
                    $column = $fields[0];
1✔
71
                    $attr   = $column->attributes('http://www.w3.org/2001/XMLSchema-instance');
1✔
72

73
                    if (isset($attr['type']) && (string) $attr['type'] === 'xs:hexBinary') {
1✔
74
                        $columnValue = pack('H*', (string) $column);
×
75
                    } else {
76
                        $null        = isset($column['nil']) || isset($attr[0]);
1✔
77
                        $columnValue = $null ? null : (string) $column;
1✔
78
                    }
79

80
                    $rowValues[$columnName] = $columnValue;
1✔
81
                }
82

83
                $tableValues[$tableName][] = $rowValues;
1✔
84
            }
85
        }
86

87
        foreach ($this->xmlFileContents->xpath('./database/table_structure') as $tableElement) {
1✔
88
            if (empty($tableElement['name'])) {
×
89
                throw new RuntimeException('<table_structure> elements must include a name attribute');
×
90
            }
91

92
            $tableName = (string) $tableElement['name'];
×
93

94
            foreach ($tableElement->xpath('./field') as $fieldElement) {
×
95
                if (empty($fieldElement['Field']) && empty($fieldElement['field'])) {
×
96
                    throw new RuntimeException('<field> elements must include a Field attribute');
×
97
                }
98

99
                $columnName = (string) (empty($fieldElement['Field']) ? $fieldElement['field'] : $fieldElement['Field']);
×
100

101
                if (!\in_array($columnName, $tableColumns[$tableName])) {
×
102
                    $tableColumns[$tableName][] = $columnName;
×
103
                }
104
            }
105
        }
106
    }
107
}
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