Commit f846c5e4 authored by crell's avatar crell Committed by Nikita Hovratov
Browse files

[!!!][TASK] Add native types to ExtensionManagementUtility

Also gets rid of some phpstan exceptions.

Resolves: #97374
Related: #97372
Related: #97210
Releases: main
Change-Id: I71083a58013f0747a9969fb15d4462bee0c595d5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74288

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Simon Schaufelberger's avatarSimon Schaufelberger <simonschaufi+typo3@gmail.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Simon Schaufelberger's avatarSimon Schaufelberger <simonschaufi+typo3@gmail.com>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
parent c7dde5f8
...@@ -2250,31 +2250,6 @@ parameters: ...@@ -2250,31 +2250,6 @@ parameters:
count: 1 count: 1
path: ../../typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php path: ../../typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php
-
message: "#^Parameter \\#1 \\$itemArray of static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\ExtensionManagementUtility\\:\\:addPlugin\\(\\) expects array, string given\\.$#"
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
-
message: "#^Parameter \\#1 \\$table of static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\ExtensionManagementUtility\\:\\:addTcaSelectItem\\(\\) expects string, array given\\.$#"
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
-
message: "#^Parameter \\#2 \\$field of static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\ExtensionManagementUtility\\:\\:addTcaSelectItem\\(\\) expects string, array given\\.$#"
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
-
message: "#^Parameter \\#4 \\$relativeToField of static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\ExtensionManagementUtility\\:\\:addTcaSelectItem\\(\\) expects string, array given\\.$#"
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
-
message: "#^Parameter \\#5 \\$relativePosition of static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\ExtensionManagementUtility\\:\\:addTcaSelectItem\\(\\) expects string, array given\\.$#"
count: 1
path: ../../typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php
- -
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNull\\(\\) with string will always evaluate to false\\.$#" message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNull\\(\\) with string will always evaluate to false\\.$#"
count: 1 count: 1
......
...@@ -19,6 +19,7 @@ expectations and existing behavior. ...@@ -19,6 +19,7 @@ expectations and existing behavior.
- :php:`\TYPO3\CMS\Core\Utility\CommandUtility` - :php:`\TYPO3\CMS\Core\Utility\CommandUtility`
- :php:`\TYPO3\CMS\Core\Utility\DebugUtility` - :php:`\TYPO3\CMS\Core\Utility\DebugUtility`
- :php:`\TYPO3\CMS\Core\Utility\DiffUtility` - :php:`\TYPO3\CMS\Core\Utility\DiffUtility`
- :php:`\TYPO3\CMS\Core\Utility\ExtensionManagementUtility`
- :php:`\TYPO3\CMS\Core\Utility\MathUtility` - :php:`\TYPO3\CMS\Core\Utility\MathUtility`
- :php:`\TYPO3\CMS\Core\Utility\PathUtility` - :php:`\TYPO3\CMS\Core\Utility\PathUtility`
- :php:`\TYPO3\CMS\Core\Utility\RootlineUtility` - :php:`\TYPO3\CMS\Core\Utility\RootlineUtility`
......
...@@ -17,6 +17,7 @@ declare(strict_types=1); ...@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Tests\Unit\Utility; namespace TYPO3\CMS\Core\Tests\Unit\Utility;
use PHPUnit\Framework\MockObject\MockObject;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
use Psr\EventDispatcher\EventDispatcherInterface; use Psr\EventDispatcher\EventDispatcherInterface;
...@@ -34,31 +35,21 @@ use TYPO3\CMS\Core\Utility\StringUtility; ...@@ -34,31 +35,21 @@ use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/** /**
* Test case * @covers \TYPO3\CMS\Core\Utility\ExtensionManagementUtility
*/ */
class ExtensionManagementUtilityTest extends UnitTestCase class ExtensionManagementUtilityTest extends UnitTestCase
{ {
use ProphecyTrait; use ProphecyTrait;
/**
* @var bool Reset singletons created by subject
*/
protected bool $resetSingletonInstances = true; protected bool $resetSingletonInstances = true;
protected ?PackageManager $backUpPackageManager; protected ?PackageManager $backUpPackageManager;
/**
* Set up
*/
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->backUpPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager(); $this->backUpPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
} }
/**
* Tear down
*/
protected function tearDown(): void protected function tearDown(): void
{ {
ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backUpPackageManager); ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backUpPackageManager);
...@@ -66,12 +57,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -66,12 +57,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
parent::tearDown(); parent::tearDown();
} }
/** protected function createMockPackageManagerWithMockPackage(string $packageKey, array $packageMethods = ['getPackagePath', 'getPackageKey']): MockObject&PackageManager
* @param string $packageKey
* @param array $packageMethods
* @return PackageManager|\PHPUnit\Framework\MockObject\MockObject
*/
protected function createMockPackageManagerWithMockPackage(string $packageKey, array $packageMethods = ['getPackagePath', 'getPackageKey'])
{ {
$packagePath = Environment::getVarPath() . '/tests/' . $packageKey . '/'; $packagePath = Environment::getVarPath() . '/tests/' . $packageKey . '/';
GeneralUtility::mkdir_deep($packagePath); GeneralUtility::mkdir_deep($packagePath);
...@@ -180,7 +166,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -180,7 +166,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
* @param string $table name of the table, must not be empty * @param string $table name of the table, must not be empty
* @return array generated TCA for the given table, will not be empty * @return array generated TCA for the given table, will not be empty
*/ */
private function generateTCAForTable($table): array private function generateTCAForTable(string $table): array
{ {
$tca = []; $tca = [];
$tca[$table] = []; $tca[$table] = [];
...@@ -204,8 +190,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -204,8 +190,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
/** /**
* Data provider for getClassNamePrefixForExtensionKey. * Data provider for getClassNamePrefixForExtensionKey.
*
* @return array
*/ */
public function extensionKeyDataProvider(): array public function extensionKeyDataProvider(): array
{ {
...@@ -231,8 +215,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -231,8 +215,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
/** /**
* @test * @test
* @param string $extensionName
* @param string $expectedPrefix
* @dataProvider extensionKeyDataProvider * @dataProvider extensionKeyDataProvider
*/ */
public function getClassNamePrefixForExtensionKey(string $extensionName, string $expectedPrefix): void public function getClassNamePrefixForExtensionKey(string $extensionName, string $expectedPrefix): void
...@@ -244,7 +226,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -244,7 +226,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
// Tests concerning addToAllTCAtypes // Tests concerning addToAllTCAtypes
////////////////////////////////////// //////////////////////////////////////
/** /**
* Tests whether fields can be add to all TCA types and duplicate fields are considered. * Tests whether fields can be added to all TCA types and duplicate fields are considered.
* *
* @test * @test
* @see ExtensionManagementUtility::addToAllTCAtypes() * @see ExtensionManagementUtility::addToAllTCAtypes()
...@@ -261,7 +243,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -261,7 +243,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
} }
/** /**
* Tests whether fields can be add to all TCA types and duplicate fields are considered. * Tests whether fields can be added to all TCA types and duplicate fields are considered.
* *
* @test * @test
* @see ExtensionManagementUtility::addToAllTCAtypes() * @see ExtensionManagementUtility::addToAllTCAtypes()
...@@ -278,7 +260,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -278,7 +260,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
} }
/** /**
* Tests whether fields can be add to all TCA types and duplicate fields are considered. * Tests whether fields can be added to all TCA types and duplicate fields are considered.
* *
* @test * @test
* @see ExtensionManagementUtility::addToAllTCAtypes() * @see ExtensionManagementUtility::addToAllTCAtypes()
...@@ -294,7 +276,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -294,7 +276,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
} }
/** /**
* Tests whether fields can be add to all TCA types and fields in pallets are respected. * Tests whether fields can be added to all TCA types and fields in pallets are respected.
* *
* @test * @test
* @see ExtensionManagementUtility::addToAllTCAtypes() * @see ExtensionManagementUtility::addToAllTCAtypes()
...@@ -309,7 +291,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -309,7 +291,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
} }
/** /**
* Tests whether fields can be add to a TCA type before existing ones * Tests whether fields can be added to a TCA type before existing ones
* *
* @test * @test
* @see ExtensionManagementUtility::addToAllTCAtypes() * @see ExtensionManagementUtility::addToAllTCAtypes()
...@@ -326,7 +308,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -326,7 +308,7 @@ class ExtensionManagementUtilityTest extends UnitTestCase
} }
/** /**
* Tests whether fields can be add to a TCA type after existing ones * Tests whether fields can be added to a TCA type after existing ones
* *
* @test * @test
* @see ExtensionManagementUtility::addToAllTCAtypes() * @see ExtensionManagementUtility::addToAllTCAtypes()
...@@ -435,9 +417,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -435,9 +417,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
self::assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']); self::assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
} }
/**
* @return array
*/
public function removeDuplicatesForInsertionRemovesDuplicatesDataProvider(): array public function removeDuplicatesForInsertionRemovesDuplicatesDataProvider(): array
{ {
return [ return [
...@@ -983,7 +962,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -983,7 +962,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
/** /**
* Data provider for executePositionedStringInsertionTrimsCorrectCharacters * Data provider for executePositionedStringInsertionTrimsCorrectCharacters
* @return array
*/ */
public function executePositionedStringInsertionTrimsCorrectCharactersDataProvider(): array public function executePositionedStringInsertionTrimsCorrectCharactersDataProvider(): array
{ {
...@@ -1029,49 +1007,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -1029,49 +1007,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
///////////////////////////////////////// /////////////////////////////////////////
// Tests concerning addTcaSelectItem // Tests concerning addTcaSelectItem
///////////////////////////////////////// /////////////////////////////////////////
/**
* @test
*/
public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1303236963);
ExtensionManagementUtility::addTcaSelectItem([], 'foo', []);
}
/**
* @test
*/
public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1303236964);
ExtensionManagementUtility::addTcaSelectItem('foo', [], []);
}
/**
* @test
*/
public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1303236965);
ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', [], []);
}
/**
* @test
*/
public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1303236966);
ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', [], 'foo', []);
}
/** /**
* @test * @test
...@@ -1550,32 +1485,17 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -1550,32 +1485,17 @@ class ExtensionManagementUtilityTest extends UnitTestCase
///////////////////////////////////////// /////////////////////////////////////////
// Tests concerning getExtensionVersion // Tests concerning getExtensionVersion
///////////////////////////////////////// /////////////////////////////////////////
/**
* Data provider for negative getExtensionVersion() tests.
*
* @return array
*/
public function getExtensionVersionFaultyDataProvider(): array
{
return [
[''],
[0],
[new \stdClass()],
[true],
];
}
/** /**
* @test * @test
* @dataProvider getExtensionVersionFaultyDataProvider
* @throws \TYPO3\CMS\Core\Package\Exception * @throws \TYPO3\CMS\Core\Package\Exception
*/ */
public function getExtensionVersionForFaultyExtensionKeyThrowsException(mixed $key): void public function getExtensionVersionForEmptyExtensionKeyThrowsException(): void
{ {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1294586096); $this->expectExceptionCode(1294586096);
ExtensionManagementUtility::getExtensionVersion($key); ExtensionManagementUtility::getExtensionVersion('');
} }
/** /**
...@@ -1696,17 +1616,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -1696,17 +1616,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
self::assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']); self::assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
} }
/**
* @test
*/
public function addPluginThrowsExceptionForMissingExtkey(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionCode(1404068038);
ExtensionManagementUtility::addPlugin('test');
}
public function addTcaSelectItemGroupAddsGroupDataProvider(): array public function addTcaSelectItemGroupAddsGroupDataProvider(): array
{ {
return [ return [
...@@ -1805,11 +1714,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase ...@@ -1805,11 +1714,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
/** /**
* @test * @test
* @param string $groupId
* @param string $groupLabel
* @param string $position
* @param array|null $existingGroups
* @param array $expectedGroups
* @dataProvider addTcaSelectItemGroupAddsGroupDataProvider * @dataProvider addTcaSelectItemGroupAddsGroupDataProvider
*/ */
public function addTcaSelectItemGroupAddsGroup(string $groupId, string $groupLabel, ?string $position, ?array $existingGroups, array $expectedGroups): void public function addTcaSelectItemGroupAddsGroup(string $groupId, string $groupLabel, ?string $position, ?array $existingGroups, array $expectedGroups): void
......
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