Commit 0f894ddd authored by Łukasz Uznański's avatar Łukasz Uznański Committed by Christian Kuhn
Browse files

[TASK] Make FileWriterTest notice free

Resolves: #84438
Releases: master
Change-Id: Iaa3fb4b63b4d71cd5cee03a67d0255c839bb9c05
Reviewed-on: https://review.typo3.org/56313


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent c9846fdf
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Core\Tests\Unit\Log\Writer;
/*
......@@ -16,17 +17,18 @@ namespace TYPO3\CMS\Core\Tests\Unit\Log\Writer;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamWrapper;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Log\LogRecord;
use TYPO3\CMS\Core\Log\Writer\FileWriter;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
* Test case
*/
class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
class FileWriterTest extends UnitTestCase
{
/**
* Subject is not notice free, disable E_NOTICES
*/
protected static $suppressNotices = true;
/**
* @var string
*/
......@@ -37,7 +39,7 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
*/
protected $logFileName = 'test.log';
protected function setUpVfsStream()
protected function setUpVfsStream(): void
{
if (!class_exists('org\\bovigo\\vfs\\vfsStream')) {
$this->markTestSkipped('File backend tests are not available with this phpunit version.');
......@@ -50,16 +52,16 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
*
* @param string $name
* @internal param string $component Component key
* @return \TYPO3\CMS\Core\Log\Logger
* @return Logger
*/
protected function createLogger($name = '')
protected function createLogger($name = ''): Logger
{
if (empty($name)) {
$name = $this->getUniqueId('test.core.log.');
}
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->registerLogger($name);
/** @var \TYPO3\CMS\Core\Log\Logger $logger */
$logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger($name);
GeneralUtility::makeInstance(LogManager::class)->registerLogger($name);
/** @var Logger $logger */
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger($name);
return $logger;
}
......@@ -67,18 +69,18 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
* Creates a file writer
*
* @param string $prependName
* @return \TYPO3\CMS\Core\Log\Writer\FileWriter
* @return FileWriter
*/
protected function createWriter($prependName = '')
protected function createWriter($prependName = ''): FileWriter
{
/** @var \TYPO3\CMS\Core\Log\Writer\FileWriter $writer */
$writer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\Writer\FileWriter::class, [
/** @var FileWriter $writer */
$writer = GeneralUtility::makeInstance(FileWriter::class, [
'logFile' => $this->getDefaultFileName($prependName)
]);
return $writer;
}
protected function getDefaultFileName($prependName = '')
protected function getDefaultFileName($prependName = ''): string
{
return 'vfs://LogRoot/' . $this->logFileDirectory . '/' . $prependName . $this->logFileName;
}
......@@ -86,11 +88,11 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
/**
* @test
*/
public function setLogFileSetsLogFile()
public function setLogFileSetsLogFile(): void
{
$this->setUpVfsStream();
vfsStream::newFile($this->logFileName)->at(vfsStreamWrapper::getRoot());
$writer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\Writer\FileWriter::class);
$writer = GeneralUtility::makeInstance(FileWriter::class);
$writer->setLogFile($this->getDefaultFileName());
$this->assertAttributeEquals($this->getDefaultFileName(), 'logFile', $writer);
}
......@@ -98,9 +100,9 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
/**
* @test
*/
public function setLogFileAcceptsAbsolutePath()
public function setLogFileAcceptsAbsolutePath(): void
{
$writer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\Writer\FileWriter::class);
$writer = GeneralUtility::makeInstance(FileWriter::class);
$tempFile = rtrim(sys_get_temp_dir(), '/\\') . '/typo3.log';
$writer->setLogFile($tempFile);
$this->assertAttributeEquals($tempFile, 'logFile', $writer);
......@@ -109,7 +111,7 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
/**
* @test
*/
public function createsLogFileDirectory()
public function createsLogFileDirectory(): void
{
$this->setUpVfsStream();
$this->createWriter();
......@@ -119,7 +121,7 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
/**
* @test
*/
public function createsLogFile()
public function createsLogFile(): void
{
$this->setUpVfsStream();
$this->createWriter();
......@@ -129,10 +131,10 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
/**
* @return array
*/
public function logsToFileDataProvider()
public function logsToFileDataProvider(): array
{
$simpleRecord = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogRecord::class, $this->getUniqueId('test.core.log.fileWriter.simpleRecord.'), \TYPO3\CMS\Core\Log\LogLevel::INFO, 'test record');
$recordWithData = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogRecord::class, $this->getUniqueId('test.core.log.fileWriter.recordWithData.'), \TYPO3\CMS\Core\Log\LogLevel::ALERT, 'test record with data', ['foo' => ['bar' => 'baz']]);
$simpleRecord = GeneralUtility::makeInstance(LogRecord::class, $this->getUniqueId('test.core.log.fileWriter.simpleRecord.'), \TYPO3\CMS\Core\Log\LogLevel::INFO, 'test record');
$recordWithData = GeneralUtility::makeInstance(LogRecord::class, $this->getUniqueId('test.core.log.fileWriter.recordWithData.'), \TYPO3\CMS\Core\Log\LogLevel::ALERT, 'test record with data', ['foo' => ['bar' => 'baz']]);
return [
'simple record' => [$simpleRecord, trim((string)$simpleRecord)],
'record with data' => [$recordWithData, trim((string)$recordWithData)]
......@@ -141,11 +143,11 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
/**
* @test
* @param \TYPO3\CMS\Core\Log\LogRecord $record Record Test Data
* @param LogRecord $record Record Test Data
* @param string $expectedResult Needle
* @dataProvider logsToFileDataProvider
*/
public function logsToFile(\TYPO3\CMS\Core\Log\LogRecord $record, $expectedResult)
public function logsToFile(LogRecord $record, $expectedResult): void
{
$this->setUpVfsStream();
$this->createWriter()->writeLog($record);
......@@ -155,11 +157,11 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
/**
* @test
* @param \TYPO3\CMS\Core\Log\LogRecord $record Record Test Data
* @param LogRecord $record Record Test Data
* @param string $expectedResult Needle
* @dataProvider logsToFileDataProvider
*/
public function differentWritersLogToDifferentFiles(\TYPO3\CMS\Core\Log\LogRecord $record, $expectedResult)
public function differentWritersLogToDifferentFiles(LogRecord $record, $expectedResult): void
{
$this->setUpVfsStream();
$firstWriter = $this->createWriter();
......@@ -182,10 +184,10 @@ class FileWriterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
{
$this->setUpVfsStream();
$firstWriter = $this->getMockBuilder(\TYPO3\CMS\Core\Log\Writer\FileWriter::class)
$firstWriter = $this->getMockBuilder(FileWriter::class)
->setMethods(['dummy'])
->getMock();
$secondWriter = $this->getMockBuilder(\TYPO3\CMS\Core\Log\Writer\FileWriter::class)
$secondWriter = $this->getMockBuilder(FileWriter::class)
->setMethods(['createLogFile'])
->getMock();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment