From 79c01f891a2cf1b43fab6e00ddbcdf1e7084ae23 Mon Sep 17 00:00:00 2001 From: Nikita Hovratov <nikita.h@live.de> Date: Sat, 12 Nov 2022 19:36:42 +0100 Subject: [PATCH] [TASK] Replace prophecy in EXT:core/Tests/Unit/Imaging/* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: #98755 Resolves: #98756 Releases: main Change-Id: If8484ba37f25cceb7a2d35dfc22717d95c122716 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76576 Tested-by: core-ci <typo3@b13.com> Tested-by: Oliver Klee <typo3-coding@oliverklee.de> Tested-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Stefan Bürk <stefan@buerk.tech> --- .../Tests/Unit/Imaging/IconRegistryTest.php | 57 ++++++------------- .../core/Tests/Unit/Imaging/IconTest.php | 21 ++----- 2 files changed, 23 insertions(+), 55 deletions(-) diff --git a/typo3/sysext/core/Tests/Unit/Imaging/IconRegistryTest.php b/typo3/sysext/core/Tests/Unit/Imaging/IconRegistryTest.php index 397f4330f108..ac51c291ebe1 100644 --- a/typo3/sysext/core/Tests/Unit/Imaging/IconRegistryTest.php +++ b/typo3/sysext/core/Tests/Unit/Imaging/IconRegistryTest.php @@ -17,10 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Unit\Imaging; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; -use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; +use TYPO3\CMS\Core\Cache\Frontend\NullFrontend; use TYPO3\CMS\Core\Exception; use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider; use TYPO3\CMS\Core\Imaging\IconProviderInterface; @@ -30,30 +27,12 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class IconRegistryTest extends UnitTestCase { - use ProphecyTrait; - - /** - * @var string - */ - protected string $notRegisteredIconIdentifier = 'my-super-unregistered-identifier'; - - /** @var ObjectProphecy<FrontendInterface> */ - protected ObjectProphecy $cacheFrontendProphecy; - - public function setUp(): void - { - parent::setUp(); - $this->cacheFrontendProphecy = $this->prophesize(FrontendInterface::class); - $this->cacheFrontendProphecy->get(Argument::cetera())->willReturn(false); - $this->cacheFrontendProphecy->set(Argument::cetera())->willReturn(null); - } - /** * @test */ public function getDefaultIconIdentifierReturnsTheCorrectDefaultIconIdentifierString(): void { - $result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getDefaultIconIdentifier(); + $result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getDefaultIconIdentifier(); self::assertEquals('default-not-found', $result); } @@ -62,7 +41,7 @@ class IconRegistryTest extends UnitTestCase */ public function isRegisteredReturnsTrueForRegisteredIcon(): void { - $subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'); + $subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons'); $result = $subject->isRegistered($subject->getDefaultIconIdentifier()); self::assertTrue($result); } @@ -72,7 +51,7 @@ class IconRegistryTest extends UnitTestCase */ public function isRegisteredReturnsFalseForNotRegisteredIcon(): void { - $result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->isRegistered($this->notRegisteredIconIdentifier); + $result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->isRegistered('my-super-unregistered-identifier'); self::assertFalse($result); } @@ -82,7 +61,7 @@ class IconRegistryTest extends UnitTestCase public function registerIconAddNewIconToRegistry(): void { $unregisteredIcon = 'foo-bar-unregistered'; - $subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'); + $subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons'); self::assertFalse($subject->isRegistered($unregisteredIcon)); $subject->registerIcon($unregisteredIcon, BitmapIconProvider::class, [ 'name' => 'pencil', @@ -99,7 +78,7 @@ class IconRegistryTest extends UnitTestCase $this->expectException(\InvalidArgumentException::class); $this->expectExceptionCode(1437425803); - (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->registerIcon($this->notRegisteredIconIdentifier, GeneralUtility::class); + (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->registerIcon('my-super-unregistered-identifier', GeneralUtility::class); } /** @@ -110,7 +89,7 @@ class IconRegistryTest extends UnitTestCase $this->expectException(Exception::class); $this->expectExceptionCode(1437425804); - (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconConfigurationByIdentifier($this->notRegisteredIconIdentifier); + (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconConfigurationByIdentifier('my-super-unregistered-identifier'); } /** @@ -118,7 +97,7 @@ class IconRegistryTest extends UnitTestCase */ public function getIconConfigurationByIdentifierReturnsCorrectConfiguration(): void { - $result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconConfigurationByIdentifier('default-not-found'); + $result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconConfigurationByIdentifier('default-not-found'); // result must contain at least provider and options array self::assertArrayHasKey('provider', $result); self::assertArrayHasKey('options', $result); @@ -131,7 +110,7 @@ class IconRegistryTest extends UnitTestCase */ public function getAllRegisteredIconIdentifiersReturnsAnArrayWithIconIdentifiers(): void { - self::assertIsArray((new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getAllRegisteredIconIdentifiers()); + self::assertIsArray((new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getAllRegisteredIconIdentifiers()); } /** @@ -139,7 +118,7 @@ class IconRegistryTest extends UnitTestCase */ public function getAllRegisteredIconIdentifiersReturnsArrayWithAllRegisteredIconIdentifiers(): void { - $result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getAllRegisteredIconIdentifiers(); + $result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getAllRegisteredIconIdentifiers(); self::assertIsArray($result); self::assertContains('default-not-found', $result); } @@ -149,7 +128,7 @@ class IconRegistryTest extends UnitTestCase */ public function getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForEmptyFileExtension(): void { - $result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconIdentifierForFileExtension(''); + $result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconIdentifierForFileExtension(''); self::assertEquals('mimetypes-other-other', $result); } @@ -158,7 +137,7 @@ class IconRegistryTest extends UnitTestCase */ public function getIconIdentifierForFileExtensionReturnsDefaultIconIdentifierForUnknownFileExtension(): void { - $result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconIdentifierForFileExtension('xyz'); + $result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconIdentifierForFileExtension('xyz'); self::assertEquals('mimetypes-other-other', $result); } @@ -167,7 +146,7 @@ class IconRegistryTest extends UnitTestCase */ public function getIconIdentifierForFileExtensionReturnsImageIconIdentifierForImageFileExtension(): void { - $result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconIdentifierForFileExtension('jpg'); + $result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconIdentifierForFileExtension('jpg'); self::assertEquals('mimetypes-media-image', $result); } @@ -176,7 +155,7 @@ class IconRegistryTest extends UnitTestCase */ public function registerFileExtensionRegisterAnIcon(): void { - $subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'); + $subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons'); $subject->registerFileExtension('abc', 'xyz'); $result = $subject->getIconIdentifierForFileExtension('abc'); self::assertEquals('xyz', $result); @@ -187,7 +166,7 @@ class IconRegistryTest extends UnitTestCase */ public function registerFileExtensionOverwriteAnExistingIcon(): void { - $subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'); + $subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons'); $subject->registerFileExtension('jpg', 'xyz'); $result = $subject->getIconIdentifierForFileExtension('jpg'); self::assertEquals('xyz', $result); @@ -198,7 +177,7 @@ class IconRegistryTest extends UnitTestCase */ public function registerMimeTypeIconRegisterAnIcon(): void { - $subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'); + $subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons'); $subject->registerMimeTypeIcon('foo/bar', 'mimetype-foo-bar'); $result = $subject->getIconIdentifierForMimeType('foo/bar'); self::assertEquals('mimetype-foo-bar', $result); @@ -209,7 +188,7 @@ class IconRegistryTest extends UnitTestCase */ public function registerMimeTypeIconOverwriteAnExistingIcon(): void { - $subject = new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'); + $subject = new IconRegistry(new NullFrontend('test'), 'BackendIcons'); $subject->registerMimeTypeIcon('video/*', 'mimetype-foo-bar'); $result = $subject->getIconIdentifierForMimeType('video/*'); self::assertEquals('mimetype-foo-bar', $result); @@ -220,7 +199,7 @@ class IconRegistryTest extends UnitTestCase */ public function getIconIdentifierForMimeTypeWithUnknownMimeTypeReturnNull(): void { - $result = (new IconRegistry($this->cacheFrontendProphecy->reveal(), 'BackendIcons'))->getIconIdentifierForMimeType('bar/foo'); + $result = (new IconRegistry(new NullFrontend('test'), 'BackendIcons'))->getIconIdentifierForMimeType('bar/foo'); self::assertNull($result); } } diff --git a/typo3/sysext/core/Tests/Unit/Imaging/IconTest.php b/typo3/sysext/core/Tests/Unit/Imaging/IconTest.php index d9c68daa45d8..c369b29707b3 100644 --- a/typo3/sysext/core/Tests/Unit/Imaging/IconTest.php +++ b/typo3/sysext/core/Tests/Unit/Imaging/IconTest.php @@ -17,11 +17,9 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Unit\Imaging; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Psr\Container\ContainerInterface; -use Psr\EventDispatcher\EventDispatcherInterface; -use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; +use TYPO3\CMS\Core\Cache\Frontend\NullFrontend; +use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Imaging\IconRegistry; @@ -30,25 +28,16 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class IconTest extends UnitTestCase { - use ProphecyTrait; - protected ?Icon $subject; protected string $iconIdentifier = 'actions-close'; protected string $overlayIdentifier = 'overlay-readonly'; - /** - * Set up - */ protected function setUp(): void { parent::setUp(); - $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class); - $cacheFrontendProphecy->get(Argument::cetera())->willReturn(false); - $cacheFrontendProphecy->set(Argument::cetera())->willReturn(null); - $eventDispatcherProphecy = $this->prophesize(EventDispatcherInterface::class); - $containerProphecy = $this->prophesize(ContainerInterface::class); - $containerProphecy->has(Argument::cetera())->willReturn(false); - $iconFactory = new IconFactory($eventDispatcherProphecy->reveal(), new IconRegistry($cacheFrontendProphecy->reveal(), 'BackendIcons'), $containerProphecy->reveal()); + $containerMock = $this->createMock(ContainerInterface::class); + $containerMock->method('has')->with(self::anything())->willReturn(false); + $iconFactory = new IconFactory(new NoopEventDispatcher(), new IconRegistry(new NullFrontend('test'), 'BackendIcons'), $containerMock); $this->subject = $iconFactory->getIcon($this->iconIdentifier, Icon::SIZE_SMALL, $this->overlayIdentifier, IconState::cast(IconState::STATE_DISABLED)); } -- GitLab