Skip to content

Commit

Permalink
[TASK] Simplify testing of assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Apr 17, 2024
1 parent 3e77107 commit 6f6c54a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
12 changes: 12 additions & 0 deletions fractor/src/Testing/PHPUnit/AbstractFractorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions fractor/src/ValueObject/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions fractor/tests/Fractor/FractorRunner/FractorRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6f6c54a

Please sign in to comment.