From 6f6c54a1bb0fcc86713eae6a9a2e47caf391e6c2 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Wed, 17 Apr 2024 15:06:02 +0200 Subject: [PATCH] [TASK] Simplify testing of assertions --- .../src/Testing/PHPUnit/AbstractFractorTestCase.php | 12 ++++++++++++ fractor/src/ValueObject/File.php | 10 ++++++++++ .../Fractor/FractorRunner/FractorRunnerTest.php | 3 --- .../FlexForm/AddRenderTypeToFlexFormFractorTest.php | 10 ---------- 4 files changed, 22 insertions(+), 13 deletions(-) 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/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/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