getPathname()); $fileContents = file_get_contents($fileName); // evaluate @@{expr}@@ expressions $fileContents = preg_replace_callback( '/@@\{(.*?)\}@@/', function($matches) { return eval('return ' . $matches[1] . ';'); }, $fileContents ); // parse sections $parts = array_map('trim', explode('-----', $fileContents)); // first part is the name $name = array_shift($parts) . ' (' . $fileName . ')'; // multiple sections possible with always two forming a pair foreach (array_chunk($parts, 2) as $chunk) { list($expected, $mode) = $this->extractMode(canonicalize($chunk[1])); $tests[] = array($name, $chunk[0], $expected, $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)]; } }