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: ...@@ -1810,11 +1810,6 @@ parameters:
count: 1 count: 1
path: ../../typo3/sysext/core/Tests/Unit/Log/Fixtures/WriterFixture.php 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\\(\\)\\.$#" message: "#^Call to an undefined method Symfony\\\\Component\\\\Mime\\\\Header\\\\HeaderInterface\\:\\:getAddress\\(\\)\\.$#"
count: 1 count: 1
......
...@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Configuration; ...@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Configuration;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Core\Configuration\ConfigurationManager; use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility; use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
...@@ -41,6 +42,21 @@ class ConfigurationManagerTest extends 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 * @param array $methods
*/ */
...@@ -59,12 +75,11 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -59,12 +75,11 @@ class ConfigurationManagerTest extends UnitTestCase
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);
$this->expectExceptionCode(1310203814); $this->expectExceptionCode(1310203814);
$defaultConfigurationFile = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('defaultConfiguration'); $defaultConfigurationFile = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('defaultConfiguration');
file_put_contents( file_put_contents(
$defaultConfigurationFile, $defaultConfigurationFile,
'<?php throw new \RuntimeException(\'foo\', 1310203814); ?>' '<?php throw new \RuntimeException(\'foo\', 1310203814); ?>'
); );
$this->testFilesToDelete[] = $defaultConfigurationFile;
$this->subject $this->subject
->expects(self::once()) ->expects(self::once())
...@@ -80,12 +95,11 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -80,12 +95,11 @@ class ConfigurationManagerTest extends UnitTestCase
{ {
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);
$configurationFile = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('localConfiguration'); $configurationFile = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('localConfiguration');
file_put_contents( file_put_contents(
$configurationFile, $configurationFile,
'<?php throw new \RuntimeException(\'foo\', 1310203815); ?>' '<?php throw new \RuntimeException(\'foo\', 1310203815); ?>'
); );
$this->testFilesToDelete[] = $configurationFile;
$this->subject $this->subject
->expects(self::once()) ->expects(self::once())
...@@ -378,13 +392,12 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -378,13 +392,12 @@ class ConfigurationManagerTest extends UnitTestCase
$subject = $this->getAccessibleMock(ConfigurationManager::class, ['dummy']); $subject = $this->getAccessibleMock(ConfigurationManager::class, ['dummy']);
$directory = StringUtility::getUniqueId('test_'); $directory = StringUtility::getUniqueId('test_');
$absoluteDirectory = Environment::getVarPath() . '/tests/' . $directory; $absoluteDirectory = $this->getTestDirectory() . '/' . $directory;
mkdir($absoluteDirectory); mkdir($absoluteDirectory);
$file = StringUtility::getUniqueId('test_'); $file = StringUtility::getUniqueId('test_');
$absoluteFile1 = Environment::getVarPath() . '/tests/' . $file; $absoluteFile1 = $absoluteDirectory . '/' . $file;
touch($absoluteFile1); touch($absoluteFile1);
$this->testFilesToDelete[] = $absoluteFile1;
$subject->_set('localConfigurationFile', $absoluteFile1); $subject->_set('localConfigurationFile', $absoluteFile1);
clearstatcache(); clearstatcache();
...@@ -392,7 +405,6 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -392,7 +405,6 @@ class ConfigurationManagerTest extends UnitTestCase
$result = $subject->canWriteConfiguration(); $result = $subject->canWriteConfiguration();
self::assertTrue($result); self::assertTrue($result);
$this->testFilesToDelete[] = $absoluteDirectory;
} }
/** /**
...@@ -400,7 +412,7 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -400,7 +412,7 @@ class ConfigurationManagerTest extends UnitTestCase
*/ */
public function writeLocalConfigurationWritesSortedContentToConfigurationFile(): void public function writeLocalConfigurationWritesSortedContentToConfigurationFile(): void
{ {
$configurationFile = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('localConfiguration'); $configurationFile = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('localConfiguration');
if (!is_file($configurationFile)) { if (!is_file($configurationFile)) {
if (!$fh = fopen($configurationFile, 'wb')) { if (!$fh = fopen($configurationFile, 'wb')) {
self::markTestSkipped('Can not create file ' . $configurationFile . '. Please check your write permissions.'); self::markTestSkipped('Can not create file ' . $configurationFile . '. Please check your write permissions.');
...@@ -414,7 +426,6 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -414,7 +426,6 @@ class ConfigurationManagerTest extends UnitTestCase
1346364362 1346364362
); );
} }
$this->testFilesToDelete[] = $configurationFile;
$this->subject $this->subject
->method('getLocalConfigurationFileLocation') ->method('getLocalConfigurationFileLocation')
...@@ -444,11 +455,10 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -444,11 +455,10 @@ class ConfigurationManagerTest extends UnitTestCase
$subject = $this->getAccessibleMock(ConfigurationManager::class, ['getLocalConfigurationFileLocation']); $subject = $this->getAccessibleMock(ConfigurationManager::class, ['getLocalConfigurationFileLocation']);
$file = 'tests/' . StringUtility::getUniqueId('test_'); $file = StringUtility::getUniqueId('test_');
$absoluteFile = Environment::getVarPath() . '/' . $file; $absoluteFile = $this->getTestDirectory() . '/' . $file;
touch($absoluteFile); touch($absoluteFile);
$subject->method('getLocalConfigurationFileLocation')->willReturn($absoluteFile); $subject->method('getLocalConfigurationFileLocation')->willReturn($absoluteFile);
$this->testFilesToDelete[] = $absoluteFile;
$subject->_set('localConfigurationFile', $file); $subject->_set('localConfigurationFile', $file);
$subject->createLocalConfigurationFromFactoryConfiguration(); $subject->createLocalConfigurationFromFactoryConfiguration();
...@@ -464,8 +474,8 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -464,8 +474,8 @@ class ConfigurationManagerTest extends UnitTestCase
$subject->_set('localConfigurationFile', $localConfigurationFile); $subject->_set('localConfigurationFile', $localConfigurationFile);
$subject->method('getLocalConfigurationFileLocation')->willReturn(Environment::getVarPath() . '/' . $localConfigurationFile); $subject->method('getLocalConfigurationFileLocation')->willReturn(Environment::getVarPath() . '/' . $localConfigurationFile);
$factoryConfigurationFile = 'tests/' . StringUtility::getUniqueId('test_') . '.php'; $factoryConfigurationFile = StringUtility::getUniqueId('test_') . '.php';
$factoryConfigurationAbsoluteFile = Environment::getVarPath() . '/' . $factoryConfigurationFile; $factoryConfigurationAbsoluteFile = $this->getTestDirectory() . '/' . $factoryConfigurationFile;
$subject->method('getFactoryConfigurationFileLocation')->willReturn($factoryConfigurationAbsoluteFile); $subject->method('getFactoryConfigurationFileLocation')->willReturn($factoryConfigurationAbsoluteFile);
$uniqueContentString = StringUtility::getUniqueId('string_'); $uniqueContentString = StringUtility::getUniqueId('string_');
$validFactoryConfigurationFileContent = $validFactoryConfigurationFileContent =
...@@ -477,7 +487,6 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -477,7 +487,6 @@ class ConfigurationManagerTest extends UnitTestCase
$factoryConfigurationAbsoluteFile, $factoryConfigurationAbsoluteFile,
$validFactoryConfigurationFileContent $validFactoryConfigurationFileContent
); );
$this->testFilesToDelete[] = $factoryConfigurationAbsoluteFile;
$subject->_set('factoryConfigurationFile', $factoryConfigurationFile); $subject->_set('factoryConfigurationFile', $factoryConfigurationFile);
...@@ -494,12 +503,13 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -494,12 +503,13 @@ class ConfigurationManagerTest extends UnitTestCase
public function createLocalConfigurationFromFactoryConfigurationMergesConfigurationWithAdditionalFactoryFile(): void public function createLocalConfigurationFromFactoryConfigurationMergesConfigurationWithAdditionalFactoryFile(): void
{ {
$subject = $this->getAccessibleMock(ConfigurationManager::class, ['writeLocalConfiguration', 'getLocalConfigurationFileLocation', 'getFactoryConfigurationFileLocation', 'getAdditionalFactoryConfigurationFileLocation']); $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->_set('localConfigurationFile', $localConfigurationFile);
$subject->method('getLocalConfigurationFileLocation')->willReturn(Environment::getVarPath() . '/' . $localConfigurationFile); $subject->method('getLocalConfigurationFileLocation')->willReturn($localConfigurationFile);
$factoryConfigurationFile = 'tests/' . StringUtility::getUniqueId('test_') . '.php'; $factoryConfigurationFile = StringUtility::getUniqueId('test_') . '.php';
$factoryConfigurationAbsoluteFile = Environment::getVarPath() . '/' . $factoryConfigurationFile; $factoryConfigurationAbsoluteFile = $testDirectory . $factoryConfigurationFile;
$subject->method('getFactoryConfigurationFileLocation')->willReturn($factoryConfigurationAbsoluteFile); $subject->method('getFactoryConfigurationFileLocation')->willReturn($factoryConfigurationAbsoluteFile);
$validFactoryConfigurationFileContent = $validFactoryConfigurationFileContent =
'<?php' . LF . '<?php' . LF .
...@@ -508,11 +518,10 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -508,11 +518,10 @@ class ConfigurationManagerTest extends UnitTestCase
$factoryConfigurationAbsoluteFile, $factoryConfigurationAbsoluteFile,
$validFactoryConfigurationFileContent $validFactoryConfigurationFileContent
); );
$this->testFilesToDelete[] = $factoryConfigurationAbsoluteFile;
$subject->_set('factoryConfigurationFile', $factoryConfigurationFile); $subject->_set('factoryConfigurationFile', $factoryConfigurationFile);
$additionalFactoryConfigurationFile = 'tests/' . StringUtility::getUniqueId('test_') . '.php'; $additionalFactoryConfigurationFile = StringUtility::getUniqueId('test_') . '.php';
$additionalFactoryConfigurationAbsoluteFile = Environment::getVarPath() . '/' . $additionalFactoryConfigurationFile; $additionalFactoryConfigurationAbsoluteFile = $testDirectory . $additionalFactoryConfigurationFile;
$subject->method('getAdditionalFactoryConfigurationFileLocation')->willReturn($additionalFactoryConfigurationAbsoluteFile); $subject->method('getAdditionalFactoryConfigurationFileLocation')->willReturn($additionalFactoryConfigurationAbsoluteFile);
$uniqueContentString = StringUtility::getUniqueId('string_'); $uniqueContentString = StringUtility::getUniqueId('string_');
$validAdditionalFactoryConfigurationFileContent = $validAdditionalFactoryConfigurationFileContent =
...@@ -524,7 +533,6 @@ class ConfigurationManagerTest extends UnitTestCase ...@@ -524,7 +533,6 @@ class ConfigurationManagerTest extends UnitTestCase
$additionalFactoryConfigurationAbsoluteFile, $additionalFactoryConfigurationAbsoluteFile,
$validAdditionalFactoryConfigurationFileContent $validAdditionalFactoryConfigurationFileContent
); );
$this->testFilesToDelete[] = $additionalFactoryConfigurationAbsoluteFile;
$subject->_set('additionalFactoryConfigurationFile', $additionalFactoryConfigurationFile); $subject->_set('additionalFactoryConfigurationFile', $additionalFactoryConfigurationFile);
$subject $subject
......
...@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Http; ...@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Http;
use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\StreamFactoryInterface;
use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\StreamFactory; use TYPO3\CMS\Core\Http\StreamFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility; use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
...@@ -28,6 +29,21 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase; ...@@ -28,6 +29,21 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
*/ */
class StreamFactoryTest extends 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 * @test
*/ */
...@@ -94,7 +110,7 @@ class StreamFactoryTest extends UnitTestCase ...@@ -94,7 +110,7 @@ class StreamFactoryTest extends UnitTestCase
*/ */
public function createStreamFromFile(): void public function createStreamFromFile(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
file_put_contents($fileName, 'Foo'); file_put_contents($fileName, 'Foo');
$factory = new StreamFactory(); $factory = new StreamFactory();
...@@ -107,7 +123,7 @@ class StreamFactoryTest extends UnitTestCase ...@@ -107,7 +123,7 @@ class StreamFactoryTest extends UnitTestCase
*/ */
public function createStreamFromFileWithMode(): void public function createStreamFromFileWithMode(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
$factory = new StreamFactory(); $factory = new StreamFactory();
$stream = $factory->createStreamFromFile($fileName, 'w'); $stream = $factory->createStreamFromFile($fileName, 'w');
...@@ -122,7 +138,7 @@ class StreamFactoryTest extends UnitTestCase ...@@ -122,7 +138,7 @@ class StreamFactoryTest extends UnitTestCase
*/ */
public function createStreamFromFileWithInvalidMode(): void public function createStreamFromFileWithInvalidMode(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName); touch($fileName);
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
...@@ -148,7 +164,7 @@ class StreamFactoryTest extends UnitTestCase ...@@ -148,7 +164,7 @@ class StreamFactoryTest extends UnitTestCase
*/ */
public function createStreamFromResource(): void public function createStreamFromResource(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName); touch($fileName);
file_put_contents($fileName, 'Foo'); file_put_contents($fileName, 'Foo');
......
...@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Http; ...@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Http;
use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\Stream; use TYPO3\CMS\Core\Http\Stream;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility; use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
...@@ -37,6 +38,21 @@ class StreamTest extends UnitTestCase ...@@ -37,6 +38,21 @@ class StreamTest extends UnitTestCase
$this->stream = new Stream('php://memory', 'wb+'); $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 * @test
*/ */
...@@ -60,9 +76,8 @@ class StreamTest extends UnitTestCase ...@@ -60,9 +76,8 @@ class StreamTest extends UnitTestCase
*/ */
public function isReadableReturnsFalseIfStreamIsNotReadable(): void public function isReadableReturnsFalseIfStreamIsNotReadable(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName); touch($fileName);
$this->testFilesToDelete[] = $fileName;
$stream = new Stream($fileName, 'w'); $stream = new Stream($fileName, 'w');
self::assertFalse($stream->isReadable()); self::assertFalse($stream->isReadable());
} }
...@@ -110,9 +125,8 @@ class StreamTest extends UnitTestCase ...@@ -110,9 +125,8 @@ class StreamTest extends UnitTestCase
*/ */
public function toStringSerializationReturnsEmptyStringWhenStreamIsNotReadable(): void public function toStringSerializationReturnsEmptyStringWhenStreamIsNotReadable(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName); touch($fileName);
$this->testFilesToDelete[] = $fileName;
file_put_contents($fileName, 'FOO BAR'); file_put_contents($fileName, 'FOO BAR');
$stream = new Stream($fileName, 'w'); $stream = new Stream($fileName, 'w');
...@@ -124,9 +138,8 @@ class StreamTest extends UnitTestCase ...@@ -124,9 +138,8 @@ class StreamTest extends UnitTestCase
*/ */
public function closeClosesResource(): void public function closeClosesResource(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName); touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
$stream->close(); $stream->close();
...@@ -142,9 +155,8 @@ class StreamTest extends UnitTestCase ...@@ -142,9 +155,8 @@ class StreamTest extends UnitTestCase
*/ */
public function closeUnsetsResource(): void public function closeUnsetsResource(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName); touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
$stream->close(); $stream->close();
...@@ -157,9 +169,8 @@ class StreamTest extends UnitTestCase ...@@ -157,9 +169,8 @@ class StreamTest extends UnitTestCase
*/ */
public function closeDoesNothingAfterDetach(): void public function closeDoesNothingAfterDetach(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
touch($fileName); touch($fileName);
$this->testFilesToDelete[] = $fileName;
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
$detached = $stream->detach(); $detached = $stream->detach();
...@@ -183,8 +194,7 @@ class StreamTest extends UnitTestCase ...@@ -183,8 +194,7 @@ class StreamTest extends UnitTestCase
*/ */
public function tellReportsCurrentPositionInResource(): void public function tellReportsCurrentPositionInResource(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
file_put_contents($fileName, 'FOO BAR'); file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
...@@ -199,8 +209,7 @@ class StreamTest extends UnitTestCase ...@@ -199,8 +209,7 @@ class StreamTest extends UnitTestCase
*/ */
public function tellRaisesExceptionIfResourceIsDetached(): void public function tellRaisesExceptionIfResourceIsDetached(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
file_put_contents($fileName, 'FOO BAR'); file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
...@@ -217,8 +226,7 @@ class StreamTest extends UnitTestCase ...@@ -217,8 +226,7 @@ class StreamTest extends UnitTestCase
*/ */
public function eofReportsFalseWhenNotAtEndOfStream(): void public function eofReportsFalseWhenNotAtEndOfStream(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
file_put_contents($fileName, 'FOO BAR'); file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
...@@ -232,8 +240,7 @@ class StreamTest extends UnitTestCase ...@@ -232,8 +240,7 @@ class StreamTest extends UnitTestCase
*/ */
public function eofReportsTrueWhenAtEndOfStream(): void public function eofReportsTrueWhenAtEndOfStream(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
file_put_contents($fileName, 'FOO BAR'); file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
...@@ -249,8 +256,7 @@ class StreamTest extends UnitTestCase ...@@ -249,8 +256,7 @@ class StreamTest extends UnitTestCase
*/ */
public function eofReportsTrueWhenStreamIsDetached(): void public function eofReportsTrueWhenStreamIsDetached(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
file_put_contents($fileName, 'FOO BAR'); file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
...@@ -265,8 +271,7 @@ class StreamTest extends UnitTestCase ...@@ -265,8 +271,7 @@ class StreamTest extends UnitTestCase
*/ */
public function isSeekableReturnsTrueForReadableStreams(): void public function isSeekableReturnsTrueForReadableStreams(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
file_put_contents($fileName, 'FOO BAR'); file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
...@@ -278,8 +283,7 @@ class StreamTest extends UnitTestCase ...@@ -278,8 +283,7 @@ class StreamTest extends UnitTestCase
*/ */
public function isSeekableReturnsFalseForDetachedStreams(): void public function isSeekableReturnsFalseForDetachedStreams(): void
{ {
$fileName = Environment::getVarPath() . '/tests/' . StringUtility::getUniqueId('test_'); $fileName = $this->getTestDirectory() . '/' . StringUtility::getUniqueId('test_');
$this->testFilesToDelete[] = $fileName;
file_put_contents($fileName, 'FOO BAR'); file_put_contents($fileName, 'FOO BAR');
$resource = fopen($fileName, 'wb+'); $resource = fopen($fileName, 'wb+');
$stream = new Stream($resource); $stream = new Stream($resource);
...@@ -292,8 +296,7 @@ class StreamTest extends UnitTestCase ...@@ -292,8 +296,7 @@ class StreamTest extends UnitTestCase
*/ */
public function seekAdvancesToGivenOffsetOfStream(): void