Commit 69bf2c66 authored by Anja Leichsenring's avatar Anja Leichsenring Committed by Christian Kuhn
Browse files

[TASK] Reduce VFS usage in unit tests - Part 1

The component causes errors every once in a while and does not
provide a huge benefit anymore.
This part contains the low hanging fruits, the harder cases will
be tackled in other parts.

Resolves: #97762
Releases: main
Change-Id: I36d59cbf3514c13cceacf8de4bebf577b2389f59
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74882


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent d1023c9e
......@@ -1810,11 +1810,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Log/Fixtures/WriterFixture.php
-
message: "#^Call to an undefined method org\\\\bovigo\\\\vfs\\\\vfsStreamContent\\:\\:hasChild\\(\\)\\.$#"
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php
-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Mime\\\\Header\\\\HeaderInterface\\:\\:getAddress\\(\\)\\.$#"
count: 1
......
......@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Configuration;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
......@@ -41,6 +42,21 @@ class ConfigurationManagerTest extends UnitTestCase
);
}
/**
* Helper method to create a random directory and return the path.
* The path will be registered for deletion upon test ending
*
* @param string $prefix
* @return string
*/
protected function getTestDirectory(string $prefix = 'root_'): string
{
$path = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId($prefix);
GeneralUtility::mkdir_deep($path);
$this->testFilesToDelete[] = $path;
return $path;
}
/**
* @param array $methods
*/
......@@ -59,12 +75,11 @@ class ConfigurationManagerTest extends UnitTestCase
$this->expectException(\RuntimeException::class);
$this->expectExceptionCode(1310203814);
$defaultConfigurationFile = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('defaultConfiguration');
$defaultConfigurationFile = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('defaultConfiguration');
file_put_contents(
$defaultConfigurationFile,
'<?php throw new \RuntimeException(\'foo\', 1310203814); ?>'
);
$this->testFilesToDelete[] = $defaultConfigurationFile;
$this->subject
->expects(self::once())
......@@ -80,12 +95,11 @@ class ConfigurationManagerTest extends UnitTestCase
{
$this->expectException(\RuntimeException::class);
$configurationFile = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('localConfiguration');
$configurationFile = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('localConfiguration');
file_put_contents(
$configurationFile,
'<?php throw new \RuntimeException(\'foo\', 1310203815); ?>'
);
$this->testFilesToDelete[] = $configurationFile;
$this->subject
->expects(self::once())
......@@ -378,13 +392,12 @@ class ConfigurationManagerTest extends UnitTestCase
$subject = $this->getAccessibleMock(ConfigurationManager::class, ['dummy']);
$directory = StringUtility::getUniqueId('test_');
$absoluteDirectory = Environment::getVarPath() . '/tests/' . $directory;
$absoluteDirectory = $this->getTestDirectory() . '/' . $directory;
mkdir($absoluteDirectory);
$file = StringUtility::getUniqueId('test_');
$absoluteFile1 = Environment::getVarPath() . '/tests/' . $file;
$absoluteFile1 = $absoluteDirectory . '/' . $file;
touch($absoluteFile1);
$this->testFilesToDelete[] = $absoluteFile1;
$subject->_set('localConfigurationFile', $absoluteFile1);
clearstatcache();
......@@ -392,7 +405,6 @@ class ConfigurationManagerTest extends UnitTestCase
$result = $subject->canWriteConfiguration();
self::assertTrue($result);
$this->testFilesToDelete[] = $absoluteDirectory;
}
/**
......@@ -400,7 +412,7 @@ class ConfigurationManagerTest extends UnitTestCase
*/
public function writeLocalConfigurationWritesSortedContentToConfigurationFile(): void
{
$configurationFile = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('localConfiguration');
$configurationFile = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('localConfiguration');
if (!is_file($configurationFile)) {
if (!$fh = fopen($configurationFile, 'wb')) {
self::markTestSkipped('Can not create file ' . $configurationFile . '. Please check your write permissions.');
......@@ -414,7 +426,6 @@ class ConfigurationManagerTest extends UnitTestCase
1346364362
);
}
$this->testFilesToDelete[] = $configurationFile;
$this->subject
->method('getLocalConfigurationFileLocation')
......@@ -444,11 +455,10 @@ class ConfigurationManagerTest extends UnitTestCase
$subject = $this->getAccessibleMock(ConfigurationManager::class, ['getLocalConfigurationFileLocation']);
$file = 'tests/' . StringUtility::getUniqueId('test_');
$absoluteFile = Environment::getVarPath() . '/' . $file;
$file = StringUtility::getUniqueId('test_');
$absoluteFile = $this->getTestDirectory() . '/' . $file;
touch($absoluteFile);
$subject->method('getLocalConfigurationFileLocation')->willReturn($absoluteFile);
$this->testFilesToDelete[] = $absoluteFile;
$subject->_set('localConfigurationFile', $file);
$subject->createLocalConfigurationFromFactoryConfiguration();
......@@ -464,8 +474,8 @@ class ConfigurationManagerTest extends UnitTestCase
$subject->_set('localConfigurationFile', $localConfigurationFile);
$subject->method('getLocalConfigurationFileLocation')->willReturn(Environment::getVarPath() . '/' . $localConfigurationFile);
$factoryConfigurationFile = 'tests/' . StringUtility::getUniqueId('test_') . '.php';
$factoryConfigurationAbsoluteFile = Environment::getVarPath() . '/' . $factoryConfigurationFile;
$factoryConfigurationFile = StringUtility::getUniqueId('test_') . '.php';
$factoryConfigurationAbsoluteFile = $this->getTestDirectory() . '/' . $factoryConfigurationFile;
$subject->method('getFactoryConfigurationFileLocation')->willReturn($factoryConfigurationAbsoluteFile);
$uniqueContentString = StringUtility::getUniqueId('string_');
$validFactoryConfigurationFileContent =
......@@ -477,7 +487,6 @@ class ConfigurationManagerTest extends UnitTestCase
$factoryConfigurationAbsoluteFile,
$validFactoryConfigurationFileContent
);
$this->testFilesToDelete[] = $factoryConfigurationAbsoluteFile;
$subject->_set('factoryConfigurationFile', $factoryConfigurationFile);
......@@ -494,12 +503,13 @@ class ConfigurationManagerTest extends UnitTestCase
public function createLocalConfigurationFromFactoryConfigurationMergesConfigurationWithAdditionalFactoryFile(): void
{
$subject = $this->getAccessibleMock(ConfigurationManager::class, ['writeLocalConfiguration', 'getLocalConfigurationFileLocation', 'getFactoryConfigurationFileLocation', 'getAdditionalFactoryConfigurationFileLocation']);
$localConfigurationFile = '/tests/' . StringUtility::getUniqueId('dummy_');
$testDirectory = $this->getTestDirectory() . '/';
$localConfigurationFile = $testDirectory . StringUtility::getUniqueId('dummy_');
$subject->_set('localConfigurationFile', $localConfigurationFile);
$subject->method('getLocalConfigurationFileLocation')->willReturn(Environment::getVarPath() . '/' . $localConfigurationFile);
$subject->method('getLocalConfigurationFileLocation')->willReturn($localConfigurationFile);
$factoryConfigurationFile = 'tests/' . StringUtility::getUniqueId('test_') . '.php';
$factoryConfigurationAbsoluteFile = Environment::getVarPath() . '/' . $factoryConfigurationFile;
$factoryConfigurationFile = StringUtility::getUniqueId('test_') . '.php';
$factoryConfigurationAbsoluteFile = $testDirectory . $factoryConfigurationFile;
$subject->method('getFactoryConfigurationFileLocation')->willReturn($factoryConfigurationAbsoluteFile);
$validFactoryConfigurationFileContent =
'<?php' . LF .
......@@ -508,11 +518,10 @@ class ConfigurationManagerTest extends UnitTestCase
$factoryConfigurationAbsoluteFile,
$validFactoryConfigurationFileContent
);
$this->testFilesToDelete[] = $factoryConfigurationAbsoluteFile;
$subject->_set('factoryConfigurationFile', $factoryConfigurationFile);
$additionalFactoryConfigurationFile = 'tests/' . StringUtility::getUniqueId('test_') . '.php';
$additionalFactoryConfigurationAbsoluteFile = Environment::getVarPath() . '/' . $additionalFactoryConfigurationFile;
$additionalFactoryConfigurationFile = StringUtility::getUniqueId('test_') . '.php';
$additionalFactoryConfigurationAbsoluteFile = $testDirectory . $additionalFactoryConfigurationFile;
$subject->method('getAdditionalFactoryConfigurationFileLocation')->willReturn($additionalFactoryConfigurationAbsoluteFile);
$uniqueContentString = StringUtility::getUniqueId('string_');
$validAdditionalFactoryConfigurationFileContent =
......@@ -524,7 +533,6 @@ class ConfigurationManagerTest extends UnitTestCase
$additionalFactoryConfigurationAbsoluteFile,
$validAdditionalFactoryConfigurationFileContent
);
$this->testFilesToDelete[] = $additionalFactoryConfigurationAbsoluteFile;
$subject->_set('additionalFactoryConfigurationFile', $additionalFactoryConfigurationFile);
$subject
......
......@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Http;
use Psr\Http\Message\StreamFactoryInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\StreamFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
......@@ -28,6 +29,21 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
*/
class StreamFactoryTest extends UnitTestCase
{
/**
* Helper method to create a random directory and return the path.
* The path will be registered for deletion upon test ending
*
* @param string $prefix
* @return string
*/
protected function getTestDirectory(string $prefix = 'root_'): string
{
$path = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId($prefix);
GeneralUtility::mkdir_deep($path);
$this->testFilesToDelete[] = $path;
return $path;
}
/**
* @test
*/
......@@ -94,7 +110,7 @@ class StreamFactoryTest extends UnitTestCase
*/
public function createStreamFromFile(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'Foo');
$factory = new StreamFactory();
......@@ -107,7 +123,7 @@ class StreamFactoryTest extends UnitTestCase
*/
public function createStreamFromFileWithMode(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
$factory = new StreamFactory();
$stream = $factory->createStreamFromFile($fileName, 'w');
......@@ -122,7 +138,7 @@ class StreamFactoryTest extends UnitTestCase
*/
public function createStreamFromFileWithInvalidMode(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->expectException(\InvalidArgumentException::class);
......@@ -148,7 +164,7 @@ class StreamFactoryTest extends UnitTestCase
*/
public function createStreamFromResource(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
file_put_contents($fileName, 'Foo');
......
......@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Http;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\Stream;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
......@@ -37,6 +38,21 @@ class StreamTest extends UnitTestCase
$this->stream = new Stream('php://memory', 'wb+');
}
/**
* Helper method to create a random directory and return the path.
* The path will be registered for deletion upon test ending
*
* @param string $prefix
* @return string
*/
protected function getTestDirectory(string $prefix = 'root_'): string
{
$path = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId($prefix);
$this->testFilesToDelete[] = $path;
GeneralUtility::mkdir_deep($path);
return $path;
}
/**
* @test
*/
......@@ -60,9 +76,8 @@ class StreamTest extends UnitTestCase
*/
public function isReadableReturnsFalseIfStreamIsNotReadable(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$stream = new Stream($fileName, 'w');
self::assertFalse($stream->isReadable());
}
......@@ -110,9 +125,8 @@ class StreamTest extends UnitTestCase
*/
public function toStringSerializationReturnsEmptyStringWhenStreamIsNotReadable(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
file_put_contents($fileName, 'FOO BAR');
$stream = new Stream($fileName, 'w');
......@@ -124,9 +138,8 @@ class StreamTest extends UnitTestCase
*/
public function closeClosesResource(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
$stream->close();
......@@ -142,9 +155,8 @@ class StreamTest extends UnitTestCase
*/
public function closeUnsetsResource(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
$stream->close();
......@@ -157,9 +169,8 @@ class StreamTest extends UnitTestCase
*/
public function closeDoesNothingAfterDetach(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
$detached = $stream->detach();
......@@ -183,8 +194,7 @@ class StreamTest extends UnitTestCase
*/
public function tellReportsCurrentPositionInResource(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -199,8 +209,7 @@ class StreamTest extends UnitTestCase
*/
public function tellRaisesExceptionIfResourceIsDetached(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -217,8 +226,7 @@ class StreamTest extends UnitTestCase
*/
public function eofReportsFalseWhenNotAtEndOfStream(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -232,8 +240,7 @@ class StreamTest extends UnitTestCase
*/
public function eofReportsTrueWhenAtEndOfStream(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -249,8 +256,7 @@ class StreamTest extends UnitTestCase
*/
public function eofReportsTrueWhenStreamIsDetached(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -265,8 +271,7 @@ class StreamTest extends UnitTestCase
*/
public function isSeekableReturnsTrueForReadableStreams(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -278,8 +283,7 @@ class StreamTest extends UnitTestCase
*/
public function isSeekableReturnsFalseForDetachedStreams(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -292,8 +296,7 @@ class StreamTest extends UnitTestCase
*/
public function seekAdvancesToGivenOffsetOfStream(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -306,8 +309,7 @@ class StreamTest extends UnitTestCase
*/
public function rewindResetsToStartOfStream(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -321,8 +323,7 @@ class StreamTest extends UnitTestCase
*/
public function seekRaisesExceptionWhenStreamIsDetached(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -337,8 +338,7 @@ class StreamTest extends UnitTestCase
*/
public function isWritableReturnsFalseWhenStreamIsDetached(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -351,8 +351,7 @@ class StreamTest extends UnitTestCase
*/
public function writeRaisesExceptionWhenStreamIsDetached(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -367,8 +366,7 @@ class StreamTest extends UnitTestCase
*/
public function isReadableReturnsFalseWhenStreamIsDetached(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+');
$stream = new Stream($resource);
......@@ -381,8 +379,7 @@ class StreamTest extends UnitTestCase
*/
public function readRaisesExceptionWhenStreamIsDetached(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'r');
$stream = new Stream($resource);
......@@ -397,8 +394,7 @@ class StreamTest extends UnitTestCase
*/
public function readReturnsEmptyStringWhenAtEndOfFile(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'r');
$stream = new Stream($resource);
......@@ -413,8 +409,7 @@ class StreamTest extends UnitTestCase
*/
public function getContentsReturnsEmptyStringIfStreamIsNotReadable(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'w');
$stream = new Stream($resource);
......@@ -466,9 +461,8 @@ class StreamTest extends UnitTestCase
*/
public function attachWithResourceAttachesResource(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'r+');
$this->stream->attach($resource);
......@@ -483,9 +477,8 @@ class StreamTest extends UnitTestCase
*/
public function attachWithStringRepresentingResourceCreatesAndAttachesResource(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$this->stream->attach($fileName);
$resource = fopen($fileName, 'r+');
......@@ -501,9 +494,8 @@ class StreamTest extends UnitTestCase
*/
public function getContentsShouldGetFullStreamContents(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'r+');
$this->stream->attach($resource);
......@@ -520,9 +512,8 @@ class StreamTest extends UnitTestCase
*/
public function getContentsShouldReturnStreamContentsFromCurrentPointer(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'r+');
$this->stream->attach($resource);
......@@ -539,9 +530,8 @@ class StreamTest extends UnitTestCase
*/
public function getMetadataReturnsAllMetadataWhenNoKeyPresent(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'r+');
$this->stream->attach($resource);
......@@ -556,9 +546,8 @@ class StreamTest extends UnitTestCase
*/
public function getMetadataReturnsDataForSpecifiedKey(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'r+');
$this->stream->attach($resource);
......@@ -575,9 +564,8 @@ class StreamTest extends UnitTestCase
*/
public function getMetadataReturnsNullIfNoDataExistsForKey(): void
{
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_');
$fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'r+');
$this->stream->attach($resource);
......
......@@ -17,9 +17,8 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Tests\Unit\Log\Writer;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamWrapper;
use Psr\Log\LogLevel;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Log\LogRecord;
......@@ -35,46 +34,42 @@ class FileWriterTest extends UnitTestCase
{
protected string $logFileDirectory = 'Log';
protected string $logFileName = 'test.log';
protected string $testRoot;
protected function setUpVfsStream(): void
protected function setUp(): void
{
vfsStream::setup('LogRoot');
parent::setUp();
$this->testRoot = Environment::getVarPath() . '/tests/';
GeneralUtility::mkdir_deep($this->testRoot);
$this->testFilesToDelete[] = $this->testRoot;
}
/**
* Creates a test logger
*
* @param string $name
* @return Logger