PhpCsFixer\Test\IntegrationCaseFactory::create PHP Метод

create() публичный Метод

public create ( Symfony\Component\Finder\SplFileInfo $file ) : IntegrationCase
$file Symfony\Component\Finder\SplFileInfo
Результат IntegrationCase
    public function create(SplFileInfo $file)
    {
        try {
            if (!preg_match('/^
                            --TEST--           \\r?\\n(?<title>          .*?)
                       \\s   --RULESET--        \\r?\\n(?<ruleset>        .*?)
                    (?:\\s   --CONFIG--         \\r?\\n(?<config>         .*?))?
                    (?:\\s   --SETTINGS--       \\r?\\n(?<settings>       .*?))?
                    (?:\\s   --REQUIREMENTS--   \\r?\\n(?<requirements>   .*?))?
                    (?:\\s   --EXPECT--         \\r?\\n(?<expect>         .*?\\r?\\n*))?
                    (?:\\s   --INPUT--          \\r?\\n(?<input>          .*))?
                $/sx', $file->getContents(), $match)) {
                throw new \InvalidArgumentException('File format is invalid.');
            }
            $match = array_merge(array('config' => null, 'settings' => null, 'requirements' => null, 'expect' => null, 'input' => null), $match);
            return new IntegrationCase($file->getRelativePathname(), $match['title'], $this->determineSettings($match['settings']), $this->determineRequirements($match['requirements']), $this->determineConfig($match['config']), $this->determineRuleset($match['ruleset']), $this->determineExpectedCode($match['expect'], $file), $this->determineInputCode($match['input'], $file));
        } catch (\InvalidArgumentException $e) {
            throw new \InvalidArgumentException(sprintf('%s Test file: "%s".', $e->getMessage(), $file->getRelativePathname()), $e->getCode(), $e);
        }
    }

Usage Example

 /**
  * Creates test data by parsing '.test' files.
  *
  * @return IntegrationCase[][]
  */
 public function getTests()
 {
     $fixturesDir = realpath(static::getFixturesDir());
     if (!is_dir($fixturesDir)) {
         throw new \UnexpectedValueException(sprintf('Given fixture dir "%s" is not a directory.', $fixturesDir));
     }
     $factory = new IntegrationCaseFactory();
     $tests = array();
     foreach (Finder::create()->files()->in($fixturesDir) as $file) {
         if ('test' !== $file->getExtension()) {
             continue;
         }
         $tests[] = array($factory->create($file->getRelativePathname(), file_get_contents($file->getRealpath())));
     }
     return $tests;
 }