Compare commits
6 commits
1.x
...
ignore-fil
Author | SHA1 | Date | |
---|---|---|---|
2a6718c650 | |||
05f7c2b609 | |||
2b180e967c | |||
f0121f8bc6 | |||
a56d9b2d5e | |||
636aed29bb |
5 changed files with 107 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 Collection<int,TemplateFile> $filesToGenerate
|
||||||
|
* @var ConfigDto $configurationDataDto,
|
||||||
|
* @var array<non-empty-string,mixed> $configurationData
|
||||||
|
*/
|
||||||
|
[$configurationData, $configurationDataDto, $filesToGenerate] = $filesToGenerateAndConfigurationData;
|
||||||
|
|
||||||
|
$filesToGenerate = $filesToGenerate->filter(function (TemplateFile $templateFile): bool {
|
||||||
|
return !collect($this->filenames)->contains($templateFile->name);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $next([$configurationData, $configurationDataDto, $filesToGenerate]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,9 +8,11 @@ use App\Command\CreateFinalConfigurationDataCommand;
|
||||||
use App\Command\CreateListOfFilesToGenerateCommand;
|
use App\Command\CreateListOfFilesToGenerateCommand;
|
||||||
use App\Command\FindBuildConfigurationFileCommand;
|
use App\Command\FindBuildConfigurationFileCommand;
|
||||||
use App\Command\GenerateConfigurationFilesCommand;
|
use App\Command\GenerateConfigurationFilesCommand;
|
||||||
|
use App\Command\RemoveIgnoredFilesCommand;
|
||||||
use App\Command\ValidateConfigurationDataCommand;
|
use App\Command\ValidateConfigurationDataCommand;
|
||||||
use App\DataTransferObject\ConfigDto;
|
use App\DataTransferObject\ConfigDto;
|
||||||
use App\DataTransferObject\TemplateFile;
|
use App\DataTransferObject\TemplateFile;
|
||||||
|
use App\IgnoreFile;
|
||||||
use Illuminate\Pipeline\Pipeline;
|
use Illuminate\Pipeline\Pipeline;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
@ -72,6 +74,7 @@ class GenerateCommand extends Command
|
||||||
new CreateFinalConfigurationDataCommand(),
|
new CreateFinalConfigurationDataCommand(),
|
||||||
new ValidateConfigurationDataCommand(),
|
new ValidateConfigurationDataCommand(),
|
||||||
new CreateListOfFilesToGenerateCommand(),
|
new CreateListOfFilesToGenerateCommand(),
|
||||||
|
new RemoveIgnoredFilesCommand(IgnoreFile::parse()),
|
||||||
new GenerateConfigurationFilesCommand(
|
new GenerateConfigurationFilesCommand(
|
||||||
$this->filesystem,
|
$this->filesystem,
|
||||||
$this->twig,
|
$this->twig,
|
||||||
|
|
19
src/IgnoreFile.php
Normal file
19
src/IgnoreFile.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
final class IgnoreFile
|
||||||
|
{
|
||||||
|
public const FILENAME = '.bcignore';
|
||||||
|
|
||||||
|
public static function parse(): array
|
||||||
|
{
|
||||||
|
if (@stat(self::FILENAME) === false) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return explode("\n", file_get_contents(self::FILENAME));
|
||||||
|
}
|
||||||
|
}
|
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 = collect([
|
||||||
|
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[2]);
|
||||||
|
self::assertSame('phpcs.xml.dist', $result[2][0]->name);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
26
tests/Kernel/IgnoreFileTest.php
Normal file
26
tests/Kernel/IgnoreFileTest.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\IgnoreFile;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
|
||||||
|
class IgnoreFileTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
@unlink(IgnoreFile::FILENAME);
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_parses_a_list_of_file_names_from_an_ignore_file(): void
|
||||||
|
{
|
||||||
|
file_put_contents(IgnoreFile::FILENAME, join("\n", ['phpstan.neon.dist']));
|
||||||
|
|
||||||
|
self::assertSame(['phpstan.neon.dist'], IgnoreFile::parse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_an_empty_array_of_filenames_if_there_is_no_ignore_file(): void
|
||||||
|
{
|
||||||
|
self::assertSame([], IgnoreFile::parse());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue