Mercurial > hg > isophonics-drupal-site
diff vendor/nikic/php-parser/test/PhpParser/CodeTestAbstract.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/vendor/nikic/php-parser/test/PhpParser/CodeTestAbstract.php Fri Feb 23 15:52:07 2018 +0000 +++ b/vendor/nikic/php-parser/test/PhpParser/CodeTestAbstract.php Mon Apr 23 09:33:26 2018 +0100 @@ -1,61 +1,30 @@ -<?php +<?php declare(strict_types=1); namespace PhpParser; -abstract class CodeTestAbstract extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +require_once __DIR__ . '/CodeTestParser.php'; + +abstract class CodeTestAbstract extends TestCase { - protected function getTests($directory, $fileExtension) { - $directory = realpath($directory); - $it = new \RecursiveDirectoryIterator($directory); - $it = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::LEAVES_ONLY); - $it = new \RegexIterator($it, '(\.' . preg_quote($fileExtension) . '$)'); - - $tests = array(); - foreach ($it as $file) { - $fileName = $file->getPathname(); - $fileContents = file_get_contents($fileName); - $fileContents = canonicalize($fileContents); - - // evaluate @@{expr}@@ expressions - $fileContents = preg_replace_callback( - '/@@\{(.*?)\}@@/', - function($matches) { - return eval('return ' . $matches[1] . ';'); - }, - $fileContents - ); - - // parse sections - $parts = preg_split("/\n-----(?:\n|$)/", $fileContents); + protected function getTests($directory, $fileExtension, $chunksPerTest = 2) { + $parser = new CodeTestParser; + $allTests = []; + foreach (filesInDir($directory, $fileExtension) as $fileName => $fileContents) { + list($name, $tests) = $parser->parseTest($fileContents, $chunksPerTest); // first part is the name - $name = array_shift($parts) . ' (' . $fileName . ')'; + $name .= ' (' . $fileName . ')'; $shortName = ltrim(str_replace($directory, '', $fileName), '/\\'); // multiple sections possible with always two forming a pair - $chunks = array_chunk($parts, 2); - foreach ($chunks as $i => $chunk) { - $dataSetName = $shortName . (count($chunks) > 1 ? '#' . $i : ''); - list($expected, $mode) = $this->extractMode($chunk[1]); - $tests[$dataSetName] = array($name, $chunk[0], $expected, $mode); + foreach ($tests as $i => list($mode, $parts)) { + $dataSetName = $shortName . (count($parts) > 1 ? '#' . $i : ''); + $allTests[$dataSetName] = array_merge([$name], $parts, [$mode]); } } - return $tests; - } - - private function extractMode($expected) { - $firstNewLine = strpos($expected, "\n"); - if (false === $firstNewLine) { - $firstNewLine = strlen($expected); - } - - $firstLine = substr($expected, 0, $firstNewLine); - if (0 !== strpos($firstLine, '!!')) { - return [$expected, null]; - } - - $expected = (string) substr($expected, $firstNewLine + 1); - return [$expected, substr($firstLine, 2)]; + return $allTests; } }