php-parser/test/PhpParser/CodeTestAbstract.php

29 lines
987 B
PHP
Raw Normal View History

<?php
namespace PhpParser;
2017-01-19 22:23:19 +01:00
require_once __DIR__ . '/CodeTestParser.php';
abstract class CodeTestAbstract extends \PHPUnit_Framework_TestCase
{
protected function getTests($directory, $fileExtension, $chunksPerTest = 2) {
2017-01-19 22:23:19 +01:00
$parser = new CodeTestParser;
$allTests = array();
foreach (filesInDir($directory, $fileExtension) as $fileName => $fileContents) {
list($name, $tests) = $parser->parseTest($fileContents, $chunksPerTest);
2011-11-27 21:43:27 +01:00
// first part is the name
2017-01-19 22:23:19 +01:00
$name .= ' (' . $fileName . ')';
$shortName = ltrim(str_replace($directory, '', $fileName), '/\\');
2011-11-27 21:43:27 +01:00
// multiple sections possible with always two forming a pair
2017-01-19 22:23:19 +01:00
foreach ($tests as $i => list($mode, $parts)) {
$dataSetName = $shortName . (count($parts) > 1 ? '#' . $i : '');
$allTests[$dataSetName] = array_merge([$name], $parts, [$mode]);
2011-11-27 21:43:27 +01:00
}
}
2017-01-19 22:23:19 +01:00
return $allTests;
}
}