diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/AbstractSoftReferenceParserTest.php b/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/AbstractSoftReferenceParserTest.php index 441dfe75dbcced69dedb2ca91836cf4aeda71c75..c6b056a82dc0507527cf73ccabaf9e178cde9be9 100644 --- a/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/AbstractSoftReferenceParserTest.php +++ b/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/AbstractSoftReferenceParserTest.php @@ -17,9 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference; -use Prophecy\PhpUnit\ProphecyTrait; -use Psr\EventDispatcher\EventDispatcherInterface; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; use TYPO3\CMS\Core\DataHandling\SoftReference\EmailSoftReferenceParser; use TYPO3\CMS\Core\DataHandling\SoftReference\ExtensionPathSoftReferenceParser; @@ -30,24 +28,21 @@ use TYPO3\CMS\Core\DataHandling\SoftReference\SubstituteSoftReferenceParser; use TYPO3\CMS\Core\DataHandling\SoftReference\TypolinkSoftReferenceParser; use TYPO3\CMS\Core\DataHandling\SoftReference\TypolinkTagSoftReferenceParser; use TYPO3\CMS\Core\DataHandling\SoftReference\UrlSoftReferenceParser; +use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; abstract class AbstractSoftReferenceParserTest extends UnitTestCase { - use ProphecyTrait; - protected bool $resetSingletonInstances = true; protected function getParserByKey($softrefKey): SoftReferenceParserInterface { - $eventDispatcher = $this->prophesize(EventDispatcherInterface::class); - $runtimeCache = $this->prophesize(FrontendInterface::class); - $logger = $this->prophesize(LoggerInterface::class); + $runtimeCache = $this->createMock(FrontendInterface::class); - $softReferenceParserFactory = new SoftReferenceParserFactory($runtimeCache->reveal(), $logger->reveal()); + $softReferenceParserFactory = new SoftReferenceParserFactory($runtimeCache, new NullLogger()); $softReferenceParserFactory->addParser(new SubstituteSoftReferenceParser(), 'substitute'); $softReferenceParserFactory->addParser(new NotifySoftReferenceParser(), 'notify'); - $softReferenceParserFactory->addParser(new TypolinkSoftReferenceParser($eventDispatcher->reveal()), 'typolink'); + $softReferenceParserFactory->addParser(new TypolinkSoftReferenceParser(new NoopEventDispatcher()), 'typolink'); $softReferenceParserFactory->addParser(new TypolinkTagSoftReferenceParser(), 'typolink_tag'); $softReferenceParserFactory->addParser(new ExtensionPathSoftReferenceParser(), 'ext_fileref'); $softReferenceParserFactory->addParser(new EmailSoftReferenceParser(), 'email'); diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/TypoLinkSoftReferenceParserTest.php b/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/TypoLinkSoftReferenceParserTest.php index c31fc34554847a0b2e3a58c6d4dd078569fddafa..4c52d802eed4683560b3537f2ce9f2609ff88305 100644 --- a/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/TypoLinkSoftReferenceParserTest.php +++ b/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/TypoLinkSoftReferenceParserTest.php @@ -235,19 +235,19 @@ class TypoLinkSoftReferenceParserTest extends AbstractSoftReferenceParserTest */ public function findRefReturnsParsedElementsWithFile(array $softrefConfiguration, array $expectedElement): void { - $fileObject = $this->prophesize(File::class); - $fileObject->getUid()->willReturn(42)->shouldBeCalledTimes(1); + $fileObject = $this->createMock(File::class); + $fileObject->expects(self::once())->method('getUid')->willReturn(42); - $resourceFactory = $this->prophesize(ResourceFactory::class); - $resourceFactory->getFileObject('42')->willReturn($fileObject->reveal()); + $resourceFactory = $this->createMock(ResourceFactory::class); + $resourceFactory->method('getFileObject')->with('42')->willReturn($fileObject); // For `t3://file?identifier=42` handling - $resourceFactory->getFileObjectFromCombinedIdentifier('42')->willReturn($fileObject->reveal()); - // For `file:23` handling - $resourceFactory->retrieveFileOrFolderObject('42')->willReturn($fileObject->reveal()); - // For `fileadmin/download.jpg` handling - $resourceFactory->retrieveFileOrFolderObject('fileadmin/download.jpg')->willReturn($fileObject->reveal()); - - GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory->reveal()); + $resourceFactory->method('getFileObjectFromCombinedIdentifier')->with('42')->willReturn($fileObject); + // For `file:42` and `fileadmin/download.jpg` handling + $resourceFactory->method('retrieveFileOrFolderObject')->willReturnMap([ + ['42', $fileObject], + ['fileadmin/download.jpg', $fileObject], + ]); + GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory); $subject = $this->getParserByKey('typolink'); $subject->setParserKey('typolink', $softrefConfiguration); @@ -286,11 +286,12 @@ class TypoLinkSoftReferenceParserTest extends AbstractSoftReferenceParserTest */ public function findRefReturnsNullWithFolder(array $softrefConfiguration): void { - $folderObject = $this->prophesize(Folder::class); + $folderObject = $this->createMock(Folder::class); - $resourceFactory = $this->prophesize(ResourceFactory::class); - $resourceFactory->getFolderObjectFromCombinedIdentifier('1:/foo/bar/baz')->willReturn($folderObject->reveal())->shouldBeCalledTimes(1); - GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory->reveal()); + $resourceFactory = $this->createMock(ResourceFactory::class); + $resourceFactory->expects(self::once())->method('getFolderObjectFromCombinedIdentifier') + ->with('1:/foo/bar/baz')->willReturn($folderObject); + GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory); $result = $this->getParserByKey('typolink')->parse( 'tt_content', diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/TypoLinkTagSoftReferenceParserTest.php b/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/TypoLinkTagSoftReferenceParserTest.php index 1afa951176e59fc82faa8716a058a2291bdc3bc8..bba290bc3c541a2c04f5fb4b42b80d7a7e0ff6f5 100644 --- a/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/TypoLinkTagSoftReferenceParserTest.php +++ b/typo3/sysext/core/Tests/Unit/DataHandling/SoftReference/TypoLinkTagSoftReferenceParserTest.php @@ -178,19 +178,17 @@ class TypoLinkTagSoftReferenceParserTest extends AbstractSoftReferenceParserTest */ public function findRefReturnsParsedElementsWithFile(array $softrefConfiguration, array $expectedElement): void { - $fileObject = $this->prophesize(File::class); - $fileObject->getUid()->willReturn(42)->shouldBeCalledTimes(1); + $fileObject = $this->createMock(File::class); + $fileObject->expects(self::once())->method('getUid')->willReturn(42); - $resourceFactory = $this->prophesize(ResourceFactory::class); - $resourceFactory->getFileObject('42')->willReturn($fileObject->reveal()); + $resourceFactory = $this->createMock(ResourceFactory::class); + $resourceFactory->method('getFileObject')->with('42')->willReturn($fileObject); // For `t3://file?identifier=42` handling - $resourceFactory->getFileObjectFromCombinedIdentifier('42')->willReturn($fileObject->reveal()); - // For `file:23` handling - $resourceFactory->retrieveFileOrFolderObject('42')->willReturn($fileObject->reveal()); - // For `fileadmin/download.jpg` handling - $resourceFactory->retrieveFileOrFolderObject('fileadmin/download.jpg')->willReturn($fileObject->reveal()); + $resourceFactory->method('getFileObjectFromCombinedIdentifier')->with('42')->willReturn($fileObject); + // For `file:42` handling + $resourceFactory->method('retrieveFileOrFolderObject')->with('42')->willReturn($fileObject); - GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory->reveal()); + GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory); $subject = $this->getParserByKey('typolink_tag'); $subject->setParserKey('typolink_tag', $softrefConfiguration); @@ -234,11 +232,12 @@ class TypoLinkTagSoftReferenceParserTest extends AbstractSoftReferenceParserTest */ public function findRefReturnsNullWithFolder(array $softrefConfiguration): void { - $folderObject = $this->prophesize(Folder::class); + $folderObject = $this->createMock(Folder::class); - $resourceFactory = $this->prophesize(ResourceFactory::class); - $resourceFactory->getFolderObjectFromCombinedIdentifier('1:/foo/bar/baz')->willReturn($folderObject->reveal())->shouldBeCalledTimes(1); - GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory->reveal()); + $resourceFactory = $this->createMock(ResourceFactory::class); + $resourceFactory->expects(self::once())->method('getFolderObjectFromCombinedIdentifier') + ->with('1:/foo/bar/baz')->willReturn($folderObject); + GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory); $result = $this->getParserByKey('typolink_tag')->parse( 'tt_content',