File: validate_and_print.php

package info (click to toggle)
phpunit 12.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 50,160 kB
  • sloc: php: 101,772; xml: 2,084; makefile: 124; sh: 99
file content (45 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php declare(strict_types=1);
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace PHPUnit\TestFixture;

use const PHP_EOL;
use function file_get_contents;
use function libxml_clear_errors;
use function libxml_get_errors;
use function libxml_use_internal_errors;
use function printf;
use function trim;
use DOMDocument;

function validate_and_print(string $logfile): void
{
    libxml_use_internal_errors(true);

    $document = new DOMDocument;
    $document->load($logfile);

    if (!$document->schemaValidate(__DIR__ . '/../../../../src/Logging/OpenTestReporting/schema/otr.xsd')) {
        print 'Generated XML document does not validate against Open Test Reporting schemas:' . PHP_EOL . PHP_EOL;

        foreach (libxml_get_errors() as $error) {
            printf(
                '- Line %d: %s' . PHP_EOL,
                $error->line,
                trim($error->message),
            );
        }

        print PHP_EOL;
    }

    libxml_clear_errors();

    print file_get_contents($logfile);
}