3 declare(strict_types = 1);
19 require __DIR__ .
'/../../vendor/autoload.php';
21 if (PHP_SAPI !==
'cli') {
22 die(
'Script must be called from command line.' . chr(10));
36 private $fix =
false;
63 $output = new \Symfony\Component\Console\Output\ConsoleOutput();
67 foreach ($filesToProcess as $csvFixture) {
68 $fullFilePath = $csvFixture->getRealPath();
77 if ($singleFileScanResult !==
'') {
84 .
' is not in valid CSV format: ' . $singleFileScanResult;
88 if (!empty($outputLines)) {
89 foreach ($outputLines as $line) {
103 $finder =
new Symfony\Component\Finder\Finder();
106 ->in(__DIR__ .
'/../../typo3/sysext/*/Tests/Functional/**')
121 $lines = file($csvFixture);
123 foreach ($lines as $index => $line) {
125 $columns = str_getcsv($line);
126 if ($columnCount === 0) {
127 $columnCount = count($columns);
129 if (count($columns) !== $columnCount) {
131 if (count($columns) === 1 && strpos($columns[0],
'#') === 0) {
134 return 'Line ' . ($index + 1) .
'; Expected column count: ' . $columnCount .
'; Actual: ' . count($columns);
147 private function fixCsvFile(
string $csvFixture): bool
149 $changeNeeded =
false;
151 $lines = file($csvFixture);
154 foreach ($lines as $line) {
156 $csvLine = str_getcsv($line);
157 $csvLines[] = $csvLine;
158 foreach ($csvLine as $columnNumber => $columnContent) {
159 if (!empty($columnContent) && $columnNumber + 1 > $neededColumns) {
160 $neededColumns = $columnNumber + 1;
164 foreach ($csvLines as $csvLine) {
166 if (count($csvLine) !== $neededColumns && substr($csvLine[0], 0, 2) !==
'# ') {
167 $changeNeeded =
true;
173 $fileHandle = fopen($csvFixture,
'w');
175 throw new \Exception(
'Opening file "' . $csvFixture .
'" for writing failed.');
177 foreach ($csvLines as $csvLine) {
179 $csvLine = array_slice(array_pad($csvLine, $neededColumns,
''), 0, $neededColumns);
181 $line = array_reduce($csvLine,
function ($carry, $column) use (&$isComment) {
182 if ($carry ===
null && substr($column, 0, 2) ===
'# ') {
185 } elseif ($isComment) {
188 } elseif (empty($column) && $column !==
'0') {
190 $carry .= $carry ===
null ?
'' :
',';
191 } elseif (MathUtility::canBeInterpretedAsInteger($column)) {
193 $carry .= ($carry ===
null ?
'' :
',') . $column;
196 $column = str_replace(
'"',
'""', $column);
197 $carry .= ($carry ===
null ?
'' :
',') .
'"' . $column .
'"';
201 fwrite($fileHandle, $line . chr(10));
205 return $changeNeeded;
210 $pathSegment = str_replace(
'Build/Scripts',
'', __DIR__);
211 return str_replace($pathSegment,
'', $fullPath);
222 $pattern =
'#typo3[\\\\/]sysext[\\\\/](?<extName>[a-z].+?)[\\\\/]Tests[\\\\/]Functional[\\\\/](?<file>.*)#';
223 preg_match_all($pattern, $filename, $matches, PREG_SET_ORDER, 0);
224 if (isset($matches[0])) {
225 return 'EXT:' . $matches[0][
'extName'] .
' > ' . $matches[0][
'file'];
232 $args = getopt(
'', [
'fix',
'fixAll']);
233 if (array_key_exists(
'fix',
$args)) {
236 if (array_key_exists(
'fixAll',
$args)) {