Fix broken test handling for log files (#113)

This commit is contained in:
Daniel Siepmann 2023-08-30 12:06:52 +02:00 committed by GitHub
parent 8663d5a759
commit 1a0ba50125
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 8 deletions

View file

@ -30,6 +30,10 @@ Fixes
Those are handled the same way, the entity is skipped and errors are logged. Those are handled the same way, the entity is skipped and errors are logged.
That way further entities can be imported while only none working entities are skipped. That way further entities can be imported while only none working entities are skipped.
* Fix broken check of logged errors within functional tests.
The logging is now adjusted to only log errors.
The file will be checked for each test that does not expect errors to happen.
Tasks Tasks
----- -----

View file

@ -28,6 +28,13 @@ use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
abstract class AbstractImportTest extends FunctionalTestCase abstract class AbstractImportTest extends FunctionalTestCase
{ {
/**
* Whether to expect errors to be logged.
* Will check for no errors if set to false.
* @var bool
*/
protected $expectErrors = false;
protected function setUp(): void protected function setUp(): void
{ {
$this->coreExtensionsToLoad = array_merge($this->coreExtensionsToLoad, [ $this->coreExtensionsToLoad = array_merge($this->coreExtensionsToLoad, [
@ -49,9 +56,9 @@ abstract class AbstractImportTest extends FunctionalTestCase
'LOG' => [ 'LOG' => [
'WerkraumMedia' => [ 'WerkraumMedia' => [
'writerConfiguration' => [ 'writerConfiguration' => [
\TYPO3\CMS\Core\Log\LogLevel::DEBUG => [ \TYPO3\CMS\Core\Log\LogLevel::ERROR => [
\TYPO3\CMS\Core\Log\Writer\FileWriter::class => [ \TYPO3\CMS\Core\Log\Writer\FileWriter::class => [
'logFileInfix' => 'debug', 'logFileInfix' => 'error',
], ],
], ],
], ],
@ -70,23 +77,44 @@ abstract class AbstractImportTest extends FunctionalTestCase
$this->setUpBackendUserFromFixture(1); $this->setUpBackendUserFromFixture(1);
$GLOBALS['LANG'] = $this->getContainer()->get(LanguageService::class); $GLOBALS['LANG'] = $this->getContainer()->get(LanguageService::class);
foreach ($this->getLogFiles() as $logFile) {
file_put_contents($logFile, '');
}
} }
protected function assertPostConditions(): void protected function assertPostConditions(): void
{ {
$path = self::getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log'; if ($this->expectErrors === true) {
$this->assertSame( return;
'', }
file_get_contents($path),
'The TYPO3 log file contained content while expecting to be empty.' foreach ($this->getLogFiles() as $file) {
); $this->assertSame(
'',
file_get_contents($file),
'The TYPO3 log file "' . $file . '" contained content while expecting to be empty.'
);
}
} }
protected function tearDown(): void protected function tearDown(): void
{ {
$this->expectErrors = false;
unset($GLOBALS['LANG']); unset($GLOBALS['LANG']);
GuzzleClientFaker::tearDown(); GuzzleClientFaker::tearDown();
parent::tearDown(); parent::tearDown();
} }
/**
* @return string[]
*/
private function getLogFiles(): array
{
return [
self::getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
self::getInstancePath() . '/typo3temp/var/log/typo3_error_0493d91d8e.log',
];
}
} }

View file

@ -305,6 +305,7 @@ class ImportTest extends AbstractImportTest
*/ */
public function importsFollowingRecordsInCaseOfAnMappingException(): void public function importsFollowingRecordsInCaseOfAnMappingException(): void
{ {
$this->expectErrors = true;
$this->importDataSet(__DIR__ . '/Fixtures/Import/ImportsFollowingRecordsInCaseOfAnMappingException.xml'); $this->importDataSet(__DIR__ . '/Fixtures/Import/ImportsFollowingRecordsInCaseOfAnMappingException.xml');
GuzzleClientFaker::appendResponseFromFile(__DIR__ . '/Fixtures/Import/Guzzle/thuecat.org/resources/mapping-exception.json'); GuzzleClientFaker::appendResponseFromFile(__DIR__ . '/Fixtures/Import/Guzzle/thuecat.org/resources/mapping-exception.json');
GuzzleClientFaker::appendResponseFromFile(__DIR__ . '/Fixtures/Import/Guzzle/thuecat.org/resources/165868194223-zmqf.json'); GuzzleClientFaker::appendResponseFromFile(__DIR__ . '/Fixtures/Import/Guzzle/thuecat.org/resources/165868194223-zmqf.json');