Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Reader.php

class Reader

Same name in this branch
  1. 11.1.x vendor/symfony/css-selector/Parser/Reader.php \Symfony\Component\CssSelector\Parser\Reader

@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

@internal This class is not covered by the backward compatibility promise for PHPUnit

Hierarchy

  • class \PHPUnit\Runner\Baseline\Reader

Expanded class hierarchy of Reader

1 file declares its use of Reader
Application.php in vendor/phpunit/phpunit/src/TextUI/Application.php

File

vendor/phpunit/phpunit/src/Runner/Baseline/Reader.php, line 30

Namespace

PHPUnit\Runner\Baseline
View source
final class Reader {
    
    /**
     * @psalm-param non-empty-string $baselineFile
     *
     * @throws CannotLoadBaselineException
     */
    public function read(string $baselineFile) : Baseline {
        if (!file_exists($baselineFile)) {
            throw new CannotLoadBaselineException(sprintf('Cannot read baseline %s, file does not exist', $baselineFile));
        }
        try {
            $document = (new XmlLoader())->loadFile($baselineFile);
        } catch (XmlException $e) {
            throw new CannotLoadBaselineException(sprintf('Cannot read baseline: %s', trim($e->getMessage())));
        }
        $version = (int) $document->documentElement
            ->getAttribute('version');
        if ($version !== Baseline::VERSION) {
            throw new CannotLoadBaselineException(sprintf('Cannot read baseline %s, version %d is not supported', $baselineFile, $version));
        }
        $baseline = new Baseline();
        $baselineDirectory = dirname(realpath($baselineFile));
        $xpath = new DOMXPath($document);
        foreach ($xpath->query('file') as $fileElement) {
            assert($fileElement instanceof DOMElement);
            $file = $baselineDirectory . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $fileElement->getAttribute('path'));
            foreach ($xpath->query('line', $fileElement) as $lineElement) {
                assert($lineElement instanceof DOMElement);
                $line = (int) $lineElement->getAttribute('number');
                $hash = $lineElement->getAttribute('hash');
                foreach ($xpath->query('issue', $lineElement) as $issueElement) {
                    assert($issueElement instanceof DOMElement);
                    $description = $issueElement->textContent;
                    assert($line > 0);
                    assert(!empty($hash));
                    assert(!empty($description));
                    $baseline->add(Issue::from($file, $line, $hash, $description));
                }
            }
        }
        return $baseline;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Reader::read public function @psalm-param non-empty-string $baselineFile

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal