Commit 896e629a authored by Benni Mack's avatar Benni Mack Committed by Oliver Hader
Browse files

[BUGFIX] Avoid PHP notices in unit tests

When commenting out the line

  SystemEnvironmentBuilder::initializeBasicErrorReporting()

then Unit Tests run with notices, showing notices as errors.

This happened due to recent updates of the TYPO3 testing framework v6.

The fix to overcome this is https://review.typo3.org/c/Packages/TYPO3.CMS/+/62926
but the preferred clean ups are done beforehand.

Resolves: #90245
Releases: master
Change-Id: Ieb43f2f9524fb18c221b9c690de7116c994f5260
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63068


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
parent e1fc3208
......@@ -103,7 +103,7 @@ class EmailLoginNotification
{
return sprintf(
'User "%s" logged in from %s at "%s" (%s)',
$user['username'],
$user['username'] ?? 'unknown',
$ipAddress,
$siteName,
$httpHost
......
......@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Http;
use Prophecy\Argument;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Http\RouteDispatcher;
use TYPO3\CMS\Backend\Routing\Route;
......@@ -52,7 +51,6 @@ class RouteDispatcherTest extends UnitTestCase
FormProtectionFactory::set('default', $formProtectionProphecy->reveal());
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$responseProphecy = $this->prophesize(ResponseInterface::class);
$routerProphecy = $this->prophesize(Router::class);
GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
$routeProphecy = $this->prophesize(Route::class);
......@@ -72,7 +70,7 @@ class RouteDispatcherTest extends UnitTestCase
$this->expectExceptionCode(1425381442);
$subject = new RouteDispatcher($containerProphecy->reveal());
$subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
$subject->dispatch($requestProphecy->reveal());
}
/**
......@@ -85,7 +83,6 @@ class RouteDispatcherTest extends UnitTestCase
FormProtectionFactory::set('default', $formProtectionProphecy->reveal());
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$responseProphecy = $this->prophesize(ResponseInterface::class);
$routerProphecy = $this->prophesize(Router::class);
GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
$routeProphecy = $this->prophesize(Route::class);
......@@ -98,7 +95,7 @@ class RouteDispatcherTest extends UnitTestCase
$containerProphecy->has(Argument::any())->willReturn(false);
$target = [
RouteDispatcherClassFixture::class,
new RouteDispatcherClassFixture(),
'mainAction'
];
$routeProphecy->getOption('target')->willReturn($target);
......@@ -108,7 +105,7 @@ class RouteDispatcherTest extends UnitTestCase
$this->expectExceptionCode(1520756142);
$subject = new RouteDispatcher($containerProphecy->reveal());
$subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
$subject->dispatch($requestProphecy->reveal());
}
/**
......@@ -121,7 +118,6 @@ class RouteDispatcherTest extends UnitTestCase
FormProtectionFactory::set('default', $formProtectionProphecy->reveal());
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$responseProphecy = $this->prophesize(ResponseInterface::class);
$routerProphecy = $this->prophesize(Router::class);
GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
$routeProphecy = $this->prophesize(Route::class);
......@@ -143,7 +139,7 @@ class RouteDispatcherTest extends UnitTestCase
$this->expectExceptionCode(1520756466);
$subject = new RouteDispatcher($containerProphecy->reveal());
$subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
$subject->dispatch($requestProphecy->reveal());
}
/**
......@@ -156,7 +152,6 @@ class RouteDispatcherTest extends UnitTestCase
FormProtectionFactory::set('default', $formProtectionProphecy->reveal());
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$responseProphecy = $this->prophesize(ResponseInterface::class);
$routerProphecy = $this->prophesize(Router::class);
GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
$routeProphecy = $this->prophesize(Route::class);
......@@ -176,7 +171,7 @@ class RouteDispatcherTest extends UnitTestCase
$this->expectExceptionCode(1520756623);
$subject = new RouteDispatcher($containerProphecy->reveal());
$subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
$subject->dispatch($requestProphecy->reveal());
}
/**
......@@ -189,7 +184,6 @@ class RouteDispatcherTest extends UnitTestCase
FormProtectionFactory::set('default', $formProtectionProphecy->reveal());
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$responseProphecy = $this->prophesize(ResponseInterface::class);
$routerProphecy = $this->prophesize(Router::class);
GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
$routeProphecy = $this->prophesize(Route::class);
......@@ -210,7 +204,7 @@ class RouteDispatcherTest extends UnitTestCase
$this->expectExceptionCode(1520756623);
$subject = new RouteDispatcher($containerProphecy->reveal());
$subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
$subject->dispatch($requestProphecy->reveal());
}
/**
......@@ -223,7 +217,6 @@ class RouteDispatcherTest extends UnitTestCase
FormProtectionFactory::set('default', $formProtectionProphecy->reveal());
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$responseProphecy = $this->prophesize(ResponseInterface::class);
$routerProphecy = $this->prophesize(Router::class);
GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
$routeProphecy = $this->prophesize(Route::class);
......@@ -243,7 +236,7 @@ class RouteDispatcherTest extends UnitTestCase
$this->expectExceptionCode(1442431631);
$subject = new RouteDispatcher($containerProphecy->reveal());
$subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
$subject->dispatch($requestProphecy->reveal());
}
/**
......@@ -256,7 +249,6 @@ class RouteDispatcherTest extends UnitTestCase
FormProtectionFactory::set('default', $formProtectionProphecy->reveal());
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$responseProphecy = $this->prophesize(ResponseInterface::class);
$routerProphecy = $this->prophesize(Router::class);
GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
$routeProphecy = $this->prophesize(Route::class);
......@@ -276,7 +268,7 @@ class RouteDispatcherTest extends UnitTestCase
$this->expectExceptionCode(1520756142);
$subject = new RouteDispatcher($containerProphecy->reveal());
$subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
$subject->dispatch($requestProphecy->reveal());
}
/**
......@@ -289,7 +281,6 @@ class RouteDispatcherTest extends UnitTestCase
FormProtectionFactory::set('default', $formProtectionProphecy->reveal());
$requestProphecy = $this->prophesize(ServerRequestInterface::class);
$responseProphecy = $this->prophesize(ResponseInterface::class);
$routerProphecy = $this->prophesize(Router::class);
GeneralUtility::setSingletonInstance(Router::class, $routerProphecy->reveal());
$routeProphecy = $this->prophesize(Route::class);
......@@ -309,6 +300,6 @@ class RouteDispatcherTest extends UnitTestCase
$this->expectExceptionCode(1520757000);
$subject = new RouteDispatcher($containerProphecy->reveal());
$subject->dispatch($requestProphecy->reveal(), $responseProphecy->reveal());
$subject->dispatch($requestProphecy->reveal());
}
}
......@@ -37,7 +37,7 @@ class Typo3Information
{
if ($languageService) {
$this->languageService = $languageService;
} elseif ($GLOBALS['LANG'] instanceof LanguageService) {
} elseif (($GLOBALS['LANG'] ?? null) instanceof LanguageService) {
$this->languageService = $GLOBALS['LANG'];
} else {
$this->languageService = LanguageService::create('default');
......
......@@ -239,7 +239,7 @@ class PageRouter implements RouterInterface
$page = $pageRepository->getPage($pageId, true);
$pagePath = $page['slug'] ?? '';
if ($parameters['MP'] ?? false) {
if ($parameters['MP'] ?? '') {
$mountPointPairs = explode(',', $parameters['MP']);
$pagePath = $this->resolveMountPointParameterIntoPageSlug(
$pageId,
......@@ -511,7 +511,7 @@ class PageRouter implements RouterInterface
$pageId = (int)($page['l10n_parent'] > 0 ? $page['l10n_parent'] : $page['uid']);
$type = $this->resolveType($route, $remainingQueryParameters);
// See PageSlugCandidateProvider where this is added.
if ($page['MPvar']) {
if ($page['MPvar'] ?? '') {
$routeArguments['MP'] = $page['MPvar'];
}
return new PageArguments($pageId, $type, $routeArguments, [], $remainingQueryParameters);
......
......@@ -304,7 +304,7 @@ class LegacyLinkNotationConverterTest extends UnitTestCase
$parameters['folder'] = substr($parameters['folder'], 5);
}
// fake "0" storage
if (!MathUtility::canBeInterpretedAsInteger($parameters['folder']{0})) {
if (!MathUtility::canBeInterpretedAsInteger($parameters['folder'][0])) {
$parameters['folder'] = '0:' . $parameters['folder'];
}
$folderObject = $this->getMockBuilder(Folder::class)
......
......@@ -486,11 +486,15 @@ class ResourceStorageTest extends BaseTestCase
$folderStub = new Folder($this->subject, '/foo/', 'foo');
$resourceFactory->createFolderObject(Argument::cetera())->willReturn($folderStub);
$fileStub = new File(['identifier' => '/foo/bar.jpg'], $this->subject);
$fileStub = new File(['identifier' => '/foo/bar.jpg', 'name' => 'bar.jpg'], $this->subject);
$driverMock->expects(self::once())
->method('isWithin')
->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
->willReturn(true);
$driverMock->expects(self::once())
->method('getFolderInfoByIdentifier')
->with($folderStub->getIdentifier())
->willReturn(['identifier' => $folderStub->getIdentifier(), 'name' => $folderStub->getName()]);
$this->subject->setEvaluatePermissions(true);
$this->subject->addFileMount('/foo/', [
......@@ -510,13 +514,17 @@ class ResourceStorageTest extends BaseTestCase
$resourceFactory = $this->prophesize(ResourceFactory::class);
$this->prepareSubject([], false, $driverMock, $resourceFactory->reveal(), [], ['isWithinProcessingFolder']);
$fileStub = new File(['identifier' => '/foo/bar.jpg'], $this->subject);
$fileStub = new File(['identifier' => '/foo/bar.jpg', 'name' => 'bar.jpg'], $this->subject);
$folderStub = new Folder($this->subject, '/foo/', 'foo');
$resourceFactory->createFolderObject(Argument::cetera())->willReturn($folderStub);
$driverMock->expects(self::once())
->method('isWithin')
->with($folderStub->getIdentifier(), $fileStub->getIdentifier())
->willReturn(true);
$driverMock->expects(self::once())
->method('getFolderInfoByIdentifier')
->with($folderStub->getIdentifier())
->willReturn(['identifier' => $folderStub->getIdentifier(), 'name' => $folderStub->getName()]);
$this->subject->setEvaluatePermissions(true);
$this->subject->addFileMount('/foo/', [
......
......@@ -92,7 +92,7 @@ class TreeDataProviderFactoryTest extends UnitTestCase
*/
public function factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration, int $expectedExceptionCode): void
{
if ($tcaConfiguration['internal_type'] === 'db' && is_array($tcaConfiguration['treeConfig'] ?? null)) {
if (($tcaConfiguration['internal_type'] ?? '') === 'db' && is_array($tcaConfiguration['treeConfig'] ?? null)) {
$treeDataProvider = $this->prophesize(DatabaseTreeDataProvider::class);
GeneralUtility::addInstance(DatabaseTreeDataProvider::class, $treeDataProvider->reveal());
}
......
......@@ -316,7 +316,10 @@ class ExtensionManagementService implements SingletonInterface
protected function setInExtensionRepository($extensionKey)
{
$paths = Extension::returnInstallPaths();
$path = $paths[$this->downloadUtility->getDownloadPath()];
$path = $paths[$this->downloadUtility->getDownloadPath()] ?? '';
if (empty($path)) {
return;
}
$localExtensionStorage = $path . $extensionKey . '/Initialisation/Extensions/';
$this->dependencyUtility->setLocalExtensionStorage($localExtensionStorage);
}
......
......@@ -57,8 +57,8 @@ class EmConfUtilityTest extends UnitTestCase
],
];
$subject = new EmConfUtility();
$_EXTKEY = 'test';
$result = $subject->constructEmConf(['EM_CONF' => $input]);
$_EXTKEY = 'seminars';
$result = $subject->constructEmConf(['EM_CONF' => $input, 'extKey' => $_EXTKEY]);
eval(substr($result, 7));
$result = $EM_CONF[$_EXTKEY];
self::assertEquals($expected, $result);
......@@ -86,8 +86,8 @@ class EmConfUtilityTest extends UnitTestCase
];
$subject = new EmConfUtility();
$_EXTKEY = 'test';
$result = $subject->constructEmConf(['EM_CONF' => $input]);
$_EXTKEY = 'seminars';
$result = $subject->constructEmConf(['EM_CONF' => $input, 'extKey' => $_EXTKEY]);
eval(substr($result, 7));
$result = $EM_CONF[$_EXTKEY];
self::assertEquals($expected, $result);
......
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