Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\TextUI\XmlConfiguration;
11
 
12
use function sprintf;
13
use PHPUnit\Util\Xml\Exception as XmlException;
14
use PHPUnit\Util\Xml\Loader as XmlLoader;
15
use PHPUnit\Util\Xml\SchemaDetector;
16
 
17
/**
18
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
19
 */
20
final class Migrator
21
{
22
    /**
23
     * @throws Exception
24
     * @throws MigrationBuilderException
25
     * @throws MigrationException
26
     * @throws XmlException
27
     */
28
    public function migrate(string $filename): string
29
    {
30
        $origin = (new SchemaDetector)->detect($filename);
31
 
32
        if (!$origin->detected()) {
33
            throw new Exception(
34
                sprintf(
35
                    '"%s" is not a valid PHPUnit XML configuration file that can be migrated',
36
                    $filename,
37
                )
38
            );
39
        }
40
 
41
        $configurationDocument = (new XmlLoader)->loadFile(
42
            $filename,
43
            false,
44
            true,
45
            true
46
        );
47
 
48
        foreach ((new MigrationBuilder)->build($origin->version()) as $migration) {
49
            $migration->migrate($configurationDocument);
50
        }
51
 
52
        $configurationDocument->formatOutput       = true;
53
        $configurationDocument->preserveWhiteSpace = false;
54
 
55
        return $configurationDocument->saveXML();
56
    }
57
}