1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-27 04:14:44 +01:00
PHP-Parser/test/PhpParser/CodeTestAbstract.php

31 lines
1021 B
PHP
Raw Normal View History

<?php declare(strict_types=1);
namespace PhpParser;
2017-04-27 18:14:07 +02:00
use PHPUnit\Framework\TestCase;
2017-01-19 22:23:19 +01:00
require_once __DIR__ . '/CodeTestParser.php';
2017-04-27 18:14:07 +02:00
abstract class CodeTestAbstract extends TestCase
{
protected function getTests($directory, $fileExtension, $chunksPerTest = 2) {
2017-01-19 22:23:19 +01:00
$parser = new CodeTestParser;
2017-08-13 14:35:03 +02:00
$allTests = [];
2017-01-19 22:23:19 +01:00
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;
}
}