From 2b76b3dc8d35ac1dc260ee83e9ff3af073023f76 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 13:57:09 +0200 Subject: [PATCH 01/31] [TASK] Minor code cleanups --- fractor/config/application.php | 5 ----- fractor/src/Command/ProcessCommand.php | 6 ++---- fractor/src/Fractor/FractorRunner.php | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/fractor/config/application.php b/fractor/config/application.php index dfa98f88..610266f3 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -1,8 +1,6 @@ set(FractorApplication::class) ->public(); - $services->set(FileFinder::class); - $services->set(FractorRunner::class); - $services->set(FractorConfig::class) ->lazy(true); }; diff --git a/fractor/src/Command/ProcessCommand.php b/fractor/src/Command/ProcessCommand.php index 7d7714bf..3abb338d 100644 --- a/fractor/src/Command/ProcessCommand.php +++ b/fractor/src/Command/ProcessCommand.php @@ -18,10 +18,8 @@ public function __construct(private readonly FractorConfig $config, private read parent::__construct(); } - protected function configure() + protected function configure(): void { - parent::configure(); - $this->addOption( 'config', 'c', @@ -34,6 +32,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $this->runner->run($this->config); - return 0; + return Command::SUCCESS; } } diff --git a/fractor/src/Fractor/FractorRunner.php b/fractor/src/Fractor/FractorRunner.php index 43665ccb..32299dfe 100644 --- a/fractor/src/Fractor/FractorRunner.php +++ b/fractor/src/Fractor/FractorRunner.php @@ -15,7 +15,7 @@ final class FractorRunner /** * @param list $processors */ - public function __construct(private readonly FileFinder $fileFinder, private readonly array $processors) + public function __construct(private readonly FileFinder $fileFinder, private readonly iterable $processors) { } From ff1b213468208aeb4aa663deffe918023a6bfe2f Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 13:58:37 +0200 Subject: [PATCH 02/31] [TASK] Remove DummyRule --- tests/typo3-flexform/fractor.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/typo3-flexform/fractor.php b/tests/typo3-flexform/fractor.php index 126c6ea8..45c8d3d9 100644 --- a/tests/typo3-flexform/fractor.php +++ b/tests/typo3-flexform/fractor.php @@ -1,7 +1,6 @@ withFileProcessor(XmlFileProcessor::class); $config->withRule(AddRenderTypeToFlexFormFractor::class); - $config->withRule(DummyRule::class); }; From 4addf0654c584a8b1310d789cf074c5ce17882ef Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 14:00:31 +0200 Subject: [PATCH 03/31] [TASK] Make services private per default --- fractor/config/application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/fractor/config/application.php b/fractor/config/application.php index 610266f3..37013cb2 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -8,6 +8,7 @@ $services = $containerConfigurator->services(); $services->defaults() ->autowire() + ->private() ->autoconfigure(); $services->load('a9f\\Fractor\\', __DIR__ . '/../src/') From b14913f90ec82e8afcd52a2be201130cedda5e8f Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 14:23:43 +0200 Subject: [PATCH 04/31] [TASK] Add AbstractFractorTestCase --- .../Exception/ShouldNotHappenException.php | 9 ++++ .../PHPUnit/AbstractFractorTestCase.php | 49 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 fractor/src/Exception/ShouldNotHappenException.php create mode 100644 fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php diff --git a/fractor/src/Exception/ShouldNotHappenException.php b/fractor/src/Exception/ShouldNotHappenException.php new file mode 100644 index 00000000..aab45850 --- /dev/null +++ b/fractor/src/Exception/ShouldNotHappenException.php @@ -0,0 +1,9 @@ +bootFromConfigFile($this->provideConfigFilePath()); + } + + protected function bootFromConfigFile(string $configFile): void + { + if(self::$currentContainer === null) { + self::$currentContainer = (new ContainerBuilder())->createDependencyInjectionContainer($configFile); + } + } + + /** + * Syntax-sugar to remove static + * + * @template T of object + * @phpstan-param class-string $type + * @phpstan-return T + */ + protected function getService(string $type): object + { + if (self::$currentContainer === null) { + throw new ShouldNotHappenException('First, create container with "bootWithConfigFileInfos([...])"'); + } + + $object = self::$currentContainer->get($type); + if ($object === null) { + $message = sprintf('Service "%s" was not found', $type); + throw new ShouldNotHappenException($message); + } + + return $object; + } +} \ No newline at end of file From 5cf3ad5d1cc56ac61134d6db07a6bd45efd4007e Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 14:37:11 +0200 Subject: [PATCH 05/31] [TASK] Add AbstractFractorTestCase --- .gitignore | 1 + fractor/config/application.php | 5 +---- .../src/Testing/PHPUnit/AbstractFractorTestCase.php | 8 ++++++-- fractor/tests/FileSystem/FileFinderTest.php | 11 +++++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..143c4262 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.phpunit.result.cache \ No newline at end of file diff --git a/fractor/config/application.php b/fractor/config/application.php index 37013cb2..0186ab74 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -8,15 +8,12 @@ $services = $containerConfigurator->services(); $services->defaults() ->autowire() - ->private() + ->public() ->autoconfigure(); $services->load('a9f\\Fractor\\', __DIR__ . '/../src/') ->exclude('../src/Configuration/'); - $services->set(FractorApplication::class) - ->public(); - $services->set(FractorConfig::class) ->lazy(true); }; diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index 31cbedaa..ba854637 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -5,20 +5,24 @@ use a9f\Fractor\DependencyInjection\ContainerBuilder; use a9f\Fractor\Exception\ShouldNotHappenException; +use a9f\Fractor\Fractor\FractorRunner; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; abstract class AbstractFractorTestCase extends TestCase { private static ?ContainerInterface $currentContainer = null; - abstract protected function provideConfigFilePath(): string; + private FractorRunner $fractorRunner; + + abstract protected function provideConfigFilePath(): ?string; protected function setUp(): void { $this->bootFromConfigFile($this->provideConfigFilePath()); + $this->fractorRunner = $this->getService(FractorRunner::class); } - protected function bootFromConfigFile(string $configFile): void + protected function bootFromConfigFile(?string $configFile): void { if(self::$currentContainer === null) { self::$currentContainer = (new ContainerBuilder())->createDependencyInjectionContainer($configFile); diff --git a/fractor/tests/FileSystem/FileFinderTest.php b/fractor/tests/FileSystem/FileFinderTest.php index 16e4e732..713c9ace 100644 --- a/fractor/tests/FileSystem/FileFinderTest.php +++ b/fractor/tests/FileSystem/FileFinderTest.php @@ -5,17 +5,19 @@ namespace FileSystem; use a9f\Fractor\FileSystem\FileFinder; +use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use UnexpectedValueException; -final class FileFinderTest extends TestCase +final class FileFinderTest extends AbstractFractorTestCase { private FileFinder $subject; protected function setUp(): void { - $this->subject = new FileFinder(); + parent::setUp(); + $this->subject = $this->getService(FileFinder::class); } #[Test] @@ -36,4 +38,9 @@ public function findAllNonEmptyFilesInGivenDirectoriesWithGivenExtensions(): voi { self::assertCount(2, $this->subject->findFiles([__DIR__ . '/Fixture/DirectorToSearchIn'], ['txt', 'json'])); } + + protected function provideConfigFilePath(): ?string + { + return null; + } } From 7a0cc7e267f73efbfa7da68d72aca10dfb23aa84 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 15:14:16 +0200 Subject: [PATCH 06/31] [TASK] Add test for changing text files --- fractor/config/application.php | 2 +- .../DependencyInjection/ContainerBuilder.php | 7 ++++- .../PHPUnit/AbstractFractorTestCase.php | 17 ++++++++-- fractor/tests/FileSystem/FileFinderTest.php | 2 +- .../FractorRunner/Assertions/my_text_file.txt | 1 + .../FractorRunner/Fixture/my_text_file.txt | 1 + .../FractorRunner/FractorRunnerTest.php | 28 +++++++++++++++++ .../FractorRunner/config/application.php | 20 ++++++++++++ .../Fractor/FractorRunner/config/fractor.php | 10 ++++++ fractor/tests/Helper/Contract/TextRule.php | 11 +++++++ .../FileProcessor/TextFileProcessor.php | 31 +++++++++++++++++++ .../tests/Helper/Rules/ReplaceXXXTextRule.php | 15 +++++++++ 12 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 fractor/tests/Fractor/FractorRunner/Assertions/my_text_file.txt create mode 100644 fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt create mode 100644 fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php create mode 100644 fractor/tests/Fractor/FractorRunner/config/application.php create mode 100644 fractor/tests/Fractor/FractorRunner/config/fractor.php create mode 100644 fractor/tests/Helper/Contract/TextRule.php create mode 100644 fractor/tests/Helper/FileProcessor/TextFileProcessor.php create mode 100644 fractor/tests/Helper/Rules/ReplaceXXXTextRule.php diff --git a/fractor/config/application.php b/fractor/config/application.php index 0186ab74..b62661be 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -15,5 +15,5 @@ ->exclude('../src/Configuration/'); $services->set(FractorConfig::class) - ->lazy(true); + ->lazy(); }; diff --git a/fractor/src/DependencyInjection/ContainerBuilder.php b/fractor/src/DependencyInjection/ContainerBuilder.php index 176ca082..ea9bf44d 100644 --- a/fractor/src/DependencyInjection/ContainerBuilder.php +++ b/fractor/src/DependencyInjection/ContainerBuilder.php @@ -13,7 +13,7 @@ class ContainerBuilder { - public function createDependencyInjectionContainer(?string $fractorConfigFile): ContainerInterface + public function createDependencyInjectionContainer(?string $fractorConfigFile, array $additionalConfigFiles = []): ContainerInterface { $config = new FractorConfig(); @@ -34,6 +34,11 @@ public function createDependencyInjectionContainer(?string $fractorConfigFile): $config->import($fractorConfigFile); } + foreach ($additionalConfigFiles as $additionalConfigFile) { + $fileLoader = new PhpFileLoader($config, new FileLocator(dirname($additionalConfigFile))); + $fileLoader->load($additionalConfigFile); + } + $this->registerConfiguredRules($config); $this->registerConfiguredFileProcessors($config); diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index ba854637..803c0198 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -3,6 +3,7 @@ namespace a9f\Fractor\Testing\PHPUnit; +use a9f\Fractor\Configuration\FractorConfig; use a9f\Fractor\DependencyInjection\ContainerBuilder; use a9f\Fractor\Exception\ShouldNotHappenException; use a9f\Fractor\Fractor\FractorRunner; @@ -16,19 +17,29 @@ abstract class AbstractFractorTestCase extends TestCase abstract protected function provideConfigFilePath(): ?string; + protected function additionalConfigurationFiles(): array + { + return []; + } + protected function setUp(): void { - $this->bootFromConfigFile($this->provideConfigFilePath()); + $this->bootFromConfigFile(); $this->fractorRunner = $this->getService(FractorRunner::class); } - protected function bootFromConfigFile(?string $configFile): void + protected function bootFromConfigFile(): void { if(self::$currentContainer === null) { - self::$currentContainer = (new ContainerBuilder())->createDependencyInjectionContainer($configFile); + self::$currentContainer = (new ContainerBuilder())->createDependencyInjectionContainer($this->provideConfigFilePath(), $this->additionalConfigurationFiles()); } } + protected function doTest(): void + { + $this->fractorRunner->run($this->getService(FractorConfig::class)); + } + /** * Syntax-sugar to remove static * diff --git a/fractor/tests/FileSystem/FileFinderTest.php b/fractor/tests/FileSystem/FileFinderTest.php index 713c9ace..41d383bb 100644 --- a/fractor/tests/FileSystem/FileFinderTest.php +++ b/fractor/tests/FileSystem/FileFinderTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FileSystem; +namespace a9f\Fractor\Tests\FileSystem; use a9f\Fractor\FileSystem\FileFinder; use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase; diff --git a/fractor/tests/Fractor/FractorRunner/Assertions/my_text_file.txt b/fractor/tests/Fractor/FractorRunner/Assertions/my_text_file.txt new file mode 100644 index 00000000..fc6a78a0 --- /dev/null +++ b/fractor/tests/Fractor/FractorRunner/Assertions/my_text_file.txt @@ -0,0 +1 @@ +The text YYY will be replaced by YYY \ No newline at end of file diff --git a/fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt b/fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt new file mode 100644 index 00000000..fc6a78a0 --- /dev/null +++ b/fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt @@ -0,0 +1 @@ +The text YYY will be replaced by YYY \ No newline at end of file diff --git a/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php new file mode 100644 index 00000000..a7ac2093 --- /dev/null +++ b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php @@ -0,0 +1,28 @@ +doTest(); + self::assertFileEquals(__DIR__ . '/Assertions/my_text_file.txt', __DIR__ . '/Fixture/my_text_file.txt'); + } + + protected function additionalConfigurationFiles(): array + { + return [ + __DIR__ . '/config/application.php' + ]; + } +} \ No newline at end of file diff --git a/fractor/tests/Fractor/FractorRunner/config/application.php b/fractor/tests/Fractor/FractorRunner/config/application.php new file mode 100644 index 00000000..46fb1d23 --- /dev/null +++ b/fractor/tests/Fractor/FractorRunner/config/application.php @@ -0,0 +1,20 @@ +services(); + $services->defaults() + ->autowire() + ->autoconfigure(); + + $services->set(ReplaceXXXTextRule::class); + + $services->set(TextFileProcessor::class)->arg('$rules', tagged_iterator('fractor.text_rules')); + $containerBuilder->registerForAutoconfiguration(TextRule::class)->addTag('fractor.text_rules'); +}; diff --git a/fractor/tests/Fractor/FractorRunner/config/fractor.php b/fractor/tests/Fractor/FractorRunner/config/fractor.php new file mode 100644 index 00000000..9689111c --- /dev/null +++ b/fractor/tests/Fractor/FractorRunner/config/fractor.php @@ -0,0 +1,10 @@ +setPaths([__DIR__ .'/../Fixture']); + $config->setFileExtensions(['txt']); + $config->withFileProcessor(TextFileProcessor::class); +}; diff --git a/fractor/tests/Helper/Contract/TextRule.php b/fractor/tests/Helper/Contract/TextRule.php new file mode 100644 index 00000000..dfa3408a --- /dev/null +++ b/fractor/tests/Helper/Contract/TextRule.php @@ -0,0 +1,11 @@ + $rules + */ + public function __construct(private iterable $rules) + { + } + + public function canHandle(\SplFileInfo $file): bool + { + return $file->getExtension() === 'txt'; + } + + public function handle(\SplFileInfo $file): void + { + foreach ($this->rules as $rule) { + $fileContent = file_get_contents($file->getPathname()); + $changedFileContent = $rule->apply($fileContent); + file_put_contents($file->getPathname(), $changedFileContent); + } + } +} \ No newline at end of file diff --git a/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php b/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php new file mode 100644 index 00000000..240dec4a --- /dev/null +++ b/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php @@ -0,0 +1,15 @@ + Date: Tue, 16 Apr 2024 15:37:58 +0200 Subject: [PATCH 07/31] [TASK] Simplify configuration for rules and runner --- fractor-xml/config/application.php | 11 +++++- fractor-xml/config/fractor.php | 8 ----- fractor-xml/src/AbstractXmlFractor.php | 2 +- .../XmlFractorCompilerPass.php | 34 ------------------- fractor-xml/src/XmlFileProcessor.php | 2 +- fractor/config/application.php | 10 ++++-- fractor/src/Contract/FractorRule.php | 7 ---- .../FileProcessorCompilerPass.php | 24 ------------- .../DependencyInjection/ContainerBuilder.php | 21 ------------ fractor/tests/Helper/Contract/TextRule.php | 2 +- 10 files changed, 21 insertions(+), 100 deletions(-) delete mode 100644 fractor-xml/config/fractor.php delete mode 100644 fractor-xml/src/DependencyInjection/XmlFractorCompilerPass.php delete mode 100644 fractor/src/Contract/FractorRule.php delete mode 100644 fractor/src/DependencyInjection/CompilerPass/FileProcessorCompilerPass.php diff --git a/fractor-xml/config/application.php b/fractor-xml/config/application.php index be45e400..c991e62b 100644 --- a/fractor-xml/config/application.php +++ b/fractor-xml/config/application.php @@ -1,12 +1,21 @@ services(); $services->defaults() ->autowire() ->autoconfigure(); $services->load('a9f\\FractorXml\\', __DIR__ . '/../src/'); + + + $services->set(XmlFileProcessor::class)->arg('$rules', tagged_iterator('fractor.xml_rule')); + + $containerBuilder->registerForAutoconfiguration(XmlFractor::class)->addTag('fractor.xml_rule'); }; diff --git a/fractor-xml/config/fractor.php b/fractor-xml/config/fractor.php deleted file mode 100644 index 0c926c79..00000000 --- a/fractor-xml/config/fractor.php +++ /dev/null @@ -1,8 +0,0 @@ -addCompilerPass(new XmlFractorCompilerPass()); -}; diff --git a/fractor-xml/src/AbstractXmlFractor.php b/fractor-xml/src/AbstractXmlFractor.php index 4b21abd3..ab0eb35c 100644 --- a/fractor-xml/src/AbstractXmlFractor.php +++ b/fractor-xml/src/AbstractXmlFractor.php @@ -6,7 +6,7 @@ use a9f\FractorXml\Contract\DomNodeVisitor; use a9f\FractorXml\Contract\XmlFractor; -abstract class AbstractXmlFractor implements DomNodeVisitor, XmlFractor, FractorRule +abstract class AbstractXmlFractor implements DomNodeVisitor, XmlFractor { public function beforeTraversal(\DOMNode $rootNode): void { diff --git a/fractor-xml/src/DependencyInjection/XmlFractorCompilerPass.php b/fractor-xml/src/DependencyInjection/XmlFractorCompilerPass.php deleted file mode 100644 index fdcc3c08..00000000 --- a/fractor-xml/src/DependencyInjection/XmlFractorCompilerPass.php +++ /dev/null @@ -1,34 +0,0 @@ -hasDefinition(XmlFileProcessor::class)) { - return; - } - - $taggedServices = $container->findTaggedServiceIds('fractor.rule'); - $xmlRules = array_filter( - $taggedServices, - static fn (string $class) => in_array(XmlFractor::class, class_implements($class) ?: []), - ARRAY_FILTER_USE_KEY - ); - $references = array_map(static fn ($id) => new Reference($id), array_keys($xmlRules)); - - $definition = $container->findDefinition(XmlFileProcessor::class); - $definition->setArgument('$rules', $references); - } -} diff --git a/fractor-xml/src/XmlFileProcessor.php b/fractor-xml/src/XmlFileProcessor.php index 061cc1c2..fe60f41b 100644 --- a/fractor-xml/src/XmlFileProcessor.php +++ b/fractor-xml/src/XmlFileProcessor.php @@ -10,7 +10,7 @@ final class XmlFileProcessor implements FileProcessor /** * @param list $rules */ - public function __construct(private readonly array $rules) + public function __construct(private readonly iterable $rules) { } diff --git a/fractor/config/application.php b/fractor/config/application.php index b62661be..1447a00c 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -1,10 +1,13 @@ services(); $services->defaults() ->autowire() @@ -14,6 +17,9 @@ $services->load('a9f\\Fractor\\', __DIR__ . '/../src/') ->exclude('../src/Configuration/'); + $services->set(FractorRunner::class)->arg('$processors', tagged_iterator('fractor.file_processor')); $services->set(FractorConfig::class) ->lazy(); + + $containerBuilder->registerForAutoconfiguration(FileProcessor::class)->addTag('fractor.file_processor'); }; diff --git a/fractor/src/Contract/FractorRule.php b/fractor/src/Contract/FractorRule.php deleted file mode 100644 index e1f5f8a3..00000000 --- a/fractor/src/Contract/FractorRule.php +++ /dev/null @@ -1,7 +0,0 @@ -has(FractorRunner::class)) { - return; - } - - $taggedServices = $container->findTaggedServiceIds('fractor.file_processor'); - $references = array_map(static fn ($id) => new Reference($id), array_keys($taggedServices)); - - $definition = $container->findDefinition(FractorRunner::class); - $definition->setArgument('$processors', $references); - } -} diff --git a/fractor/src/DependencyInjection/ContainerBuilder.php b/fractor/src/DependencyInjection/ContainerBuilder.php index ea9bf44d..70afdec1 100644 --- a/fractor/src/DependencyInjection/ContainerBuilder.php +++ b/fractor/src/DependencyInjection/ContainerBuilder.php @@ -4,7 +4,6 @@ use a9f\Fractor\Configuration\FractorConfig; use a9f\Fractor\DependencyInjection\CompilerPass\CommandsCompilerPass; -use a9f\Fractor\DependencyInjection\CompilerPass\FileProcessorCompilerPass; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -28,7 +27,6 @@ public function createDependencyInjectionContainer(?string $fractorConfigFile, a $this->importExtensionConfigurations($config); $config->addCompilerPass(new CommandsCompilerPass()); - $config->addCompilerPass(new FileProcessorCompilerPass()); if ($fractorConfigFile !== null && is_file($fractorConfigFile)) { $config->import($fractorConfigFile); @@ -39,30 +37,11 @@ public function createDependencyInjectionContainer(?string $fractorConfigFile, a $fileLoader->load($additionalConfigFile); } - $this->registerConfiguredRules($config); - $this->registerConfiguredFileProcessors($config); - $config->compile(); return $config; } - private function registerConfiguredRules(FractorConfig $config): void - { - foreach ($config->getRules() as $rule) { - $config->registerForAutoconfiguration($rule) - ->addTag('fractor.rule'); - } - } - - private function registerConfiguredFileProcessors(FractorConfig $config): void - { - foreach ($config->getFileProcessors() as $processor) { - $config->registerForAutoconfiguration($processor) - ->addTag('fractor.file_processor'); - } - } - private function importExtensionConfigurations(FractorConfig $config): void { if (!class_exists('a9f\\FractorExtensionInstaller\\Generated\\InstalledPackages')) { diff --git a/fractor/tests/Helper/Contract/TextRule.php b/fractor/tests/Helper/Contract/TextRule.php index dfa3408a..6088bd86 100644 --- a/fractor/tests/Helper/Contract/TextRule.php +++ b/fractor/tests/Helper/Contract/TextRule.php @@ -5,7 +5,7 @@ use a9f\Fractor\Contract\FractorRule; -interface TextRule extends FractorRule +interface TextRule { public function apply(string $fileContent): string; } \ No newline at end of file From 668330977c0c7c99e6c5ade5278b599a508b727f Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 16:05:25 +0200 Subject: [PATCH 08/31] [TASK] Add phpunit.xml for fractor lib --- fractor/.gitignore | 3 ++- fractor/phpunit.xml | 13 +++++++++++++ .../src/Testing/PHPUnit/AbstractFractorTestCase.php | 10 ++++------ .../tests/Fractor/FractorRunner/config/fractor.php | 4 +--- 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 fractor/phpunit.xml diff --git a/fractor/.gitignore b/fractor/.gitignore index 94d6d75a..a89e45ef 100644 --- a/fractor/.gitignore +++ b/fractor/.gitignore @@ -1,2 +1,3 @@ /vendor/ -/composer.lock \ No newline at end of file +/composer.lock +.phpunit.cache \ No newline at end of file diff --git a/fractor/phpunit.xml b/fractor/phpunit.xml new file mode 100644 index 00000000..3e3375ed --- /dev/null +++ b/fractor/phpunit.xml @@ -0,0 +1,13 @@ + + + + + tests + + + + + ./src + + + diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index 803c0198..c0ff1af2 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -12,7 +12,7 @@ abstract class AbstractFractorTestCase extends TestCase { - private static ?ContainerInterface $currentContainer = null; + private ?ContainerInterface $currentContainer = null; private FractorRunner $fractorRunner; abstract protected function provideConfigFilePath(): ?string; @@ -30,9 +30,7 @@ protected function setUp(): void protected function bootFromConfigFile(): void { - if(self::$currentContainer === null) { - self::$currentContainer = (new ContainerBuilder())->createDependencyInjectionContainer($this->provideConfigFilePath(), $this->additionalConfigurationFiles()); - } + $this->currentContainer = (new ContainerBuilder())->createDependencyInjectionContainer($this->provideConfigFilePath(), $this->additionalConfigurationFiles()); } protected function doTest(): void @@ -49,11 +47,11 @@ protected function doTest(): void */ protected function getService(string $type): object { - if (self::$currentContainer === null) { + if ($this->currentContainer === null) { throw new ShouldNotHappenException('First, create container with "bootWithConfigFileInfos([...])"'); } - $object = self::$currentContainer->get($type); + $object = $this->currentContainer->get($type); if ($object === null) { $message = sprintf('Service "%s" was not found', $type); throw new ShouldNotHappenException($message); diff --git a/fractor/tests/Fractor/FractorRunner/config/fractor.php b/fractor/tests/Fractor/FractorRunner/config/fractor.php index 9689111c..baf724c3 100644 --- a/fractor/tests/Fractor/FractorRunner/config/fractor.php +++ b/fractor/tests/Fractor/FractorRunner/config/fractor.php @@ -1,10 +1,8 @@ setPaths([__DIR__ .'/../Fixture']); + $config->setPaths([__DIR__ .'/../Fixture/']); $config->setFileExtensions(['txt']); - $config->withFileProcessor(TextFileProcessor::class); }; From 5f774c0dc931a979c74f22450088ed04f51c1460 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 16:06:49 +0200 Subject: [PATCH 09/31] [TASK] Add phpunit.xml for fractor-xml lib --- fractor-xml/.gitignore | 3 ++- fractor-xml/phpunit.xml | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 fractor-xml/phpunit.xml diff --git a/fractor-xml/.gitignore b/fractor-xml/.gitignore index 94d6d75a..a89e45ef 100644 --- a/fractor-xml/.gitignore +++ b/fractor-xml/.gitignore @@ -1,2 +1,3 @@ /vendor/ -/composer.lock \ No newline at end of file +/composer.lock +.phpunit.cache \ No newline at end of file diff --git a/fractor-xml/phpunit.xml b/fractor-xml/phpunit.xml new file mode 100644 index 00000000..82a7d07f --- /dev/null +++ b/fractor-xml/phpunit.xml @@ -0,0 +1,13 @@ + + + + + tests + + + + + ./src + + + From 717988e518619b38f4c7b34672a0ea73d09e1f58 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 22:32:22 +0200 Subject: [PATCH 10/31] [TASK] Fix tests for TextFileProcessor --- fractor/composer.json | 1 + fractor/config/application.php | 7 ++- fractor/src/Contract/FileProcessor.php | 4 +- fractor/src/FileSystem/FileCollector.php | 28 ++++++++++++ fractor/src/Fractor/FractorRunner.php | 13 ++++-- .../PHPUnit/AbstractFractorTestCase.php | 3 ++ fractor/src/ValueObject/File.php | 45 +++++++++++++++++++ .../FractorRunner/Fixture/my_text_file.txt | 2 +- .../FractorRunner/FractorRunnerTest.php | 3 +- fractor/tests/Helper/Contract/TextRule.php | 3 +- .../FileProcessor/TextFileProcessor.php | 7 ++- .../tests/Helper/Rules/ReplaceXXXTextRule.php | 7 ++- 12 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 fractor/src/FileSystem/FileCollector.php create mode 100644 fractor/src/ValueObject/File.php diff --git a/fractor/composer.json b/fractor/composer.json index bba74871..98b1e96c 100644 --- a/fractor/composer.json +++ b/fractor/composer.json @@ -12,6 +12,7 @@ ], "require": { "php": "^8.2", + "nette/utils": "^4.0", "symfony/config": "^6.4", "symfony/console": "^6.4", "symfony/dependency-injection": "^6.4", diff --git a/fractor/config/application.php b/fractor/config/application.php index 1447a00c..6f72b7f0 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -15,7 +15,12 @@ ->autoconfigure(); $services->load('a9f\\Fractor\\', __DIR__ . '/../src/') - ->exclude('../src/Configuration/'); + ->exclude([ + __DIR__ . '/../src/Configuration', + __DIR__ . '/../src/ValueObject', + ] + ); + $services->set(FractorRunner::class)->arg('$processors', tagged_iterator('fractor.file_processor')); $services->set(FractorConfig::class) diff --git a/fractor/src/Contract/FileProcessor.php b/fractor/src/Contract/FileProcessor.php index b9982479..ee61ecbf 100644 --- a/fractor/src/Contract/FileProcessor.php +++ b/fractor/src/Contract/FileProcessor.php @@ -2,9 +2,11 @@ namespace a9f\Fractor\Contract; +use a9f\Fractor\ValueObject\File; + interface FileProcessor { public function canHandle(\SplFileInfo $file): bool; - public function handle(\SplFileInfo $file): void; + public function handle(File $file): void; } diff --git a/fractor/src/FileSystem/FileCollector.php b/fractor/src/FileSystem/FileCollector.php new file mode 100644 index 00000000..9fc0eaab --- /dev/null +++ b/fractor/src/FileSystem/FileCollector.php @@ -0,0 +1,28 @@ + + */ + private array $files = []; + public function addFile(File $file): void + { + $this->files[$file->getFilePath()] = $file; + } + + public function getFileByPath(string $filePath): ?File + { + return $this->files[$filePath] ?? null; + } + + public function getFiles(): array + { + return $this->files; + } +} \ No newline at end of file diff --git a/fractor/src/Fractor/FractorRunner.php b/fractor/src/Fractor/FractorRunner.php index 32299dfe..b64611fd 100644 --- a/fractor/src/Fractor/FractorRunner.php +++ b/fractor/src/Fractor/FractorRunner.php @@ -4,18 +4,21 @@ use a9f\Fractor\Configuration\FractorConfig; use a9f\Fractor\Contract\FileProcessor; +use a9f\Fractor\FileSystem\FileCollector; use a9f\Fractor\FileSystem\FileFinder; +use a9f\Fractor\ValueObject\File; +use Nette\Utils\FileSystem; /** * Main Fractor class. This takes care of collecting a list of files, iterating over them and calling all registered * processors for them. */ -final class FractorRunner +final readonly class FractorRunner { /** * @param list $processors */ - public function __construct(private readonly FileFinder $fileFinder, private readonly iterable $processors) + public function __construct(private FileFinder $fileFinder, private readonly FileCollector $fileCollector, private iterable $processors) { } @@ -24,6 +27,7 @@ public function run(FractorConfig $config): void if ($config->getPaths() === []) { throw new \RuntimeException('No directories given'); } + $files = $this->fileFinder->findFiles($config->getPaths(), $config->getFileExtensions()); foreach ($files as $file) { @@ -32,7 +36,10 @@ public function run(FractorConfig $config): void continue; } - $processor->handle($file); + $fractorFile = new File($file->getRealPath(), FileSystem::read($file->getRealPath())); + $this->fileCollector->addFile($fractorFile); + + $processor->handle($fractorFile); } } } diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index c0ff1af2..f064064e 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -6,6 +6,7 @@ use a9f\Fractor\Configuration\FractorConfig; use a9f\Fractor\DependencyInjection\ContainerBuilder; use a9f\Fractor\Exception\ShouldNotHappenException; +use a9f\Fractor\FileSystem\FileCollector; use a9f\Fractor\Fractor\FractorRunner; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -14,6 +15,7 @@ abstract class AbstractFractorTestCase extends TestCase { private ?ContainerInterface $currentContainer = null; private FractorRunner $fractorRunner; + protected FileCollector $fileCollector; abstract protected function provideConfigFilePath(): ?string; @@ -25,6 +27,7 @@ protected function additionalConfigurationFiles(): array protected function setUp(): void { $this->bootFromConfigFile(); + $this->fileCollector = $this->getService(FileCollector::class); $this->fractorRunner = $this->getService(FractorRunner::class); } diff --git a/fractor/src/ValueObject/File.php b/fractor/src/ValueObject/File.php new file mode 100644 index 00000000..be87e2a9 --- /dev/null +++ b/fractor/src/ValueObject/File.php @@ -0,0 +1,45 @@ +originalContent = $this->content; + } + + public function getFilePath(): string + { + return $this->filePath; + } + + public function getContent(): string + { + return $this->content; + } + + public function changeFileContent(string $newFileContent): void + { + if ($this->content === $newFileContent) { + return; + } + + $this->content = $newFileContent; + $this->hasChanged = true; + } + + public function hasChanged(): bool + { + return $this->hasChanged; + } + + public function getOriginalContent(): string + { + return $this->originalContent; + } +} \ No newline at end of file diff --git a/fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt b/fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt index fc6a78a0..7d6c0e0b 100644 --- a/fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt +++ b/fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt @@ -1 +1 @@ -The text YYY will be replaced by YYY \ No newline at end of file +The text XXX will be replaced by YYY \ No newline at end of file diff --git a/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php index a7ac2093..f9725528 100644 --- a/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php +++ b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php @@ -16,7 +16,8 @@ protected function provideConfigFilePath(): ?string public function test(): void { $this->doTest(); - self::assertFileEquals(__DIR__ . '/Assertions/my_text_file.txt', __DIR__ . '/Fixture/my_text_file.txt'); + $file = $this->fileCollector->getFileByPath(__DIR__ . '/Fixture/my_text_file.txt'); + self::assertStringEqualsFile(__DIR__ . '/Assertions/my_text_file.txt', $file->getContent()); } protected function additionalConfigurationFiles(): array diff --git a/fractor/tests/Helper/Contract/TextRule.php b/fractor/tests/Helper/Contract/TextRule.php index 6088bd86..200553c9 100644 --- a/fractor/tests/Helper/Contract/TextRule.php +++ b/fractor/tests/Helper/Contract/TextRule.php @@ -4,8 +4,9 @@ namespace a9f\Fractor\Tests\Helper\Contract; use a9f\Fractor\Contract\FractorRule; +use a9f\Fractor\ValueObject\File; interface TextRule { - public function apply(string $fileContent): string; + public function apply(File $file): void; } \ No newline at end of file diff --git a/fractor/tests/Helper/FileProcessor/TextFileProcessor.php b/fractor/tests/Helper/FileProcessor/TextFileProcessor.php index 22490b44..c7e212e7 100644 --- a/fractor/tests/Helper/FileProcessor/TextFileProcessor.php +++ b/fractor/tests/Helper/FileProcessor/TextFileProcessor.php @@ -5,6 +5,7 @@ use a9f\Fractor\Contract\FileProcessor; use a9f\Fractor\Tests\Helper\Contract\TextRule; +use a9f\Fractor\ValueObject\File; final readonly class TextFileProcessor implements FileProcessor { @@ -20,12 +21,10 @@ public function canHandle(\SplFileInfo $file): bool return $file->getExtension() === 'txt'; } - public function handle(\SplFileInfo $file): void + public function handle(File $file): void { foreach ($this->rules as $rule) { - $fileContent = file_get_contents($file->getPathname()); - $changedFileContent = $rule->apply($fileContent); - file_put_contents($file->getPathname(), $changedFileContent); + $rule->apply($file); } } } \ No newline at end of file diff --git a/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php b/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php index 240dec4a..220f40a6 100644 --- a/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php +++ b/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php @@ -4,12 +4,15 @@ namespace a9f\Fractor\Tests\Helper\Rules; use a9f\Fractor\Tests\Helper\Contract\TextRule; +use a9f\Fractor\ValueObject\File; final class ReplaceXXXTextRule implements TextRule { - public function apply(string $fileContent): string + public function apply(File $file): void { - return str_replace('XXX', 'YYY', $fileContent); + $newFileContent = str_replace('XXX', 'YYY', $file->getContent()); + + $file->changeFileContent($newFileContent); } } \ No newline at end of file From e3e2f423ea02aeea2a44090ad3cb41add98c4af4 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 22:32:29 +0200 Subject: [PATCH 11/31] [TASK] Fix tests for TextFileProcessor --- fractor-xml/src/XmlFileProcessor.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fractor-xml/src/XmlFileProcessor.php b/fractor-xml/src/XmlFileProcessor.php index fe60f41b..8e8abf35 100644 --- a/fractor-xml/src/XmlFileProcessor.php +++ b/fractor-xml/src/XmlFileProcessor.php @@ -3,6 +3,7 @@ namespace a9f\FractorXml; use a9f\Fractor\Contract\FileProcessor; +use a9f\Fractor\ValueObject\File; use a9f\FractorXml\Contract\XmlFractor; final class XmlFileProcessor implements FileProcessor @@ -19,18 +20,18 @@ public function canHandle(\SplFileInfo $file): bool return $file->getExtension() === 'xml'; } - public function handle(\SplFileInfo $file): void + public function handle(File $file): void { $doc = new \DOMDocument(); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; - $doc->load($file->getPathname()); + $doc->load($file->getFilePath()); // TODO we need a way to detect if there were changes (and probably also collect changes here) $iterator = new DomDocumentIterator($this->rules); $iterator->traverseDocument($doc); // TODO only update file if changed - file_put_contents($file->getPathname(), $doc->saveXML()); + file_put_contents($file->getFilePath(), $doc->saveXML()); } } From 968a98cc24086f116aa261524804c36e03f47602 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 22:34:53 +0200 Subject: [PATCH 12/31] [TASK] Add phpunit.xml for typo3-fractor --- typo3-fractor/.gitignore | 3 ++- typo3-fractor/phpunit.xml | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 typo3-fractor/phpunit.xml diff --git a/typo3-fractor/.gitignore b/typo3-fractor/.gitignore index 94d6d75a..a89e45ef 100644 --- a/typo3-fractor/.gitignore +++ b/typo3-fractor/.gitignore @@ -1,2 +1,3 @@ /vendor/ -/composer.lock \ No newline at end of file +/composer.lock +.phpunit.cache \ No newline at end of file diff --git a/typo3-fractor/phpunit.xml b/typo3-fractor/phpunit.xml new file mode 100644 index 00000000..e5fedb47 --- /dev/null +++ b/typo3-fractor/phpunit.xml @@ -0,0 +1,13 @@ + + + + + tests + + + + + ./src + + + From a2bbebd1d9c98557c270cbf433a506ecb80c506e Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 22:57:11 +0200 Subject: [PATCH 13/31] [TASK] Add tests for typo3-fractor --- .gitignore | 1 - tests/.gitignore | 4 -- tests/composer.json | 25 -------- tests/run-test.sh | 24 -------- .../expected-output/FlexFormWithSelect.xml | 18 ------ .../fixtures/FlexFormWithSelect.xml | 18 ------ tests/typo3-flexform/fractor.php | 17 ------ typo3-fractor/composer.json | 3 +- typo3-fractor/config/application.php | 1 - .../AddRenderTypeToFlexFormFractorTest.php | 57 +++++++------------ .../Assertions/SelectWithoutRenderType.xml | 18 ++++++ .../SelectWithoutRenderType.xml} | 5 +- .../SelectWithoutRenderTypeNotInFlexForm.xml | 18 ++++++ .../Fixtures/SelectWithoutRenderType.xml.inc | 37 ------------ .../tests/Rules/FlexForm/config/fractor.php | 8 +++ 15 files changed, 69 insertions(+), 185 deletions(-) delete mode 100644 .gitignore delete mode 100644 tests/.gitignore delete mode 100644 tests/composer.json delete mode 100755 tests/run-test.sh delete mode 100644 tests/typo3-flexform/expected-output/FlexFormWithSelect.xml delete mode 100644 tests/typo3-flexform/fixtures/FlexFormWithSelect.xml delete mode 100644 tests/typo3-flexform/fractor.php create mode 100644 typo3-fractor/tests/Rules/FlexForm/Assertions/SelectWithoutRenderType.xml rename typo3-fractor/tests/Rules/FlexForm/{Fixtures/SelectWithoutRenderTypeNotInFlexForm.xml.inc => Fixture/SelectWithoutRenderType.xml} (88%) create mode 100644 typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml delete mode 100644 typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderType.xml.inc create mode 100644 typo3-fractor/tests/Rules/FlexForm/config/fractor.php diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 143c4262..00000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.phpunit.result.cache \ No newline at end of file diff --git a/tests/.gitignore b/tests/.gitignore deleted file mode 100644 index 8d152d48..00000000 --- a/tests/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/composer.lock -/vendor/ - -/*/output/ \ No newline at end of file diff --git a/tests/composer.json b/tests/composer.json deleted file mode 100644 index bf6b7cf7..00000000 --- a/tests/composer.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "a9f/fractor-tests-typo3-flexform", - "type": "project", - "require": { - "a9f/fractor": "@dev", - "a9f/fractor-extension-installer": "@dev", - "a9f/fractor-xml": "@dev", - "a9f/typo3-fractor": "@dev" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.42" - }, - "repositories": { - "fractor": { - "type": "path", - "url": "../*" - } - }, - "config": { - "allow-plugins": { - "a9f/fractor-extension-installer": true, - "ergebnis/composer-normalize": true - } - } -} diff --git a/tests/run-test.sh b/tests/run-test.sh deleted file mode 100755 index 6fbdf159..00000000 --- a/tests/run-test.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -set -x - -TESTS_BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd)" -BASE_DIR="$TESTS_BASE_DIR/../" - -cd $TESTS_BASE_DIR - -rm -r composer.lock vendor || true -composer install - -TEST_DIR=typo3-flexform - -cd $TEST_DIR - -[[ -d ./output/ ]] && rm -rf ./output/ -cp -r fixtures/ output/ - -cd $TESTS_BASE_DIR -./vendor/bin/fractor process -c $TESTS_BASE_DIR/$TEST_DIR/fractor.php - -# TODO remove -b once we keep the output format when re-writing the file -diff -rub $TEST_DIR/expected-output/ $TEST_DIR/output/ diff --git a/tests/typo3-flexform/expected-output/FlexFormWithSelect.xml b/tests/typo3-flexform/expected-output/FlexFormWithSelect.xml deleted file mode 100644 index d441be59..00000000 --- a/tests/typo3-flexform/expected-output/FlexFormWithSelect.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - array - - - - select - selectSingle - - - - - - - diff --git a/tests/typo3-flexform/fixtures/FlexFormWithSelect.xml b/tests/typo3-flexform/fixtures/FlexFormWithSelect.xml deleted file mode 100644 index fb071d8d..00000000 --- a/tests/typo3-flexform/fixtures/FlexFormWithSelect.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - array - - - - select - 1 - - - - - - - \ No newline at end of file diff --git a/tests/typo3-flexform/fractor.php b/tests/typo3-flexform/fractor.php deleted file mode 100644 index 45c8d3d9..00000000 --- a/tests/typo3-flexform/fractor.php +++ /dev/null @@ -1,17 +0,0 @@ -import(__DIR__ . '/../vendor/a9f/fractor-xml/config/fractor.php'); - - $config->setPaths([ - __DIR__ . '/output/', - ]); - - $config->withFileProcessor(XmlFileProcessor::class); - - $config->withRule(AddRenderTypeToFlexFormFractor::class); -}; diff --git a/typo3-fractor/composer.json b/typo3-fractor/composer.json index 71cfb3da..4119ac4a 100644 --- a/typo3-fractor/composer.json +++ b/typo3-fractor/composer.json @@ -14,8 +14,7 @@ "php": "^8.2", "a9f/fractor": "@dev", "a9f/fractor-extension-installer": "@dev", - "a9f/fractor-xml": "@dev", - "thecodingmachine/safe": "^2.5" + "a9f/fractor-xml": "@dev" }, "require-dev": { "ergebnis/composer-normalize": "^2.42", diff --git a/typo3-fractor/config/application.php b/typo3-fractor/config/application.php index 3b7e6dbb..f968cd22 100644 --- a/typo3-fractor/config/application.php +++ b/typo3-fractor/config/application.php @@ -7,6 +7,5 @@ $services->defaults() ->autowire() ->autoconfigure(); - $services->load('a9f\\Typo3Fractor\\', __DIR__ . '/../src/'); }; diff --git a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php index 2a50c2a1..89d527e6 100644 --- a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php +++ b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php @@ -2,49 +2,34 @@ namespace a9f\Typo3Fractor\Tests\Rules\FlexForm; -use a9f\FractorXml\DomDocumentIterator; -use a9f\Typo3Fractor\Rules\FlexForm\AddRenderTypeToFlexFormFractor; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\TestCase; +use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase; -use function Safe\file_get_contents; - -class AddRenderTypeToFlexFormFractorTest extends TestCase +class AddRenderTypeToFlexFormFractorTest extends AbstractFractorTestCase { - private const FIXTURE_SEPARATOR = '-----'; - - /** - * @return array - */ - public static function fixtureFilesProvider(): array + public function test(): void { - return [ - 'select without renderType' => [__DIR__ . '/Fixtures/SelectWithoutRenderType.xml.inc'], - 'select without renderType outside T3DataStructure' => [__DIR__ . '/Fixtures/SelectWithoutRenderTypeNotInFlexForm.xml.inc'], - ]; - } + // Act + $this->doTest(); - #[DataProvider('fixtureFilesProvider')] - public function test(string $filePath): void - { - $fixture = file_get_contents($filePath); - if (str_contains($fixture, self::FIXTURE_SEPARATOR)) { - [$originalXml, $expectedResultXml] = array_map( - 'trim', - explode(self::FIXTURE_SEPARATOR, $fixture) - ); - } else { - $originalXml = $expectedResultXml = $fixture; - } + // Arrange + $file = $this->fileCollector->getFileByPath(__DIR__ . '/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml'); + self::assertStringEqualsFile(__DIR__ . '/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml', $file->getContent()); - $document = new \DOMDocument(); - $document->loadXML($originalXml); + $file = $this->fileCollector->getFileByPath(__DIR__ . '/Fixture/SelectWithoutRenderType.xml'); + self::assertStringEqualsFile(__DIR__ . '/Assertions/SelectWithoutRenderType.xml', $file->getContent()); - $iterator = new DomDocumentIterator([new AddRenderTypeToFlexFormFractor()]); - $iterator->traverseDocument($document); + } - $result = $document->saveXML() ?: ''; + protected function provideConfigFilePath(): ?string + { + return __DIR__ . '/config/fractor.php'; + } - self::assertXmlStringEqualsXmlString($expectedResultXml, $result); + protected function additionalConfigurationFiles(): array + { + return [ + __DIR__ .'/../../../../fractor-xml/config/application.php', + __DIR__ .'/../../../config/application.php', + ]; } } diff --git a/typo3-fractor/tests/Rules/FlexForm/Assertions/SelectWithoutRenderType.xml b/typo3-fractor/tests/Rules/FlexForm/Assertions/SelectWithoutRenderType.xml new file mode 100644 index 00000000..59dc2dd4 --- /dev/null +++ b/typo3-fractor/tests/Rules/FlexForm/Assertions/SelectWithoutRenderType.xml @@ -0,0 +1,18 @@ + + + + + + array + + + + select + selectSingle + + + + + + + diff --git a/typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderTypeNotInFlexForm.xml.inc b/typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderType.xml similarity index 88% rename from typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderTypeNotInFlexForm.xml.inc rename to typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderType.xml index 314ca580..eb95f6c8 100644 --- a/typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderTypeNotInFlexForm.xml.inc +++ b/typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderType.xml @@ -1,5 +1,5 @@ - + @@ -15,4 +15,5 @@ - + + diff --git a/typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml b/typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml new file mode 100644 index 00000000..f6f20e77 --- /dev/null +++ b/typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml @@ -0,0 +1,18 @@ + + + + + + array + + + + select + 1 + + + + + + + diff --git a/typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderType.xml.inc b/typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderType.xml.inc deleted file mode 100644 index 9e9e3626..00000000 --- a/typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderType.xml.inc +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - array - - - - select - 1 - - - - - - - ------ - - - - - - array - - - - select - selectSingle - - - - - - - diff --git a/typo3-fractor/tests/Rules/FlexForm/config/fractor.php b/typo3-fractor/tests/Rules/FlexForm/config/fractor.php new file mode 100644 index 00000000..59b14533 --- /dev/null +++ b/typo3-fractor/tests/Rules/FlexForm/config/fractor.php @@ -0,0 +1,8 @@ +setPaths([__DIR__ .'/../Fixture/']); + $config->setFileExtensions(['xml']); +}; From 5f6cc0eb221d206ffc807f0d9f79a0d4799ae253 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 22:57:17 +0200 Subject: [PATCH 14/31] [TASK] Add tests for typo3-fractor --- fractor-xml/src/AbstractXmlFractor.php | 1 - fractor-xml/src/DomDocumentIterator.php | 2 +- fractor-xml/src/XmlFileProcessor.php | 2 +- fractor/src/Configuration/FractorConfig.php | 19 ------------------- fractor/tests/Helper/Contract/TextRule.php | 1 - 5 files changed, 2 insertions(+), 23 deletions(-) diff --git a/fractor-xml/src/AbstractXmlFractor.php b/fractor-xml/src/AbstractXmlFractor.php index ab0eb35c..741e1a7b 100644 --- a/fractor-xml/src/AbstractXmlFractor.php +++ b/fractor-xml/src/AbstractXmlFractor.php @@ -2,7 +2,6 @@ namespace a9f\FractorXml; -use a9f\Fractor\Contract\FractorRule; use a9f\FractorXml\Contract\DomNodeVisitor; use a9f\FractorXml\Contract\XmlFractor; diff --git a/fractor-xml/src/DomDocumentIterator.php b/fractor-xml/src/DomDocumentIterator.php index 79500a5b..1654f2a5 100644 --- a/fractor-xml/src/DomDocumentIterator.php +++ b/fractor-xml/src/DomDocumentIterator.php @@ -12,7 +12,7 @@ final class DomDocumentIterator /** * @param list $visitors */ - public function __construct(private readonly array $visitors) + public function __construct(private readonly iterable $visitors) { } diff --git a/fractor-xml/src/XmlFileProcessor.php b/fractor-xml/src/XmlFileProcessor.php index 8e8abf35..30f97abe 100644 --- a/fractor-xml/src/XmlFileProcessor.php +++ b/fractor-xml/src/XmlFileProcessor.php @@ -32,6 +32,6 @@ public function handle(File $file): void $iterator->traverseDocument($doc); // TODO only update file if changed - file_put_contents($file->getFilePath(), $doc->saveXML()); + $file->changeFileContent($doc->saveXML()); } } diff --git a/fractor/src/Configuration/FractorConfig.php b/fractor/src/Configuration/FractorConfig.php index cbc4c56b..75f3304a 100644 --- a/fractor/src/Configuration/FractorConfig.php +++ b/fractor/src/Configuration/FractorConfig.php @@ -3,7 +3,6 @@ namespace a9f\Fractor\Configuration; use a9f\Fractor\Contract\FileProcessor; -use a9f\Fractor\Contract\FractorRule; use Symfony\Component\DependencyInjection\ContainerBuilder; final class FractorConfig extends ContainerBuilder @@ -76,24 +75,6 @@ public function getFileExtensions(): array return $this->fileExtensions; } - /** - * @param class-string $ruleClass - */ - public function withRule(string $ruleClass): self - { - $this->rules[] = $ruleClass; - - return $this; - } - - /** - * @return list> - */ - public function getRules(): array - { - return $this->rules; - } - public function import(string $configFile): void { if (!file_exists($configFile)) { diff --git a/fractor/tests/Helper/Contract/TextRule.php b/fractor/tests/Helper/Contract/TextRule.php index 200553c9..25ca88f5 100644 --- a/fractor/tests/Helper/Contract/TextRule.php +++ b/fractor/tests/Helper/Contract/TextRule.php @@ -3,7 +3,6 @@ namespace a9f\Fractor\Tests\Helper\Contract; -use a9f\Fractor\Contract\FractorRule; use a9f\Fractor\ValueObject\File; interface TextRule From 90eeb649a0a1265ad9e4a5e91088fbe73365f284 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 22:59:35 +0200 Subject: [PATCH 15/31] [TASK] Fix tests in CI --- .../workflows/lint_test_pull_requests.yaml | 19 +------------------ fractor-xml/composer.json | 2 +- fractor/composer.json | 2 +- typo3-fractor/composer.json | 2 +- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/.github/workflows/lint_test_pull_requests.yaml b/.github/workflows/lint_test_pull_requests.yaml index 2ecc3483..3c57c31a 100644 --- a/.github/workflows/lint_test_pull_requests.yaml +++ b/.github/workflows/lint_test_pull_requests.yaml @@ -45,21 +45,4 @@ jobs: with: container_workdir: /app/${{ matrix.directory }} command: ${{ matrix.composer-command.command }} - memory_limit: 512M - - tests: - runs-on: ubuntu-latest - name: End to end tests - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.2' - - - name: Run tests - working-directory: tests - run: ./run-test.sh \ No newline at end of file + memory_limit: 512M \ No newline at end of file diff --git a/fractor-xml/composer.json b/fractor-xml/composer.json index a53b3d4c..ec5dc5ec 100644 --- a/fractor-xml/composer.json +++ b/fractor-xml/composer.json @@ -50,6 +50,6 @@ "analyze:php": "phpstan analyze", "style:php:check": "ecs", "style:php:fix": "ecs --fix", - "test:php": "phpunit tests/" + "test:php": "phpunit" } } diff --git a/fractor/composer.json b/fractor/composer.json index 98b1e96c..cdb9739c 100644 --- a/fractor/composer.json +++ b/fractor/composer.json @@ -48,6 +48,6 @@ "analyze:php": "phpstan analyze", "style:php:check": "ecs", "style:php:fix": "ecs --fix", - "test:php": "phpunit tests/" + "test:php": "phpunit" } } diff --git a/typo3-fractor/composer.json b/typo3-fractor/composer.json index 4119ac4a..8c858854 100644 --- a/typo3-fractor/composer.json +++ b/typo3-fractor/composer.json @@ -49,6 +49,6 @@ "analyze:php": "phpstan analyze", "style:php:check": "ecs", "style:php:fix": "ecs --fix", - "test:php": "phpunit tests/" + "test:php": "phpunit" } } From a043ff47ba59a4d513f1b825c682f653a7000084 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 16 Apr 2024 23:06:44 +0200 Subject: [PATCH 16/31] [TASK] Fix CI --- fractor-xml/src/XmlFileProcessor.php | 9 +++++++-- fractor/composer.json | 1 + fractor/config/application.php | 3 ++- fractor/src/Configuration/FractorConfig.php | 5 ----- fractor/src/DependencyInjection/ContainerBuilder.php | 3 +++ fractor/src/Exception/ShouldNotHappenException.php | 4 ++-- fractor/src/FileSystem/FileCollector.php | 6 +++++- fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php | 6 +++++- fractor/src/ValueObject/File.php | 3 ++- fractor/tests/FileSystem/FileFinderTest.php | 1 - .../tests/Fractor/FractorRunner/FractorRunnerTest.php | 5 +++-- fractor/tests/Fractor/FractorRunner/config/fractor.php | 2 +- fractor/tests/Helper/Contract/TextRule.php | 3 ++- fractor/tests/Helper/FileProcessor/TextFileProcessor.php | 3 ++- fractor/tests/Helper/Rules/ReplaceXXXTextRule.php | 4 ++-- typo3-fractor/composer.json | 1 + .../FlexForm/AddRenderTypeToFlexFormFractorTest.php | 7 ++++--- typo3-fractor/tests/Rules/FlexForm/config/fractor.php | 2 +- 18 files changed, 43 insertions(+), 25 deletions(-) diff --git a/fractor-xml/src/XmlFileProcessor.php b/fractor-xml/src/XmlFileProcessor.php index 30f97abe..2db0fb03 100644 --- a/fractor-xml/src/XmlFileProcessor.php +++ b/fractor-xml/src/XmlFileProcessor.php @@ -31,7 +31,12 @@ public function handle(File $file): void $iterator = new DomDocumentIterator($this->rules); $iterator->traverseDocument($doc); - // TODO only update file if changed - $file->changeFileContent($doc->saveXML()); + $newFileContent = $doc->saveXML(); + + if ($newFileContent === false) { + throw new \UnexpectedValueException('New file content should be a string'); + } + + $file->changeFileContent($newFileContent); } } diff --git a/fractor/composer.json b/fractor/composer.json index cdb9739c..f1b7727c 100644 --- a/fractor/composer.json +++ b/fractor/composer.json @@ -22,6 +22,7 @@ "require-dev": { "ergebnis/composer-normalize": "^2.42", "phpstan/phpstan": "^1.10", + "phpstan/phpstan-phpunit": "^1.3", "phpunit/phpunit": "^10.5", "symplify/easy-coding-standard": "^12.1" }, diff --git a/fractor/config/application.php b/fractor/config/application.php index 6f72b7f0..6e7970be 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -15,7 +15,8 @@ ->autoconfigure(); $services->load('a9f\\Fractor\\', __DIR__ . '/../src/') - ->exclude([ + ->exclude( + [ __DIR__ . '/../src/Configuration', __DIR__ . '/../src/ValueObject', ] diff --git a/fractor/src/Configuration/FractorConfig.php b/fractor/src/Configuration/FractorConfig.php index 75f3304a..92050f25 100644 --- a/fractor/src/Configuration/FractorConfig.php +++ b/fractor/src/Configuration/FractorConfig.php @@ -15,11 +15,6 @@ final class FractorConfig extends ContainerBuilder */ private array $processors = []; - /** - * @var list> - */ - private array $rules = []; - /** @var list */ private array $fileExtensions = []; diff --git a/fractor/src/DependencyInjection/ContainerBuilder.php b/fractor/src/DependencyInjection/ContainerBuilder.php index 70afdec1..5324a19a 100644 --- a/fractor/src/DependencyInjection/ContainerBuilder.php +++ b/fractor/src/DependencyInjection/ContainerBuilder.php @@ -12,6 +12,9 @@ class ContainerBuilder { + /** + * @param array $additionalConfigFiles + */ public function createDependencyInjectionContainer(?string $fractorConfigFile, array $additionalConfigFiles = []): ContainerInterface { $config = new FractorConfig(); diff --git a/fractor/src/Exception/ShouldNotHappenException.php b/fractor/src/Exception/ShouldNotHappenException.php index aab45850..4445b93a 100644 --- a/fractor/src/Exception/ShouldNotHappenException.php +++ b/fractor/src/Exception/ShouldNotHappenException.php @@ -1,9 +1,9 @@ files[$filePath] ?? null; } + /** + * @return array + */ public function getFiles(): array { return $this->files; } -} \ No newline at end of file +} diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index f064064e..72f632b5 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -1,4 +1,5 @@ + */ protected function additionalConfigurationFiles(): array { return []; @@ -62,4 +66,4 @@ protected function getService(string $type): object return $object; } -} \ No newline at end of file +} diff --git a/fractor/src/ValueObject/File.php b/fractor/src/ValueObject/File.php index be87e2a9..02fab1b8 100644 --- a/fractor/src/ValueObject/File.php +++ b/fractor/src/ValueObject/File.php @@ -1,4 +1,5 @@ originalContent; } -} \ No newline at end of file +} diff --git a/fractor/tests/FileSystem/FileFinderTest.php b/fractor/tests/FileSystem/FileFinderTest.php index 41d383bb..7cb2d862 100644 --- a/fractor/tests/FileSystem/FileFinderTest.php +++ b/fractor/tests/FileSystem/FileFinderTest.php @@ -7,7 +7,6 @@ use a9f\Fractor\FileSystem\FileFinder; use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\TestCase; use UnexpectedValueException; final class FileFinderTest extends AbstractFractorTestCase diff --git a/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php index f9725528..d6fafefe 100644 --- a/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php +++ b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php @@ -1,4 +1,5 @@ doTest(); $file = $this->fileCollector->getFileByPath(__DIR__ . '/Fixture/my_text_file.txt'); + self::assertNotNull($file); self::assertStringEqualsFile(__DIR__ . '/Assertions/my_text_file.txt', $file->getContent()); } @@ -26,4 +27,4 @@ protected function additionalConfigurationFiles(): array __DIR__ . '/config/application.php' ]; } -} \ No newline at end of file +} diff --git a/fractor/tests/Fractor/FractorRunner/config/fractor.php b/fractor/tests/Fractor/FractorRunner/config/fractor.php index baf724c3..7b9847b1 100644 --- a/fractor/tests/Fractor/FractorRunner/config/fractor.php +++ b/fractor/tests/Fractor/FractorRunner/config/fractor.php @@ -3,6 +3,6 @@ use a9f\Fractor\Configuration\FractorConfig; return static function (FractorConfig $config) { - $config->setPaths([__DIR__ .'/../Fixture/']); + $config->setPaths([__DIR__ . '/../Fixture/']); $config->setFileExtensions(['txt']); }; diff --git a/fractor/tests/Helper/Contract/TextRule.php b/fractor/tests/Helper/Contract/TextRule.php index 25ca88f5..1daf6a8f 100644 --- a/fractor/tests/Helper/Contract/TextRule.php +++ b/fractor/tests/Helper/Contract/TextRule.php @@ -1,4 +1,5 @@ apply($file); } } -} \ No newline at end of file +} diff --git a/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php b/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php index 220f40a6..17530254 100644 --- a/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php +++ b/fractor/tests/Helper/Rules/ReplaceXXXTextRule.php @@ -1,4 +1,5 @@ getContent()); $file->changeFileContent($newFileContent); } -} \ No newline at end of file +} diff --git a/typo3-fractor/composer.json b/typo3-fractor/composer.json index 8c858854..28373287 100644 --- a/typo3-fractor/composer.json +++ b/typo3-fractor/composer.json @@ -19,6 +19,7 @@ "require-dev": { "ergebnis/composer-normalize": "^2.42", "phpstan/phpstan": "^1.10", + "phpstan/phpstan-phpunit": "^1.3", "phpunit/phpunit": "^10.5", "symplify/easy-coding-standard": "^12.1" }, diff --git a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php index 89d527e6..81ceab0a 100644 --- a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php +++ b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php @@ -13,11 +13,12 @@ public function test(): void // Arrange $file = $this->fileCollector->getFileByPath(__DIR__ . '/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml'); + self::assertNotNull($file); self::assertStringEqualsFile(__DIR__ . '/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml', $file->getContent()); $file = $this->fileCollector->getFileByPath(__DIR__ . '/Fixture/SelectWithoutRenderType.xml'); + self::assertNotNull($file); self::assertStringEqualsFile(__DIR__ . '/Assertions/SelectWithoutRenderType.xml', $file->getContent()); - } protected function provideConfigFilePath(): ?string @@ -28,8 +29,8 @@ protected function provideConfigFilePath(): ?string protected function additionalConfigurationFiles(): array { return [ - __DIR__ .'/../../../../fractor-xml/config/application.php', - __DIR__ .'/../../../config/application.php', + __DIR__ . '/../../../../fractor-xml/config/application.php', + __DIR__ . '/../../../config/application.php', ]; } } diff --git a/typo3-fractor/tests/Rules/FlexForm/config/fractor.php b/typo3-fractor/tests/Rules/FlexForm/config/fractor.php index 59b14533..5b5ec6ad 100644 --- a/typo3-fractor/tests/Rules/FlexForm/config/fractor.php +++ b/typo3-fractor/tests/Rules/FlexForm/config/fractor.php @@ -3,6 +3,6 @@ use a9f\Fractor\Configuration\FractorConfig; return static function (FractorConfig $config) { - $config->setPaths([__DIR__ .'/../Fixture/']); + $config->setPaths([__DIR__ . '/../Fixture/']); $config->setFileExtensions(['xml']); }; From 1d05bf0b97a48efe9aa53c8a472042a13262f47f Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 09:09:55 +0200 Subject: [PATCH 17/31] TASK: Remove unused method of FractorConfig --- fractor/src/Configuration/FractorConfig.php | 23 --------------------- 1 file changed, 23 deletions(-) diff --git a/fractor/src/Configuration/FractorConfig.php b/fractor/src/Configuration/FractorConfig.php index 92050f25..e3d57aa1 100644 --- a/fractor/src/Configuration/FractorConfig.php +++ b/fractor/src/Configuration/FractorConfig.php @@ -2,7 +2,6 @@ namespace a9f\Fractor\Configuration; -use a9f\Fractor\Contract\FileProcessor; use Symfony\Component\DependencyInjection\ContainerBuilder; final class FractorConfig extends ContainerBuilder @@ -10,11 +9,6 @@ final class FractorConfig extends ContainerBuilder /** @var list */ private array $paths = []; - /** - * @var list> - */ - private array $processors = []; - /** @var list */ private array $fileExtensions = []; @@ -35,23 +29,6 @@ public function getPaths(): array return $this->paths; } - /** - * @param class-string $processor - */ - public function withFileProcessor(string $processor): self - { - $this->processors[] = $processor; - return $this; - } - - /** - * @return list> - */ - public function getFileProcessors(): array - { - return $this->processors; - } - /** * @param list $extensions */ From a79ee01f5714d604a54cd6bcc52b05cd4ec4732c Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 09:49:08 +0200 Subject: [PATCH 18/31] TASK: Use configuration value object --- .phpunit.result.cache | 1 + fractor/src/Command/ProcessCommand.php | 5 +-- fractor/src/Configuration/Option.php | 11 +++++++ fractor/src/Factory/ConfigurationFactory.php | 15 +++++++++ fractor/src/Fractor/FractorRunner.php | 9 +++--- .../PHPUnit/AbstractFractorTestCase.php | 3 +- fractor/src/ValueObject/Configuration.php | 31 +++++++++++++++++++ 7 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 .phpunit.result.cache create mode 100644 fractor/src/Configuration/Option.php create mode 100644 fractor/src/Factory/ConfigurationFactory.php create mode 100644 fractor/src/ValueObject/Configuration.php diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 00000000..a3f15020 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"Fractor\\FractorRunner\\FractorRunnerTest::test":8},"times":{"Fractor\\FractorRunner\\FractorRunnerTest::test":0.011}} \ No newline at end of file diff --git a/fractor/src/Command/ProcessCommand.php b/fractor/src/Command/ProcessCommand.php index 3abb338d..29cda4c2 100644 --- a/fractor/src/Command/ProcessCommand.php +++ b/fractor/src/Command/ProcessCommand.php @@ -3,6 +3,7 @@ namespace a9f\Fractor\Command; use a9f\Fractor\Configuration\FractorConfig; +use a9f\Fractor\Factory\ConfigurationFactory; use a9f\Fractor\Fractor\FractorRunner; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -13,7 +14,7 @@ #[AsCommand('process', 'Runs Fractor with the given configuration file')] class ProcessCommand extends Command { - public function __construct(private readonly FractorConfig $config, private readonly FractorRunner $runner) + public function __construct(private readonly FractorConfig $config, private readonly FractorRunner $runner, private readonly ConfigurationFactory $configurationFactory) { parent::__construct(); } @@ -30,7 +31,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $this->runner->run($this->config); + $this->runner->run($this->configurationFactory->createFromFractorConfig($this->config)); return Command::SUCCESS; } diff --git a/fractor/src/Configuration/Option.php b/fractor/src/Configuration/Option.php new file mode 100644 index 00000000..9f9e5b22 --- /dev/null +++ b/fractor/src/Configuration/Option.php @@ -0,0 +1,11 @@ +getFileExtensions(), $fractorConfig->getPaths()); + } +} \ No newline at end of file diff --git a/fractor/src/Fractor/FractorRunner.php b/fractor/src/Fractor/FractorRunner.php index b64611fd..6abb9cb9 100644 --- a/fractor/src/Fractor/FractorRunner.php +++ b/fractor/src/Fractor/FractorRunner.php @@ -6,6 +6,7 @@ use a9f\Fractor\Contract\FileProcessor; use a9f\Fractor\FileSystem\FileCollector; use a9f\Fractor\FileSystem\FileFinder; +use a9f\Fractor\ValueObject\Configuration; use a9f\Fractor\ValueObject\File; use Nette\Utils\FileSystem; @@ -18,17 +19,17 @@ /** * @param list $processors */ - public function __construct(private FileFinder $fileFinder, private readonly FileCollector $fileCollector, private iterable $processors) + public function __construct(private FileFinder $fileFinder, private FileCollector $fileCollector, private iterable $processors) { } - public function run(FractorConfig $config): void + public function run(Configuration $configuration): void { - if ($config->getPaths() === []) { + if ($configuration->getPaths() === []) { throw new \RuntimeException('No directories given'); } - $files = $this->fileFinder->findFiles($config->getPaths(), $config->getFileExtensions()); + $files = $this->fileFinder->findFiles($configuration->getPaths(), $configuration->getFileExtensions()); foreach ($files as $file) { foreach ($this->processors as $processor) { diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index 72f632b5..b1247caf 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -7,6 +7,7 @@ use a9f\Fractor\Configuration\FractorConfig; use a9f\Fractor\DependencyInjection\ContainerBuilder; use a9f\Fractor\Exception\ShouldNotHappenException; +use a9f\Fractor\Factory\ConfigurationFactory; use a9f\Fractor\FileSystem\FileCollector; use a9f\Fractor\Fractor\FractorRunner; use PHPUnit\Framework\TestCase; @@ -42,7 +43,7 @@ protected function bootFromConfigFile(): void protected function doTest(): void { - $this->fractorRunner->run($this->getService(FractorConfig::class)); + $this->fractorRunner->run($this->getService(ConfigurationFactory::class)->createFromFractorConfig($this->getService(FractorConfig::class))); } /** diff --git a/fractor/src/ValueObject/Configuration.php b/fractor/src/ValueObject/Configuration.php new file mode 100644 index 00000000..1bea6801 --- /dev/null +++ b/fractor/src/ValueObject/Configuration.php @@ -0,0 +1,31 @@ + $fileExtensions + * @param array $paths + */ + public function __construct(private array $fileExtensions, private array $paths) + { + } + + /** + * @return array + */ + public function getFileExtensions(): array + { + return $this->fileExtensions; + } + + /** + * @return array + */ + public function getPaths(): array + { + return $this->paths; + } +} \ No newline at end of file From 23e07fc2994bcc4b9ddfa87c9da985ec154a5880 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 10:13:25 +0200 Subject: [PATCH 19/31] TASK: Use ParameterBag --- .phpunit.result.cache | 2 +- fractor/config/application.php | 13 +++++++++++++ fractor/src/Command/ProcessCommand.php | 4 ++-- fractor/src/Factory/ConfigurationFactory.php | 15 ++++++++++++--- .../Testing/PHPUnit/AbstractFractorTestCase.php | 2 +- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index a3f15020..4a5ded99 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Fractor\\FractorRunner\\FractorRunnerTest::test":8},"times":{"Fractor\\FractorRunner\\FractorRunnerTest::test":0.011}} \ No newline at end of file +{"version":1,"defects":{"Fractor\\FractorRunner\\FractorRunnerTest::test":8},"times":{"Fractor\\FractorRunner\\FractorRunnerTest::test":0.005}} \ No newline at end of file diff --git a/fractor/config/application.php b/fractor/config/application.php index 6e7970be..dd9815c9 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -5,9 +5,16 @@ use a9f\Fractor\Fractor\FractorRunner; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag; +use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; +use function Symfony\Component\DependencyInjection\Loader\Configurator\service; use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator; return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder): void { + $parameters = $containerConfigurator->parameters(); + $parameters->set(\a9f\Fractor\Configuration\Option::PATHS, []); + $parameters->set(\a9f\Fractor\Configuration\Option::FILE_EXTENSIONS, []); $services = $containerConfigurator->services(); $services->defaults() ->autowire() @@ -22,6 +29,12 @@ ] ); + $services->set('parameter_bag', ContainerBag::class) + ->args([ + service('service_container'), + ]) + ->alias(ContainerBagInterface::class, 'parameter_bag') + ->alias(ParameterBagInterface::class, 'parameter_bag'); $services->set(FractorRunner::class)->arg('$processors', tagged_iterator('fractor.file_processor')); $services->set(FractorConfig::class) diff --git a/fractor/src/Command/ProcessCommand.php b/fractor/src/Command/ProcessCommand.php index 29cda4c2..7cf190c2 100644 --- a/fractor/src/Command/ProcessCommand.php +++ b/fractor/src/Command/ProcessCommand.php @@ -14,7 +14,7 @@ #[AsCommand('process', 'Runs Fractor with the given configuration file')] class ProcessCommand extends Command { - public function __construct(private readonly FractorConfig $config, private readonly FractorRunner $runner, private readonly ConfigurationFactory $configurationFactory) + public function __construct(private readonly FractorRunner $runner, private readonly ConfigurationFactory $configurationFactory) { parent::__construct(); } @@ -31,7 +31,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $this->runner->run($this->configurationFactory->createFromFractorConfig($this->config)); + $this->runner->run($this->configurationFactory->create()); return Command::SUCCESS; } diff --git a/fractor/src/Factory/ConfigurationFactory.php b/fractor/src/Factory/ConfigurationFactory.php index 8e8f3df8..313d5450 100644 --- a/fractor/src/Factory/ConfigurationFactory.php +++ b/fractor/src/Factory/ConfigurationFactory.php @@ -4,12 +4,21 @@ namespace a9f\Fractor\Factory; use a9f\Fractor\Configuration\FractorConfig; +use a9f\Fractor\Configuration\Option; use a9f\Fractor\ValueObject\Configuration; +use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; -final class ConfigurationFactory +final readonly class ConfigurationFactory { - public function createFromFractorConfig(FractorConfig $fractorConfig): Configuration + public function __construct(private ContainerBagInterface $parameterBag) { - return new Configuration($fractorConfig->getFileExtensions(), $fractorConfig->getPaths()); + } + + public function create(): Configuration + { + return new Configuration( + $this->parameterBag->get(Option::FILE_EXTENSIONS), + $this->parameterBag->get(Option::PATHS), + ); } } \ No newline at end of file diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index b1247caf..3a190e70 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -43,7 +43,7 @@ protected function bootFromConfigFile(): void protected function doTest(): void { - $this->fractorRunner->run($this->getService(ConfigurationFactory::class)->createFromFractorConfig($this->getService(FractorConfig::class))); + $this->fractorRunner->run($this->getService(ConfigurationFactory::class)->create()); } /** From 8a46b6d799a5a93f07166bbdd59a1f81a9420150 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 10:19:07 +0200 Subject: [PATCH 20/31] TASK: Refactor away from FractoConfig --- .gitignore | 1 + .phpunit.result.cache | 1 - README.md | 20 ++---- fractor/bin/fractor.php | 4 +- fractor/config/application.php | 8 +-- fractor/src/Command/ProcessCommand.php | 1 - fractor/src/Configuration/FractorConfig.php | 68 ------------------- fractor/src/Configuration/Option.php | 3 +- ...lder.php => ContainerContainerBuilder.php} | 21 ++---- fractor/src/Factory/ConfigurationFactory.php | 4 +- fractor/src/Fractor/FractorRunner.php | 1 - .../PHPUnit/AbstractFractorTestCase.php | 7 +- fractor/src/ValueObject/Configuration.php | 11 +-- .../tests/Configuration/FractorConfigTest.php | 62 ----------------- fractor/tests/FileSystem/FileFinderTest.php | 5 -- .../FractorRunner/FractorRunnerTest.php | 5 -- .../FractorRunner/config/application.php | 3 + .../Fractor/FractorRunner/config/fractor.php | 8 --- .../AddRenderTypeToFlexFormFractorTest.php | 6 +- .../Rules/FlexForm/config/application.php | 9 +++ .../tests/Rules/FlexForm/config/fractor.php | 8 --- 21 files changed, 41 insertions(+), 215 deletions(-) create mode 100644 .gitignore delete mode 100644 .phpunit.result.cache delete mode 100644 fractor/src/Configuration/FractorConfig.php rename fractor/src/DependencyInjection/{ContainerBuilder.php => ContainerContainerBuilder.php} (66%) delete mode 100644 fractor/tests/Configuration/FractorConfigTest.php delete mode 100644 fractor/tests/Fractor/FractorRunner/config/fractor.php create mode 100644 typo3-fractor/tests/Rules/FlexForm/config/application.php delete mode 100644 typo3-fractor/tests/Rules/FlexForm/config/fractor.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..143c4262 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.phpunit.result.cache \ No newline at end of file diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index 4a5ded99..00000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":{"Fractor\\FractorRunner\\FractorRunnerTest::test":8},"times":{"Fractor\\FractorRunner\\FractorRunnerTest::test":0.005}} \ No newline at end of file diff --git a/README.md b/README.md index e8548ee2..d1db3cfb 100644 --- a/README.md +++ b/README.md @@ -33,27 +33,19 @@ To utilize Fractor effectively, follow these steps: ``` 2. **Configuration**: - - Create a PHP configuration file (e.g., `fractor.php`) where you define the rules to be applied. - - At minimum, a configuration file must specify the paths to process, the file processor(s) to use and the rule(s) to apply: + - Create a PHP configuration file (e.g., `fractor.php`) where you define the paths to your files. + - At minimum, a configuration file must specify the paths to process: ```php import(__DIR__ . '/vendor/a9f/fractor-xml/config/fractor.php'); - - $config->setPaths([ - __DIR__ . '/output/', - ]); - - $config->withFileProcessor(XmlFileProcessor::class); - - $config->withRule(AddRenderTypeToFlexFormFractor::class); - $config->withRule(DummyRule::class); + return static function (ContainerConfigurator $containerConfigurator) { + $parameters = $containerConfigurator->parameters(); + $parameters->set(Option::PATHS, [__DIR__ . '/output/']); }; ``` diff --git a/fractor/bin/fractor.php b/fractor/bin/fractor.php index 3be49dcb..d7872928 100755 --- a/fractor/bin/fractor.php +++ b/fractor/bin/fractor.php @@ -1,7 +1,7 @@ createDependencyInjectionContainer($configFile); +$container = (new ContainerContainerBuilder())->createDependencyInjectionContainer([$configFile]); /** @var FractorApplication $application */ $application = $container->get(FractorApplication::class); diff --git a/fractor/config/application.php b/fractor/config/application.php index dd9815c9..68d853c4 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -1,6 +1,6 @@ parameters(); - $parameters->set(\a9f\Fractor\Configuration\Option::PATHS, []); - $parameters->set(\a9f\Fractor\Configuration\Option::FILE_EXTENSIONS, []); + $parameters->set(Option::PATHS, []); + $parameters->set(Option::FILE_EXTENSIONS, []); $services = $containerConfigurator->services(); $services->defaults() ->autowire() @@ -37,8 +37,6 @@ ->alias(ParameterBagInterface::class, 'parameter_bag'); $services->set(FractorRunner::class)->arg('$processors', tagged_iterator('fractor.file_processor')); - $services->set(FractorConfig::class) - ->lazy(); $containerBuilder->registerForAutoconfiguration(FileProcessor::class)->addTag('fractor.file_processor'); }; diff --git a/fractor/src/Command/ProcessCommand.php b/fractor/src/Command/ProcessCommand.php index 7cf190c2..1a37199e 100644 --- a/fractor/src/Command/ProcessCommand.php +++ b/fractor/src/Command/ProcessCommand.php @@ -2,7 +2,6 @@ namespace a9f\Fractor\Command; -use a9f\Fractor\Configuration\FractorConfig; use a9f\Fractor\Factory\ConfigurationFactory; use a9f\Fractor\Fractor\FractorRunner; use Symfony\Component\Console\Attribute\AsCommand; diff --git a/fractor/src/Configuration/FractorConfig.php b/fractor/src/Configuration/FractorConfig.php deleted file mode 100644 index e3d57aa1..00000000 --- a/fractor/src/Configuration/FractorConfig.php +++ /dev/null @@ -1,68 +0,0 @@ - */ - private array $paths = []; - - /** @var list */ - private array $fileExtensions = []; - - /** - * @param non-empty-list $paths A list of paths to process - */ - public function setPaths(array $paths): self - { - $this->paths = $paths; - return $this; - } - - /** - * @return list - */ - public function getPaths(): array - { - return $this->paths; - } - - /** - * @param list $extensions - */ - public function setFileExtensions(array $extensions): self - { - $this->fileExtensions = $extensions; - - return $this; - } - - /** - * @return list - */ - public function getFileExtensions(): array - { - return $this->fileExtensions; - } - - public function import(string $configFile): void - { - if (!file_exists($configFile)) { - throw new \RuntimeException(sprintf('Config file %s does not exist, cannot import', $configFile)); - } - - $closure = (require $configFile); - if (!is_callable($closure)) { - throw new \RuntimeException(sprintf( - 'Fractor config files should return a callable for configuration, %s returned %s instead', - $configFile, - get_debug_type($closure) - )); - } - - /** @var callable(FractorConfig): void $closure */ - $closure($this); - } -} diff --git a/fractor/src/Configuration/Option.php b/fractor/src/Configuration/Option.php index 9f9e5b22..f1f1dc7e 100644 --- a/fractor/src/Configuration/Option.php +++ b/fractor/src/Configuration/Option.php @@ -1,4 +1,5 @@ $additionalConfigFiles */ - public function createDependencyInjectionContainer(?string $fractorConfigFile, array $additionalConfigFiles = []): ContainerInterface + public function createDependencyInjectionContainer(array $additionalConfigFiles = []): ContainerInterface { - $config = new FractorConfig(); - - $definition = new Definition(FractorConfig::class); - $definition->setPublic(true); - $config->set(Container::class, $config); - $config->set(FractorConfig::class, $config); - + $config = new \Symfony\Component\DependencyInjection\ContainerBuilder(); $fileLoader = new PhpFileLoader($config, new FileLocator(__DIR__ . '/../../config/')); $fileLoader->load('application.php'); @@ -31,10 +22,6 @@ public function createDependencyInjectionContainer(?string $fractorConfigFile, a $config->addCompilerPass(new CommandsCompilerPass()); - if ($fractorConfigFile !== null && is_file($fractorConfigFile)) { - $config->import($fractorConfigFile); - } - foreach ($additionalConfigFiles as $additionalConfigFile) { $fileLoader = new PhpFileLoader($config, new FileLocator(dirname($additionalConfigFile))); $fileLoader->load($additionalConfigFile); @@ -45,7 +32,7 @@ public function createDependencyInjectionContainer(?string $fractorConfigFile, a return $config; } - private function importExtensionConfigurations(FractorConfig $config): void + private function importExtensionConfigurations(\Symfony\Component\DependencyInjection\ContainerBuilder $config): void { if (!class_exists('a9f\\FractorExtensionInstaller\\Generated\\InstalledPackages')) { return; diff --git a/fractor/src/Factory/ConfigurationFactory.php b/fractor/src/Factory/ConfigurationFactory.php index 313d5450..afe8cba4 100644 --- a/fractor/src/Factory/ConfigurationFactory.php +++ b/fractor/src/Factory/ConfigurationFactory.php @@ -1,9 +1,9 @@ parameterBag->get(Option::PATHS), ); } -} \ No newline at end of file +} diff --git a/fractor/src/Fractor/FractorRunner.php b/fractor/src/Fractor/FractorRunner.php index 6abb9cb9..b8fc8181 100644 --- a/fractor/src/Fractor/FractorRunner.php +++ b/fractor/src/Fractor/FractorRunner.php @@ -2,7 +2,6 @@ namespace a9f\Fractor\Fractor; -use a9f\Fractor\Configuration\FractorConfig; use a9f\Fractor\Contract\FileProcessor; use a9f\Fractor\FileSystem\FileCollector; use a9f\Fractor\FileSystem\FileFinder; diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index 3a190e70..f9042301 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -4,8 +4,7 @@ namespace a9f\Fractor\Testing\PHPUnit; -use a9f\Fractor\Configuration\FractorConfig; -use a9f\Fractor\DependencyInjection\ContainerBuilder; +use a9f\Fractor\DependencyInjection\ContainerContainerBuilder; use a9f\Fractor\Exception\ShouldNotHappenException; use a9f\Fractor\Factory\ConfigurationFactory; use a9f\Fractor\FileSystem\FileCollector; @@ -19,8 +18,6 @@ abstract class AbstractFractorTestCase extends TestCase private FractorRunner $fractorRunner; protected FileCollector $fileCollector; - abstract protected function provideConfigFilePath(): ?string; - /** * @return array */ @@ -38,7 +35,7 @@ protected function setUp(): void protected function bootFromConfigFile(): void { - $this->currentContainer = (new ContainerBuilder())->createDependencyInjectionContainer($this->provideConfigFilePath(), $this->additionalConfigurationFiles()); + $this->currentContainer = (new ContainerContainerBuilder())->createDependencyInjectionContainer($this->additionalConfigurationFiles()); } protected function doTest(): void diff --git a/fractor/src/ValueObject/Configuration.php b/fractor/src/ValueObject/Configuration.php index 1bea6801..8b0e1278 100644 --- a/fractor/src/ValueObject/Configuration.php +++ b/fractor/src/ValueObject/Configuration.php @@ -1,4 +1,5 @@ $fileExtensions - * @param array $paths + * @param list $fileExtensions + * @param list $paths */ public function __construct(private array $fileExtensions, private array $paths) { } /** - * @return array + * @return list */ public function getFileExtensions(): array { @@ -22,10 +23,10 @@ public function getFileExtensions(): array } /** - * @return array + * @return list */ public function getPaths(): array { return $this->paths; } -} \ No newline at end of file +} diff --git a/fractor/tests/Configuration/FractorConfigTest.php b/fractor/tests/Configuration/FractorConfigTest.php deleted file mode 100644 index dc28a4f3..00000000 --- a/fractor/tests/Configuration/FractorConfigTest.php +++ /dev/null @@ -1,62 +0,0 @@ -placeConfigFileInTemporaryFolderAndImport($subject, $closure); - - self::assertTrue($GLOBALS['called']); - } - - #[Test] - public function importFileThrowsExceptionIfNoClosureIsReturned(): void - { - $subject = new FractorConfig(); - - $this->expectException(\RuntimeException::class); - - $closure = <<placeConfigFileInTemporaryFolderAndImport($subject, $closure); - } - - private function placeConfigFileInTemporaryFolderAndImport(FractorConfig $config, string $closure): void - { - $tempFile = tempnam(sys_get_temp_dir(), 'fractor-test'); - self::assertIsString($tempFile); - try { - file_put_contents($tempFile, $closure); - - $config->import($tempFile); - } finally { - if (file_exists($tempFile)) { - unlink($tempFile); - } - } - } -} diff --git a/fractor/tests/FileSystem/FileFinderTest.php b/fractor/tests/FileSystem/FileFinderTest.php index 7cb2d862..8cd0c520 100644 --- a/fractor/tests/FileSystem/FileFinderTest.php +++ b/fractor/tests/FileSystem/FileFinderTest.php @@ -37,9 +37,4 @@ public function findAllNonEmptyFilesInGivenDirectoriesWithGivenExtensions(): voi { self::assertCount(2, $this->subject->findFiles([__DIR__ . '/Fixture/DirectorToSearchIn'], ['txt', 'json'])); } - - protected function provideConfigFilePath(): ?string - { - return null; - } } diff --git a/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php index d6fafefe..b94e06c7 100644 --- a/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php +++ b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php @@ -8,11 +8,6 @@ final class FractorRunnerTest extends AbstractFractorTestCase { - protected function provideConfigFilePath(): ?string - { - return __DIR__ . '/config/fractor.php'; - } - public function test(): void { $this->doTest(); diff --git a/fractor/tests/Fractor/FractorRunner/config/application.php b/fractor/tests/Fractor/FractorRunner/config/application.php index 46fb1d23..a3535ac5 100644 --- a/fractor/tests/Fractor/FractorRunner/config/application.php +++ b/fractor/tests/Fractor/FractorRunner/config/application.php @@ -8,6 +8,9 @@ use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator; return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder): void { + $parameters = $containerConfigurator->parameters(); + $parameters->set(\a9f\Fractor\Configuration\Option::FILE_EXTENSIONS, ['txt']); + $parameters->set(\a9f\Fractor\Configuration\Option::PATHS, [__DIR__ . '/../Fixture/']); $services = $containerConfigurator->services(); $services->defaults() ->autowire() diff --git a/fractor/tests/Fractor/FractorRunner/config/fractor.php b/fractor/tests/Fractor/FractorRunner/config/fractor.php deleted file mode 100644 index 7b9847b1..00000000 --- a/fractor/tests/Fractor/FractorRunner/config/fractor.php +++ /dev/null @@ -1,8 +0,0 @@ -setPaths([__DIR__ . '/../Fixture/']); - $config->setFileExtensions(['txt']); -}; diff --git a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php index 81ceab0a..54ddc989 100644 --- a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php +++ b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php @@ -21,16 +21,12 @@ public function test(): void self::assertStringEqualsFile(__DIR__ . '/Assertions/SelectWithoutRenderType.xml', $file->getContent()); } - protected function provideConfigFilePath(): ?string - { - return __DIR__ . '/config/fractor.php'; - } - protected function additionalConfigurationFiles(): array { return [ __DIR__ . '/../../../../fractor-xml/config/application.php', __DIR__ . '/../../../config/application.php', + __DIR__ . '/config/application.php', ]; } } diff --git a/typo3-fractor/tests/Rules/FlexForm/config/application.php b/typo3-fractor/tests/Rules/FlexForm/config/application.php new file mode 100644 index 00000000..59d8e916 --- /dev/null +++ b/typo3-fractor/tests/Rules/FlexForm/config/application.php @@ -0,0 +1,9 @@ +parameters(); + $parameters->set(\a9f\Fractor\Configuration\Option::FILE_EXTENSIONS, ['xml']); + $parameters->set(\a9f\Fractor\Configuration\Option::PATHS, [__DIR__ . '/../Fixture/']); +}; diff --git a/typo3-fractor/tests/Rules/FlexForm/config/fractor.php b/typo3-fractor/tests/Rules/FlexForm/config/fractor.php deleted file mode 100644 index 5b5ec6ad..00000000 --- a/typo3-fractor/tests/Rules/FlexForm/config/fractor.php +++ /dev/null @@ -1,8 +0,0 @@ -setPaths([__DIR__ . '/../Fixture/']); - $config->setFileExtensions(['xml']); -}; From 034b64b44e172f09c99c356732723f4f6e854d2d Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 10:47:23 +0200 Subject: [PATCH 21/31] TASK: Simplify configuration for file extensions --- fractor-xml/src/XmlFileProcessor.php | 5 +++++ fractor/config/application.php | 3 ++- fractor/src/Configuration/Option.php | 2 -- fractor/src/Contract/FileProcessor.php | 5 +++++ fractor/src/Factory/ConfigurationFactory.php | 13 +++++++++++-- .../Fractor/FractorRunner/config/application.php | 4 ++-- .../Helper/FileProcessor/TextFileProcessor.php | 5 +++++ .../tests/Rules/FlexForm/config/application.php | 4 ++-- 8 files changed, 32 insertions(+), 9 deletions(-) diff --git a/fractor-xml/src/XmlFileProcessor.php b/fractor-xml/src/XmlFileProcessor.php index 2db0fb03..8aca2116 100644 --- a/fractor-xml/src/XmlFileProcessor.php +++ b/fractor-xml/src/XmlFileProcessor.php @@ -39,4 +39,9 @@ public function handle(File $file): void $file->changeFileContent($newFileContent); } + + public function allowedFileExtensions(): array + { + return ['xml']; + } } diff --git a/fractor/config/application.php b/fractor/config/application.php index 68d853c4..7a4c08b1 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -2,6 +2,7 @@ use a9f\Fractor\Configuration\Option; use a9f\Fractor\Contract\FileProcessor; +use a9f\Fractor\Factory\ConfigurationFactory; use a9f\Fractor\Fractor\FractorRunner; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; @@ -14,7 +15,6 @@ return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder): void { $parameters = $containerConfigurator->parameters(); $parameters->set(Option::PATHS, []); - $parameters->set(Option::FILE_EXTENSIONS, []); $services = $containerConfigurator->services(); $services->defaults() ->autowire() @@ -37,6 +37,7 @@ ->alias(ParameterBagInterface::class, 'parameter_bag'); $services->set(FractorRunner::class)->arg('$processors', tagged_iterator('fractor.file_processor')); + $services->set(ConfigurationFactory::class)->arg('$processors', tagged_iterator('fractor.file_processor')); $containerBuilder->registerForAutoconfiguration(FileProcessor::class)->addTag('fractor.file_processor'); }; diff --git a/fractor/src/Configuration/Option.php b/fractor/src/Configuration/Option.php index f1f1dc7e..db290ce9 100644 --- a/fractor/src/Configuration/Option.php +++ b/fractor/src/Configuration/Option.php @@ -7,6 +7,4 @@ final class Option { public const PATHS = 'paths'; - - public const FILE_EXTENSIONS = 'file_extensions'; } diff --git a/fractor/src/Contract/FileProcessor.php b/fractor/src/Contract/FileProcessor.php index ee61ecbf..70511bcd 100644 --- a/fractor/src/Contract/FileProcessor.php +++ b/fractor/src/Contract/FileProcessor.php @@ -9,4 +9,9 @@ interface FileProcessor public function canHandle(\SplFileInfo $file): bool; public function handle(File $file): void; + + /** + * @return list + */ + public function allowedFileExtensions(): array; } diff --git a/fractor/src/Factory/ConfigurationFactory.php b/fractor/src/Factory/ConfigurationFactory.php index afe8cba4..b23a4817 100644 --- a/fractor/src/Factory/ConfigurationFactory.php +++ b/fractor/src/Factory/ConfigurationFactory.php @@ -5,19 +5,28 @@ namespace a9f\Fractor\Factory; use a9f\Fractor\Configuration\Option; +use a9f\Fractor\Contract\FileProcessor; use a9f\Fractor\ValueObject\Configuration; use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; final readonly class ConfigurationFactory { - public function __construct(private ContainerBagInterface $parameterBag) + /** + * @param list $processors + */ + public function __construct(private ContainerBagInterface $parameterBag, private iterable $processors) { } public function create(): Configuration { + $fileExtensions = []; + foreach ($this->processors as $processor) { + $fileExtensions = array_merge($processor->allowedFileExtensions(), $fileExtensions); + } + return new Configuration( - $this->parameterBag->get(Option::FILE_EXTENSIONS), + array_unique($fileExtensions), $this->parameterBag->get(Option::PATHS), ); } diff --git a/fractor/tests/Fractor/FractorRunner/config/application.php b/fractor/tests/Fractor/FractorRunner/config/application.php index a3535ac5..ef7f203b 100644 --- a/fractor/tests/Fractor/FractorRunner/config/application.php +++ b/fractor/tests/Fractor/FractorRunner/config/application.php @@ -1,5 +1,6 @@ parameters(); - $parameters->set(\a9f\Fractor\Configuration\Option::FILE_EXTENSIONS, ['txt']); - $parameters->set(\a9f\Fractor\Configuration\Option::PATHS, [__DIR__ . '/../Fixture/']); + $parameters->set(Option::PATHS, [__DIR__ . '/../Fixture/']); $services = $containerConfigurator->services(); $services->defaults() ->autowire() diff --git a/fractor/tests/Helper/FileProcessor/TextFileProcessor.php b/fractor/tests/Helper/FileProcessor/TextFileProcessor.php index 69c8b08c..99fb2ee8 100644 --- a/fractor/tests/Helper/FileProcessor/TextFileProcessor.php +++ b/fractor/tests/Helper/FileProcessor/TextFileProcessor.php @@ -28,4 +28,9 @@ public function handle(File $file): void $rule->apply($file); } } + + public function allowedFileExtensions(): array + { + return ['txt']; + } } diff --git a/typo3-fractor/tests/Rules/FlexForm/config/application.php b/typo3-fractor/tests/Rules/FlexForm/config/application.php index 59d8e916..cde4cb30 100644 --- a/typo3-fractor/tests/Rules/FlexForm/config/application.php +++ b/typo3-fractor/tests/Rules/FlexForm/config/application.php @@ -1,9 +1,9 @@ parameters(); - $parameters->set(\a9f\Fractor\Configuration\Option::FILE_EXTENSIONS, ['xml']); - $parameters->set(\a9f\Fractor\Configuration\Option::PATHS, [__DIR__ . '/../Fixture/']); + $parameters->set(Option::PATHS, [__DIR__ . '/../Fixture/']); }; From c8f8a56767d96865b6689add583241da8acfc110 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 10:52:50 +0200 Subject: [PATCH 22/31] TASK: Simplify ContainerBuilder file loader --- .../ContainerContainerBuilder.php | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/fractor/src/DependencyInjection/ContainerContainerBuilder.php b/fractor/src/DependencyInjection/ContainerContainerBuilder.php index 709f0745..17c38167 100644 --- a/fractor/src/DependencyInjection/ContainerContainerBuilder.php +++ b/fractor/src/DependencyInjection/ContainerContainerBuilder.php @@ -14,37 +14,39 @@ class ContainerContainerBuilder */ public function createDependencyInjectionContainer(array $additionalConfigFiles = []): ContainerInterface { - $config = new \Symfony\Component\DependencyInjection\ContainerBuilder(); - $fileLoader = new PhpFileLoader($config, new FileLocator(__DIR__ . '/../../config/')); - $fileLoader->load('application.php'); + $containerBuilder = new \Symfony\Component\DependencyInjection\ContainerBuilder(); + $this->loadFile($containerBuilder,__DIR__ . '/../../config/application.php'); + $this->importExtensionConfigurations($containerBuilder); - $this->importExtensionConfigurations($config); - - $config->addCompilerPass(new CommandsCompilerPass()); + $containerBuilder->addCompilerPass(new CommandsCompilerPass()); foreach ($additionalConfigFiles as $additionalConfigFile) { - $fileLoader = new PhpFileLoader($config, new FileLocator(dirname($additionalConfigFile))); - $fileLoader->load($additionalConfigFile); + $this->loadFile($containerBuilder,$additionalConfigFile); } - $config->compile(); + $containerBuilder->compile(); + + return $containerBuilder; + } - return $config; + + private function loadFile(\Symfony\Component\DependencyInjection\ContainerBuilder $containerBuilder, string $pathToFile): void + { + $fileLoader = new PhpFileLoader($containerBuilder, new FileLocator(dirname($pathToFile))); + $fileLoader->load($pathToFile); } - private function importExtensionConfigurations(\Symfony\Component\DependencyInjection\ContainerBuilder $config): void + private function importExtensionConfigurations(\Symfony\Component\DependencyInjection\ContainerBuilder $containerBuilder): void { if (!class_exists('a9f\\FractorExtensionInstaller\\Generated\\InstalledPackages')) { return; } foreach (\a9f\FractorExtensionInstaller\Generated\InstalledPackages::PACKAGES as $package) { - $extensionBasePath = $package['path']; - $filePath = $extensionBasePath . '/config/application.php'; + $filePath = $package['path'] . '/config/application.php'; if (file_exists($filePath)) { - $fileLoader = new PhpFileLoader($config, new FileLocator(dirname($filePath))); - $fileLoader->load(basename($filePath)); + $this->loadFile($containerBuilder, $filePath); } } } From 9b913a3a8aec64db2ecea6c22b2f3511a40b6c09 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 12:51:02 +0200 Subject: [PATCH 23/31] TASK: Fix coding standards --- .gitignore | 3 ++- fractor/src/DependencyInjection/ContainerContainerBuilder.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 143c4262..b73d3039 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache +run-test.sh \ No newline at end of file diff --git a/fractor/src/DependencyInjection/ContainerContainerBuilder.php b/fractor/src/DependencyInjection/ContainerContainerBuilder.php index 17c38167..39e9d1d7 100644 --- a/fractor/src/DependencyInjection/ContainerContainerBuilder.php +++ b/fractor/src/DependencyInjection/ContainerContainerBuilder.php @@ -15,13 +15,13 @@ class ContainerContainerBuilder public function createDependencyInjectionContainer(array $additionalConfigFiles = []): ContainerInterface { $containerBuilder = new \Symfony\Component\DependencyInjection\ContainerBuilder(); - $this->loadFile($containerBuilder,__DIR__ . '/../../config/application.php'); + $this->loadFile($containerBuilder, __DIR__ . '/../../config/application.php'); $this->importExtensionConfigurations($containerBuilder); $containerBuilder->addCompilerPass(new CommandsCompilerPass()); foreach ($additionalConfigFiles as $additionalConfigFile) { - $this->loadFile($containerBuilder,$additionalConfigFile); + $this->loadFile($containerBuilder, $additionalConfigFile); } $containerBuilder->compile(); From c20825148d25f9f5e3c3fdc008718b8bb37596a0 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 12:57:24 +0200 Subject: [PATCH 24/31] TASK: Create configuration via service configuration --- fractor/config/application.php | 2 ++ fractor/src/Command/ProcessCommand.php | 5 ++--- fractor/src/Fractor/FractorRunner.php | 8 ++++---- fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php | 5 +++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fractor/config/application.php b/fractor/config/application.php index 7a4c08b1..6485d398 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -4,6 +4,7 @@ use a9f\Fractor\Contract\FileProcessor; use a9f\Fractor\Factory\ConfigurationFactory; use a9f\Fractor\Fractor\FractorRunner; +use a9f\Fractor\ValueObject\Configuration; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag; @@ -36,6 +37,7 @@ ->alias(ContainerBagInterface::class, 'parameter_bag') ->alias(ParameterBagInterface::class, 'parameter_bag'); + $services->set(Configuration::class)->factory([service(ConfigurationFactory::class), 'create']); $services->set(FractorRunner::class)->arg('$processors', tagged_iterator('fractor.file_processor')); $services->set(ConfigurationFactory::class)->arg('$processors', tagged_iterator('fractor.file_processor')); diff --git a/fractor/src/Command/ProcessCommand.php b/fractor/src/Command/ProcessCommand.php index 1a37199e..415c7f1d 100644 --- a/fractor/src/Command/ProcessCommand.php +++ b/fractor/src/Command/ProcessCommand.php @@ -2,7 +2,6 @@ namespace a9f\Fractor\Command; -use a9f\Fractor\Factory\ConfigurationFactory; use a9f\Fractor\Fractor\FractorRunner; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -13,7 +12,7 @@ #[AsCommand('process', 'Runs Fractor with the given configuration file')] class ProcessCommand extends Command { - public function __construct(private readonly FractorRunner $runner, private readonly ConfigurationFactory $configurationFactory) + public function __construct(private readonly FractorRunner $runner) { parent::__construct(); } @@ -30,7 +29,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $this->runner->run($this->configurationFactory->create()); + $this->runner->run(); return Command::SUCCESS; } diff --git a/fractor/src/Fractor/FractorRunner.php b/fractor/src/Fractor/FractorRunner.php index b8fc8181..58889ebc 100644 --- a/fractor/src/Fractor/FractorRunner.php +++ b/fractor/src/Fractor/FractorRunner.php @@ -18,17 +18,17 @@ /** * @param list $processors */ - public function __construct(private FileFinder $fileFinder, private FileCollector $fileCollector, private iterable $processors) + public function __construct(private FileFinder $fileFinder, private FileCollector $fileCollector, private iterable $processors, private Configuration $configuration) { } - public function run(Configuration $configuration): void + public function run(): void { - if ($configuration->getPaths() === []) { + if ($this->configuration->getPaths() === []) { throw new \RuntimeException('No directories given'); } - $files = $this->fileFinder->findFiles($configuration->getPaths(), $configuration->getFileExtensions()); + $files = $this->fileFinder->findFiles($this->configuration->getPaths(), $this->configuration->getFileExtensions()); foreach ($files as $file) { foreach ($this->processors as $processor) { diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index f9042301..486f1d4b 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -6,9 +6,9 @@ use a9f\Fractor\DependencyInjection\ContainerContainerBuilder; use a9f\Fractor\Exception\ShouldNotHappenException; -use a9f\Fractor\Factory\ConfigurationFactory; use a9f\Fractor\FileSystem\FileCollector; use a9f\Fractor\Fractor\FractorRunner; +use a9f\Fractor\ValueObject\Configuration; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -17,6 +17,7 @@ abstract class AbstractFractorTestCase extends TestCase private ?ContainerInterface $currentContainer = null; private FractorRunner $fractorRunner; protected FileCollector $fileCollector; + private Configuration $configuration; /** * @return array @@ -40,7 +41,7 @@ protected function bootFromConfigFile(): void protected function doTest(): void { - $this->fractorRunner->run($this->getService(ConfigurationFactory::class)->create()); + $this->fractorRunner->run(); } /** From 8ec03e74ce755688050d24c00987ab0e00056d88 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 14:19:30 +0200 Subject: [PATCH 25/31] TASK: Add e2e tests again --- fractor/src/Contract/FilePrinter.php | 9 +++++++ .../src/FileSystem/LocalFileSystemPrinter.php | 9 +++++++ tests/.gitignore | 4 +++ tests/composer.json | 25 +++++++++++++++++++ tests/run-test.sh | 24 ++++++++++++++++++ .../expected-output/FlexFormWithSelect.xml | 18 +++++++++++++ .../fixtures/FlexFormWithSelect.xml | 18 +++++++++++++ tests/typo3-flexform/fractor.php | 9 +++++++ 8 files changed, 116 insertions(+) create mode 100644 fractor/src/Contract/FilePrinter.php create mode 100644 fractor/src/FileSystem/LocalFileSystemPrinter.php create mode 100644 tests/.gitignore create mode 100644 tests/composer.json create mode 100755 tests/run-test.sh create mode 100644 tests/typo3-flexform/expected-output/FlexFormWithSelect.xml create mode 100644 tests/typo3-flexform/fixtures/FlexFormWithSelect.xml create mode 100644 tests/typo3-flexform/fractor.php diff --git a/fractor/src/Contract/FilePrinter.php b/fractor/src/Contract/FilePrinter.php new file mode 100644 index 00000000..bbbc2f02 --- /dev/null +++ b/fractor/src/Contract/FilePrinter.php @@ -0,0 +1,9 @@ +/dev/null && pwd)" +BASE_DIR="$TESTS_BASE_DIR/../" + +cd $TESTS_BASE_DIR + +rm -r composer.lock vendor || true +composer install + +TEST_DIR=typo3-flexform + +cd $TEST_DIR + +[[ -d ./output/ ]] && rm -rf ./output/ +cp -r fixtures/ output/ + +cd $TESTS_BASE_DIR +./vendor/bin/fractor process -c $TESTS_BASE_DIR/$TEST_DIR/fractor.php + +# TODO remove -b once we keep the output format when re-writing the file +diff -rub $TEST_DIR/expected-output/ $TEST_DIR/output/ diff --git a/tests/typo3-flexform/expected-output/FlexFormWithSelect.xml b/tests/typo3-flexform/expected-output/FlexFormWithSelect.xml new file mode 100644 index 00000000..d441be59 --- /dev/null +++ b/tests/typo3-flexform/expected-output/FlexFormWithSelect.xml @@ -0,0 +1,18 @@ + + + + + + array + + + + select + selectSingle + + + + + + + diff --git a/tests/typo3-flexform/fixtures/FlexFormWithSelect.xml b/tests/typo3-flexform/fixtures/FlexFormWithSelect.xml new file mode 100644 index 00000000..fb071d8d --- /dev/null +++ b/tests/typo3-flexform/fixtures/FlexFormWithSelect.xml @@ -0,0 +1,18 @@ + + + + + + array + + + + select + 1 + + + + + + + \ No newline at end of file diff --git a/tests/typo3-flexform/fractor.php b/tests/typo3-flexform/fractor.php new file mode 100644 index 00000000..080af1c2 --- /dev/null +++ b/tests/typo3-flexform/fractor.php @@ -0,0 +1,9 @@ +parameters(); + $parameters->set(Option::PATHS, [__DIR__ . '/output/']); +}; From 44b943e26a211e326dcd931eaead8025bd323f9c Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 14:19:38 +0200 Subject: [PATCH 26/31] TASK: Add e2e tests again --- .../workflows/lint_test_pull_requests.yaml | 19 ++++++++++++++++++- fractor-xml/config/application.php | 1 - fractor/config/application.php | 1 + fractor/src/Contract/FilePrinter.php | 9 ++++++--- .../src/FileSystem/LocalFileSystemPrinter.php | 14 +++++++++++--- fractor/src/Fractor/FractorRunner.php | 14 ++++++++++++-- .../PHPUnit/AbstractFractorTestCase.php | 2 +- typo3-fractor/src/AbstractFlexformFractor.php | 4 ++-- 8 files changed, 51 insertions(+), 13 deletions(-) diff --git a/.github/workflows/lint_test_pull_requests.yaml b/.github/workflows/lint_test_pull_requests.yaml index 3c57c31a..2ecc3483 100644 --- a/.github/workflows/lint_test_pull_requests.yaml +++ b/.github/workflows/lint_test_pull_requests.yaml @@ -45,4 +45,21 @@ jobs: with: container_workdir: /app/${{ matrix.directory }} command: ${{ matrix.composer-command.command }} - memory_limit: 512M \ No newline at end of file + memory_limit: 512M + + tests: + runs-on: ubuntu-latest + name: End to end tests + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + + - name: Run tests + working-directory: tests + run: ./run-test.sh \ No newline at end of file diff --git a/fractor-xml/config/application.php b/fractor-xml/config/application.php index c991e62b..d4ebcc56 100644 --- a/fractor-xml/config/application.php +++ b/fractor-xml/config/application.php @@ -14,7 +14,6 @@ $services->load('a9f\\FractorXml\\', __DIR__ . '/../src/'); - $services->set(XmlFileProcessor::class)->arg('$rules', tagged_iterator('fractor.xml_rule')); $containerBuilder->registerForAutoconfiguration(XmlFractor::class)->addTag('fractor.xml_rule'); diff --git a/fractor/config/application.php b/fractor/config/application.php index 6485d398..9abdbb79 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -27,6 +27,7 @@ [ __DIR__ . '/../src/Configuration', __DIR__ . '/../src/ValueObject', + __DIR__ . '/../src/Testing', ] ); diff --git a/fractor/src/Contract/FilePrinter.php b/fractor/src/Contract/FilePrinter.php index bbbc2f02..3ffaf222 100644 --- a/fractor/src/Contract/FilePrinter.php +++ b/fractor/src/Contract/FilePrinter.php @@ -1,9 +1,12 @@ getFilePath(), $file->getContent()); + } +} diff --git a/fractor/src/Fractor/FractorRunner.php b/fractor/src/Fractor/FractorRunner.php index 58889ebc..79160231 100644 --- a/fractor/src/Fractor/FractorRunner.php +++ b/fractor/src/Fractor/FractorRunner.php @@ -2,6 +2,7 @@ namespace a9f\Fractor\Fractor; +use a9f\Fractor\Contract\FilePrinter; use a9f\Fractor\Contract\FileProcessor; use a9f\Fractor\FileSystem\FileCollector; use a9f\Fractor\FileSystem\FileFinder; @@ -18,11 +19,11 @@ /** * @param list $processors */ - public function __construct(private FileFinder $fileFinder, private FileCollector $fileCollector, private iterable $processors, private Configuration $configuration) + public function __construct(private FileFinder $fileFinder, private FileCollector $fileCollector, private iterable $processors, private Configuration $configuration, private FilePrinter $filePrinter) { } - public function run(): void + public function run(bool $dryRun = false): void { if ($this->configuration->getPaths() === []) { throw new \RuntimeException('No directories given'); @@ -42,5 +43,14 @@ public function run(): void $processor->handle($fractorFile); } } + + + foreach ($this->fileCollector->getFiles() as $file) { + if ($dryRun) { + continue; + } + + $this->filePrinter->printFile($file); + } } } diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index 486f1d4b..facdf5e9 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -41,7 +41,7 @@ protected function bootFromConfigFile(): void protected function doTest(): void { - $this->fractorRunner->run(); + $this->fractorRunner->run(true); } /** diff --git a/typo3-fractor/src/AbstractFlexformFractor.php b/typo3-fractor/src/AbstractFlexformFractor.php index 92520d01..146dc048 100644 --- a/typo3-fractor/src/AbstractFlexformFractor.php +++ b/typo3-fractor/src/AbstractFlexformFractor.php @@ -2,6 +2,7 @@ namespace a9f\Typo3Fractor; +use a9f\Fractor\Exception\ShouldNotHappenException; use a9f\FractorXml\AbstractXmlFractor; abstract class AbstractFlexformFractor extends AbstractXmlFractor @@ -11,8 +12,7 @@ public function canHandle(\DOMNode $node): bool $rootNode = $node->ownerDocument?->firstChild; if ($rootNode === null) { - // TODO convert into a custom ShouldNotHappenException - throw new \RuntimeException('Node\'s document does not have a root node'); + throw new ShouldNotHappenException('Node\'s document does not have a root node'); } return $rootNode->nodeName === 'T3DataStructure'; From 5a506af8919918d14555b8643dc344ba20282068 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 14:24:24 +0200 Subject: [PATCH 27/31] TASK: Simplify testing --- fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php | 2 -- .../Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php | 4 +--- typo3-fractor/tests/Rules/FlexForm/config/application.php | 3 +++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index facdf5e9..da92ec60 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -8,7 +8,6 @@ use a9f\Fractor\Exception\ShouldNotHappenException; use a9f\Fractor\FileSystem\FileCollector; use a9f\Fractor\Fractor\FractorRunner; -use a9f\Fractor\ValueObject\Configuration; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -17,7 +16,6 @@ abstract class AbstractFractorTestCase extends TestCase private ?ContainerInterface $currentContainer = null; private FractorRunner $fractorRunner; protected FileCollector $fileCollector; - private Configuration $configuration; /** * @return array diff --git a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php index 54ddc989..04838430 100644 --- a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php +++ b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php @@ -4,7 +4,7 @@ use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase; -class AddRenderTypeToFlexFormFractorTest extends AbstractFractorTestCase +final class AddRenderTypeToFlexFormFractorTest extends AbstractFractorTestCase { public function test(): void { @@ -24,8 +24,6 @@ public function test(): void protected function additionalConfigurationFiles(): array { return [ - __DIR__ . '/../../../../fractor-xml/config/application.php', - __DIR__ . '/../../../config/application.php', __DIR__ . '/config/application.php', ]; } diff --git a/typo3-fractor/tests/Rules/FlexForm/config/application.php b/typo3-fractor/tests/Rules/FlexForm/config/application.php index cde4cb30..f3d8d155 100644 --- a/typo3-fractor/tests/Rules/FlexForm/config/application.php +++ b/typo3-fractor/tests/Rules/FlexForm/config/application.php @@ -4,6 +4,9 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { + $containerConfigurator->import(__DIR__ . '/../../../../config/application.php'); + $containerConfigurator->import(__DIR__ . '/../../../../../fractor-xml/config/application.php'); + $parameters = $containerConfigurator->parameters(); $parameters->set(Option::PATHS, [__DIR__ . '/../Fixture/']); }; From 74676525e51d077840048f1d66948773d2e08e43 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 14:42:40 +0200 Subject: [PATCH 28/31] [TASK] Add ProgressBar for ProcessCommand --- fractor/config/application.php | 1 + fractor/src/Command/ProcessCommand.php | 3 +- fractor/src/Console/NullOutput.php | 22 +++++++++++ fractor/src/Console/SymfonyConsoleOutput.php | 39 +++++++++++++++++++ fractor/src/Contract/Output.php | 20 ++++++++++ fractor/src/Fractor/FractorRunner.php | 9 ++++- .../PHPUnit/AbstractFractorTestCase.php | 3 +- 7 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 fractor/src/Console/NullOutput.php create mode 100644 fractor/src/Console/SymfonyConsoleOutput.php create mode 100644 fractor/src/Contract/Output.php diff --git a/fractor/config/application.php b/fractor/config/application.php index 9abdbb79..a9c61427 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -26,6 +26,7 @@ ->exclude( [ __DIR__ . '/../src/Configuration', + __DIR__ . '/../src/Console', __DIR__ . '/../src/ValueObject', __DIR__ . '/../src/Testing', ] diff --git a/fractor/src/Command/ProcessCommand.php b/fractor/src/Command/ProcessCommand.php index 415c7f1d..cf50c447 100644 --- a/fractor/src/Command/ProcessCommand.php +++ b/fractor/src/Command/ProcessCommand.php @@ -2,6 +2,7 @@ namespace a9f\Fractor\Command; +use a9f\Fractor\Console\SymfonyConsoleOutput; use a9f\Fractor\Fractor\FractorRunner; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -29,7 +30,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $this->runner->run(); + $this->runner->run(new SymfonyConsoleOutput($output)); return Command::SUCCESS; } diff --git a/fractor/src/Console/NullOutput.php b/fractor/src/Console/NullOutput.php new file mode 100644 index 00000000..c7afa591 --- /dev/null +++ b/fractor/src/Console/NullOutput.php @@ -0,0 +1,22 @@ +progressBar = new ProgressBar($this->output, $max); + $this->progressBar->start(); + } + + public function progressAdvance(int $step = 1): void + { + $this->getProgressBar()->advance($step); + } + + public function progressFinish(): void + { + $this->getProgressBar()->finish(); + } + + private function getProgressBar(): ProgressBar + { + return $this->progressBar ?? throw new RuntimeException('The ProgressBar is not started.'); + } +} diff --git a/fractor/src/Contract/Output.php b/fractor/src/Contract/Output.php new file mode 100644 index 00000000..1adce3c0 --- /dev/null +++ b/fractor/src/Contract/Output.php @@ -0,0 +1,20 @@ +configuration->getPaths() === []) { throw new \RuntimeException('No directories given'); @@ -31,9 +32,12 @@ public function run(bool $dryRun = false): void $files = $this->fileFinder->findFiles($this->configuration->getPaths(), $this->configuration->getFileExtensions()); + $output->progressStart(count($files)); + foreach ($files as $file) { foreach ($this->processors as $processor) { if (!$processor->canHandle($file)) { + $output->progressAdvance(); continue; } @@ -41,6 +45,7 @@ public function run(bool $dryRun = false): void $this->fileCollector->addFile($fractorFile); $processor->handle($fractorFile); + $output->progressAdvance(); } } @@ -52,5 +57,7 @@ public function run(bool $dryRun = false): void $this->filePrinter->printFile($file); } + + $output->progressFinish(); } } diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index da92ec60..84aedffc 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -4,6 +4,7 @@ namespace a9f\Fractor\Testing\PHPUnit; +use a9f\Fractor\Console\NullOutput; use a9f\Fractor\DependencyInjection\ContainerContainerBuilder; use a9f\Fractor\Exception\ShouldNotHappenException; use a9f\Fractor\FileSystem\FileCollector; @@ -39,7 +40,7 @@ protected function bootFromConfigFile(): void protected function doTest(): void { - $this->fractorRunner->run(true); + $this->fractorRunner->run(new NullOutput(), true); } /** From 3e77107aa6702d83348a29f7a2eab31f53f8e4c5 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 14:50:09 +0200 Subject: [PATCH 29/31] [TASK] Add webomzart/assert to validate certain options --- fractor/composer.json | 3 ++- fractor/config/application.php | 2 +- fractor/src/Fractor/FractorRunner.php | 4 ---- fractor/src/ValueObject/Configuration.php | 4 ++++ 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fractor/composer.json b/fractor/composer.json index f1b7727c..724be146 100644 --- a/fractor/composer.json +++ b/fractor/composer.json @@ -17,7 +17,8 @@ "symfony/console": "^6.4", "symfony/dependency-injection": "^6.4", "symfony/filesystem": "^6.4", - "symfony/finder": "^6.4" + "symfony/finder": "^6.4", + "webmozart/assert": "^1.11" }, "require-dev": { "ergebnis/composer-normalize": "^2.42", diff --git a/fractor/config/application.php b/fractor/config/application.php index a9c61427..32d8d001 100644 --- a/fractor/config/application.php +++ b/fractor/config/application.php @@ -15,7 +15,7 @@ return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder): void { $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::PATHS, []); + $parameters->set(Option::PATHS, [__DIR__]); $services = $containerConfigurator->services(); $services->defaults() ->autowire() diff --git a/fractor/src/Fractor/FractorRunner.php b/fractor/src/Fractor/FractorRunner.php index 21a50a39..71a8799b 100644 --- a/fractor/src/Fractor/FractorRunner.php +++ b/fractor/src/Fractor/FractorRunner.php @@ -26,10 +26,6 @@ public function __construct(private FileFinder $fileFinder, private FileCollecto public function run(Output $output, bool $dryRun = false): void { - if ($this->configuration->getPaths() === []) { - throw new \RuntimeException('No directories given'); - } - $files = $this->fileFinder->findFiles($this->configuration->getPaths(), $this->configuration->getFileExtensions()); $output->progressStart(count($files)); diff --git a/fractor/src/ValueObject/Configuration.php b/fractor/src/ValueObject/Configuration.php index 8b0e1278..faf1bc11 100644 --- a/fractor/src/ValueObject/Configuration.php +++ b/fractor/src/ValueObject/Configuration.php @@ -4,6 +4,8 @@ namespace a9f\Fractor\ValueObject; +use Webmozart\Assert\Assert; + final readonly class Configuration { /** @@ -12,6 +14,8 @@ */ public function __construct(private array $fileExtensions, private array $paths) { + Assert::notEmpty($this->paths, 'No directories given'); + Assert::allStringNotEmpty($this->paths, 'No directories given'); } /** From bd08735d618986bc2414ee6bcc46fed8698785a9 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 15:06:02 +0200 Subject: [PATCH 30/31] [TASK] Simplify testing of assertions --- .../src/Testing/PHPUnit/AbstractFractorTestCase.php | 12 ++++++++++++ fractor/src/ValueObject/File.php | 10 ++++++++++ .../{Fixture => Fixtures}/my_text_file.txt | 0 .../Fractor/FractorRunner/FractorRunnerTest.php | 3 --- .../Fractor/FractorRunner/config/application.php | 3 +-- .../FlexForm/AddRenderTypeToFlexFormFractorTest.php | 10 ---------- .../SelectWithoutRenderType.xml | 0 .../SelectWithoutRenderTypeNotInFlexForm.xml | 0 .../tests/Rules/FlexForm/config/application.php | 2 +- 9 files changed, 24 insertions(+), 16 deletions(-) rename fractor/tests/Fractor/FractorRunner/{Fixture => Fixtures}/my_text_file.txt (100%) rename typo3-fractor/tests/Rules/FlexForm/{Fixture => Fixtures}/SelectWithoutRenderType.xml (100%) rename typo3-fractor/tests/Rules/FlexForm/{Fixture => Fixtures}/SelectWithoutRenderTypeNotInFlexForm.xml (100%) diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index 84aedffc..9ff19741 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -41,6 +41,18 @@ protected function bootFromConfigFile(): void protected function doTest(): void { $this->fractorRunner->run(new NullOutput(), true); + + foreach ($this->fileCollector->getFiles() as $file) { + if ($file) { + $assertionFile = $file->getDirectoryName() . '/../Assertions/' . $file->getFileName(); + + if (file_exists($assertionFile)) { + self::assertStringEqualsFile($assertionFile, $file->getContent()); + } else { + self::assertFalse($file->hasChanged()); + } + } + } } /** diff --git a/fractor/src/ValueObject/File.php b/fractor/src/ValueObject/File.php index 02fab1b8..c5543554 100644 --- a/fractor/src/ValueObject/File.php +++ b/fractor/src/ValueObject/File.php @@ -19,6 +19,16 @@ public function getFilePath(): string return $this->filePath; } + public function getDirectoryName(): string + { + return dirname($this->filePath); + } + + public function getFileName(): string + { + return basename($this->filePath); + } + public function getContent(): string { return $this->content; diff --git a/fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt b/fractor/tests/Fractor/FractorRunner/Fixtures/my_text_file.txt similarity index 100% rename from fractor/tests/Fractor/FractorRunner/Fixture/my_text_file.txt rename to fractor/tests/Fractor/FractorRunner/Fixtures/my_text_file.txt diff --git a/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php index b94e06c7..6c9f51e9 100644 --- a/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php +++ b/fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php @@ -11,9 +11,6 @@ final class FractorRunnerTest extends AbstractFractorTestCase public function test(): void { $this->doTest(); - $file = $this->fileCollector->getFileByPath(__DIR__ . '/Fixture/my_text_file.txt'); - self::assertNotNull($file); - self::assertStringEqualsFile(__DIR__ . '/Assertions/my_text_file.txt', $file->getContent()); } protected function additionalConfigurationFiles(): array diff --git a/fractor/tests/Fractor/FractorRunner/config/application.php b/fractor/tests/Fractor/FractorRunner/config/application.php index ef7f203b..d0474cc9 100644 --- a/fractor/tests/Fractor/FractorRunner/config/application.php +++ b/fractor/tests/Fractor/FractorRunner/config/application.php @@ -10,14 +10,13 @@ return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $containerBuilder): void { $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::PATHS, [__DIR__ . '/../Fixture/']); + $parameters->set(Option::PATHS, [__DIR__ . '/../Fixtures/']); $services = $containerConfigurator->services(); $services->defaults() ->autowire() ->autoconfigure(); $services->set(ReplaceXXXTextRule::class); - $services->set(TextFileProcessor::class)->arg('$rules', tagged_iterator('fractor.text_rules')); $containerBuilder->registerForAutoconfiguration(TextRule::class)->addTag('fractor.text_rules'); }; diff --git a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php index 04838430..a80c2762 100644 --- a/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php +++ b/typo3-fractor/tests/Rules/FlexForm/AddRenderTypeToFlexFormFractorTest.php @@ -8,17 +8,7 @@ final class AddRenderTypeToFlexFormFractorTest extends AbstractFractorTestCase { public function test(): void { - // Act $this->doTest(); - - // Arrange - $file = $this->fileCollector->getFileByPath(__DIR__ . '/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml'); - self::assertNotNull($file); - self::assertStringEqualsFile(__DIR__ . '/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml', $file->getContent()); - - $file = $this->fileCollector->getFileByPath(__DIR__ . '/Fixture/SelectWithoutRenderType.xml'); - self::assertNotNull($file); - self::assertStringEqualsFile(__DIR__ . '/Assertions/SelectWithoutRenderType.xml', $file->getContent()); } protected function additionalConfigurationFiles(): array diff --git a/typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderType.xml b/typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderType.xml similarity index 100% rename from typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderType.xml rename to typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderType.xml diff --git a/typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml b/typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderTypeNotInFlexForm.xml similarity index 100% rename from typo3-fractor/tests/Rules/FlexForm/Fixture/SelectWithoutRenderTypeNotInFlexForm.xml rename to typo3-fractor/tests/Rules/FlexForm/Fixtures/SelectWithoutRenderTypeNotInFlexForm.xml diff --git a/typo3-fractor/tests/Rules/FlexForm/config/application.php b/typo3-fractor/tests/Rules/FlexForm/config/application.php index f3d8d155..dd99f3e4 100644 --- a/typo3-fractor/tests/Rules/FlexForm/config/application.php +++ b/typo3-fractor/tests/Rules/FlexForm/config/application.php @@ -8,5 +8,5 @@ $containerConfigurator->import(__DIR__ . '/../../../../../fractor-xml/config/application.php'); $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::PATHS, [__DIR__ . '/../Fixture/']); + $parameters->set(Option::PATHS, [__DIR__ . '/../Fixtures/']); }; From fa0fdb3434d125ab6c6a309fc2ccf02fa83ff6ea Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 15:18:16 +0200 Subject: [PATCH 31/31] [TASK] Fix phpstan errors --- .../src/Testing/PHPUnit/AbstractFractorTestCase.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php index 9ff19741..8fca607c 100644 --- a/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php +++ b/fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php @@ -43,14 +43,12 @@ protected function doTest(): void $this->fractorRunner->run(new NullOutput(), true); foreach ($this->fileCollector->getFiles() as $file) { - if ($file) { - $assertionFile = $file->getDirectoryName() . '/../Assertions/' . $file->getFileName(); + $assertionFile = $file->getDirectoryName() . '/../Assertions/' . $file->getFileName(); - if (file_exists($assertionFile)) { - self::assertStringEqualsFile($assertionFile, $file->getContent()); - } else { - self::assertFalse($file->hasChanged()); - } + if (file_exists($assertionFile)) { + self::assertStringEqualsFile($assertionFile, $file->getContent()); + } else { + self::assertFalse($file->hasChanged()); } } }