Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-duplicate code within functional tests #28

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/Changelog/3.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Fixes
Tasks
-----

Nothing
* De-duplicate code within functional tests.

Deprecation
-----------
Expand Down
9 changes: 9 additions & 0 deletions Tests/Functional/Import/DestinationDataTest/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ protected function setUp(): void

$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/Structure.php');
}

protected function assertEmptyLog(): void
{
self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ public function cleansTransientFiles(): void
self::assertIsArray($transientFiles, 'Failed to retrieve transient files from filesystem.');
self::assertCount(0, $transientFiles, 'Got unexpected number of files');

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ class ImportDoesNotUseUploadsFolderTest extends AbstractTest
*/
public function doesNotUseUploadsFolder(): void
{
$fileImportPathConfiguration = 'staedte/beispielstadt/events/';
$fileImportPath = $this->getInstancePath() . '/fileadmin/' . $fileImportPathConfiguration;
GeneralUtility::mkdir_deep($fileImportPath);

$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/DefaultImportConfiguration.php');
$this->setUpConfiguration([
'restUrl = https://example.com/some-path/',
Expand All @@ -46,7 +42,7 @@ public function doesNotUseUploadsFolder(): void
self::assertSame('https://dam.destination.one/828118/f13bbf5602ffc406ebae2faa3527654dea84194666bce4925a1ca8bd3f50c5e9/tueftlerzeit-sfz-rudolstadt-jpg.jpg', (string)$requests[2]['request']->getUri());
self::assertSame('https://dam.destination.one/853436/109ac1cf87913e21b5e2b0ef0cc63d223a14374364952a855746a8e7c3fcfc36/lutherkirche-jpg.jpg', (string)$requests[3]['request']->getUri());

$importedFiles = GeneralUtility::getFilesInDir($fileImportPath);
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
Expand All @@ -60,10 +56,6 @@ public function doesNotUseUploadsFolder(): void

self::assertFalse(file_exists(Environment::getPublicPath() . '/uploads/tx_events/'), 'Uploads folder exists.');

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Wrm\Events\Tests\Functional\Import\DestinationDataTest;

use GuzzleHttp\Psr7\Response;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ImportDoesntBreakWithLongFileTitleTest extends AbstractTest
{
Expand All @@ -12,10 +11,6 @@ class ImportDoesntBreakWithLongFileTitleTest extends AbstractTest
*/
public function importsExampleAsExpected(): void
{
$fileImportPathConfiguration = 'staedte/beispielstadt/events/';
$fileImportPath = $this->getInstancePath() . '/fileadmin/' . $fileImportPathConfiguration;
GeneralUtility::mkdir_deep($fileImportPath);

$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleImportConfigurationWithCategories.php');
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleRegion.php');
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleCategory.php');
Expand All @@ -38,10 +33,6 @@ public function importsExampleAsExpected(): void
self::assertSame(0, $tester->getStatusCode());

$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportDoesntBreakWithLongFileTitle.csv');
self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Wrm\Events\Tests\Functional\Import\DestinationDataTest;

use GuzzleHttp\Psr7\Response;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ImportDoesntEndUpInEndlessDateCreationTest extends AbstractTest
{
Expand All @@ -12,10 +11,6 @@ class ImportDoesntEndUpInEndlessDateCreationTest extends AbstractTest
*/
public function importsExampleAsExpected(): void
{
$fileImportPathConfiguration = 'staedte/beispielstadt/events/';
$fileImportPath = $this->getInstancePath() . '/fileadmin/' . $fileImportPathConfiguration;
GeneralUtility::mkdir_deep($fileImportPath);

$this->setDateAspect(new \DateTimeImmutable('2022-07-01'), new \DateTimeZone('Europe/Berlin'));
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/DefaultImportConfiguration.php');
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleRegion.php');
Expand All @@ -38,10 +33,6 @@ public function importsExampleAsExpected(): void
self::assertSame(0, $tester->getStatusCode());

$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportDoesntEndUpInEndlessDateCreationTest.csv');
self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public function addsNewImages(): void
'Got unexpected number of files'
);

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}

/**
Expand Down Expand Up @@ -90,11 +86,7 @@ public function addsMultipleImagesToSingleEvent(): void
'Got unexpected number of files'
);

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}

/**
Expand Down Expand Up @@ -126,11 +118,7 @@ public function removesNoLongerExistingImages(): void
'Got unexpected number of files'
);

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}

/**
Expand Down Expand Up @@ -163,11 +151,7 @@ public function updatesExistingImage(): void
'Got unexpected number of files'
);

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}

/**
Expand Down Expand Up @@ -202,11 +186,7 @@ public function addsNewImageToExistingImages(): void
'Got unexpected number of files'
);

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}

/**
Expand Down Expand Up @@ -239,10 +219,6 @@ public function updatesSortingOfImages(): void
'Got unexpected number of files'
);

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ public function importsConfiguration(): void
{
$this->setDateAspect(new \DateTimeImmutable('2021-07-13', new \DateTimeZone('Europe/Berlin')));

$fileImportPathConfiguration1 = 'staedte/beispielstadt/events/';
$fileImportPath1 = $this->getInstancePath() . '/fileadmin/' . $fileImportPathConfiguration1;
GeneralUtility::mkdir_deep($fileImportPath1);

$fileImportPathConfiguration2 = 'staedte/anderestadt/events/';
$fileImportPath2 = $this->getInstancePath() . '/fileadmin/' . $fileImportPathConfiguration2;
GeneralUtility::mkdir_deep($fileImportPath2);
Expand Down Expand Up @@ -78,7 +74,7 @@ public function importsConfiguration(): void
);
$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsAllConfigurationTest.csv');

$importedFiles = GeneralUtility::getFilesInDir($fileImportPath1);
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
Expand All @@ -102,10 +98,6 @@ public function importsConfiguration(): void
'Got unexpected number of files'
);

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public function importsExampleAsExpected(): void
{
$this->setDateAspect(new \DateTimeImmutable('2021-07-13', new \DateTimeZone('Europe/Berlin')));

$fileImportPathConfiguration = 'staedte/beispielstadt/events/';
$fileImportPath = $this->getInstancePath() . '/fileadmin/' . $fileImportPathConfiguration;
GeneralUtility::mkdir_deep($fileImportPath);

$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleImportConfigurationWithCategories.php');
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleRegion.php');
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleCategory.php');
Expand Down Expand Up @@ -62,7 +58,7 @@ public function importsExampleAsExpected(): void
);
$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsExampleAsExpected.csv');

$importedFiles = GeneralUtility::getFilesInDir($fileImportPath);
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
Expand All @@ -74,10 +70,6 @@ public function importsExampleAsExpected(): void
'Got unexpected number of files'
);

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public function addsNewFeatures(): void
$tester = $this->executeCommand();

$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsFeaturesAddsNewFeatures.csv');
self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public function singelDate(): void
$this->executeCommand();

$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsFirstDateOfSingleDate.csv');
self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}

/**
Expand All @@ -47,11 +43,7 @@ public function recurringWeekly(): void
$this->executeCommand();

$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsFirstDateOfRecurringDatesWeekly.csv');
self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}

/**
Expand All @@ -64,10 +56,6 @@ public function recurringDaily(): void
$this->executeCommand();

$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsFirstDateOfRecurringDatesDaily.csv');
self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public function importsConfiguration(): void
{
$this->setDateAspect(new \DateTimeImmutable('2021-07-13', new \DateTimeZone('Europe/Berlin')));

$fileImportPathConfiguration = 'staedte/beispielstadt/events/';
$fileImportPath = $this->getInstancePath() . '/fileadmin/' . $fileImportPathConfiguration;
GeneralUtility::mkdir_deep($fileImportPath);

$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleRegion.php');
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleCategory.php');
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleImportConfiguration.php');
Expand Down Expand Up @@ -62,7 +58,7 @@ public function importsConfiguration(): void
);
$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsExampleAsExpected.csv');

$importedFiles = GeneralUtility::getFilesInDir($fileImportPath);
$importedFiles = GeneralUtility::getFilesInDir($this->fileImportPath);
self::assertIsArray($importedFiles, 'Failed to retrieve imported files from filesystem.');
self::assertSame(
[
Expand All @@ -74,10 +70,6 @@ public function importsConfiguration(): void
'Got unexpected number of files'
);

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Wrm\Events\Tests\Functional\Import\DestinationDataTest;

use GuzzleHttp\Psr7\Response;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* @testdox DestinationData import
Expand All @@ -17,10 +16,6 @@ class ImportsTicketsTest extends AbstractTest
*/
public function importsExampleAsExpected(): void
{
$fileImportPathConfiguration = 'staedte/beispielstadt/events/';
$fileImportPath = $this->getInstancePath() . '/fileadmin/' . $fileImportPathConfiguration;
GeneralUtility::mkdir_deep($fileImportPath);

$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/DefaultImportConfiguration.php');
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleRegion.php');
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/SingleCategory.php');
Expand All @@ -46,10 +41,6 @@ public function importsExampleAsExpected(): void

$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsTickets.csv');

self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
$this->assertEmptyLog();
}
}
Loading