mirror of
https://github.com/opdavies/build-configs.git
synced 2025-09-05 19:05:33 +01:00
Remove files that are ignored before they are generated
This commit is contained in:
parent
a56d9b2d5e
commit
f0121f8bc6
2 changed files with 59 additions and 0 deletions
34
src/Command/RemoveIgnoredFilesCommand.php
Normal file
34
src/Command/RemoveIgnoredFilesCommand.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\DataTransferObject\ConfigDto;
|
||||||
|
use App\DataTransferObject\TemplateFile;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
final class RemoveIgnoredFilesCommand
|
||||||
|
{
|
||||||
|
public function __construct(private array $filenames)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(array $filesToGenerateAndConfigurationData, \Closure $next)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array<int,TemplateFile> $filesToGenerate
|
||||||
|
* @var ConfigDto $configurationDataDto,
|
||||||
|
* @var array<non-empty-string,mixed> $configurationData
|
||||||
|
*/
|
||||||
|
[$configurationData, $configurationDataDto, $filesToGenerate] = $filesToGenerateAndConfigurationData;
|
||||||
|
|
||||||
|
$filesToGenerate = array_filter($filesToGenerate, function (TemplateFile $templateFile): bool {
|
||||||
|
return !collect($this->filenames)->contains($templateFile->name);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $next([$configurationDataDto, $filesToGenerate]);
|
||||||
|
}
|
||||||
|
}
|
25
tests/Kernel/Command/RemoveIgnoredFilesCommandTest.php
Normal file
25
tests/Kernel/Command/RemoveIgnoredFilesCommandTest.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Command\RemoveIgnoredFilesCommand;
|
||||||
|
use App\DataTransferObject\TemplateFile;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
|
||||||
|
class RemoveIgnoredFilesCommandTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
public function test_it_removes_any_ignored_files(): void
|
||||||
|
{
|
||||||
|
$filenamesToGenerate = [
|
||||||
|
new TemplateFile(data: '', name: 'phpcs.xml.dist'),
|
||||||
|
new TemplateFile(data: '', name: 'phpstan.neon.dist'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$filenamesToIgnore = ['phpstan.neon.dist'];
|
||||||
|
|
||||||
|
$command = new RemoveIgnoredFilesCommand($filenamesToIgnore);
|
||||||
|
|
||||||
|
$command->execute([[], [], $filenamesToGenerate], function ($result) {
|
||||||
|
self::assertCount(1, $result[1]);
|
||||||
|
self::assertSame('phpcs.xml.dist', $result[1][0]->name);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue