Вход Регистрация
Файл: src/vendor/nikic/php-parser/test/PhpParser/CodeTestAbstract.php
Строк: 63
<?php

namespace PhpParser;

abstract class 
CodeTestAbstract extends PHPUnit_Framework_TestCase
{
    protected function 
getTests($directory$fileExtension) {
        
$it = new RecursiveDirectoryIterator($directory);
        
$it = new RecursiveIteratorIterator($itRecursiveIteratorIterator::LEAVES_ONLY);
        
$it = new RegexIterator($it'(.' preg_quote($fileExtension) . '$)');

        
$tests = array();
        foreach (
$it as $file) {
            
$fileName realpath($file->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 ')';
            
$shortName basename($fileName'.test');

            
// multiple sections possible with always two forming a pair
            
$chunks array_chunk($parts2);
            foreach (
$chunks as $i => $chunk) {
                
$dataSetName $shortName . (count($chunks) > '#' $i '');
                list(
$expected$mode) = $this->extractMode(canonicalize($chunk[1]));
                
$tests[$dataSetName] = array($name$chunk[0], $expected$mode);
            }
        }

        return 
$tests;
    }

    private function 
extractMode($expected) {
        
$firstNewLine strpos($expected"n");
        if (
false === $firstNewLine) {
            
$firstNewLine strlen($expected);
        }

        
$firstLine substr($expected0$firstNewLine);
        if (
!== strpos($firstLine'!!')) {
            return [
$expectednull];
        }

        
$expected = (string) substr($expected$firstNewLine 1);
        return [
$expectedsubstr($firstLine2)];
    }
}
Онлайн: 2
Реклама