diff --git a/Tests/Unit/Log/Processor/AbstractMemoryProcessorTest.php b/Tests/Unit/Log/Processor/AbstractMemoryProcessorTest.php index 178b2292d5..5f5f61e6e0 100644 --- a/Tests/Unit/Log/Processor/AbstractMemoryProcessorTest.php +++ b/Tests/Unit/Log/Processor/AbstractMemoryProcessorTest.php @@ -17,7 +17,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Log\Processor; -use TYPO3\CMS\Core\Log\Processor\AbstractMemoryProcessor; +use TYPO3\CMS\Core\Tests\Unit\Log\Processor\Fixtures\TestingMemoryProcessor; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; final class AbstractMemoryProcessorTest extends UnitTestCase @@ -27,7 +27,7 @@ final class AbstractMemoryProcessorTest extends UnitTestCase */ public function setRealMemoryUsageSetsRealMemoryUsage(): void { - $processor = $this->getMockForAbstractClass(AbstractMemoryProcessor::class); + $processor = new TestingMemoryProcessor(); $processor->setRealMemoryUsage(false); self::assertFalse($processor->getRealMemoryUsage()); } @@ -37,7 +37,7 @@ public function setRealMemoryUsageSetsRealMemoryUsage(): void */ public function setFormatSizeSetsFormatSize(): void { - $processor = $this->getMockForAbstractClass(AbstractMemoryProcessor::class); + $processor = new TestingMemoryProcessor(); $processor->setFormatSize(false); self::assertFalse($processor->getFormatSize()); } diff --git a/Tests/Unit/Log/Processor/Fixtures/TestingMemoryProcessor.php b/Tests/Unit/Log/Processor/Fixtures/TestingMemoryProcessor.php new file mode 100644 index 0000000000..0bc37c0b4f --- /dev/null +++ b/Tests/Unit/Log/Processor/Fixtures/TestingMemoryProcessor.php @@ -0,0 +1,32 @@ +createMock(ResourceStorage::class); - $parentFolderFixture = $this->getMockForAbstractClass(AbstractFile::class); - $parentFolderFixture->setIdentifier($parentIdentifier)->setStorage($mockedStorageForParent); + $parentFolderFixture = $this->createMock(FolderInterface::class); + $parentFolderFixture->method('getStorage')->willReturn($mockedStorageForParent); $mockedStorage = $this->getMockBuilder(ResourceStorage::class) ->onlyMethods(['getFolderIdentifierFromFileIdentifier', 'getFolder']) @@ -47,7 +48,7 @@ public function getParentFolderGetsParentFolderFromStorage(): void $mockedStorage->expects(self::once())->method('getFolderIdentifierFromFileIdentifier')->with($currentIdentifier)->willReturn($parentIdentifier); $mockedStorage->expects(self::once())->method('getFolder')->with($parentIdentifier)->willReturn($parentFolderFixture); - $currentFolderFixture = $this->getMockForAbstractClass(AbstractFile::class); + $currentFolderFixture = new TestingFile(); $currentFolderFixture->setIdentifier($currentIdentifier)->setStorage($mockedStorage); self::assertSame($parentFolderFixture, $currentFolderFixture->getParentFolder()); diff --git a/Tests/Unit/Resource/Collection/FileCollectionRegistryTest.php b/Tests/Unit/Resource/Collection/FileCollectionRegistryTest.php index 7075686e5c..2b5739c728 100644 --- a/Tests/Unit/Resource/Collection/FileCollectionRegistryTest.php +++ b/Tests/Unit/Resource/Collection/FileCollectionRegistryTest.php @@ -17,9 +17,9 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource\Collection; -use TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection; use TYPO3\CMS\Core\Resource\Collection\FileCollectionRegistry; use TYPO3\CMS\Core\Resource\Collection\StaticFileCollection; +use TYPO3\CMS\Core\Tests\Unit\Resource\Collection\Fixtures\TestingFileCollection; use TYPO3\CMS\Core\Utility\StringUtility; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; @@ -30,7 +30,7 @@ final class FileCollectionRegistryTest extends UnitTestCase */ public function registeredFileCollectionClassesCanBeRetrieved(): void { - $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class)); + $className = TestingFileCollection::class; $subject = new FileCollectionRegistry(); $subject->registerFileCollectionClass($className, 'foobar'); $returnedClassName = $subject->getFileCollectionClass('foobar'); @@ -56,7 +56,7 @@ public function registerFileCollectionClassThrowsExceptionIfTypeIsTooLong(): voi $this->expectException(\InvalidArgumentException::class); $this->expectExceptionCode(1391295611); $subject = new FileCollectionRegistry(); - $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class)); + $className = TestingFileCollection::class; $type = str_pad('', 40); $subject->registerFileCollectionClass($className, $type); } @@ -69,7 +69,7 @@ public function registerFileCollectionClassThrowsExceptionIfTypeIsAlreadyRegiste $this->expectException(\InvalidArgumentException::class); $this->expectExceptionCode(1391295643); $subject = new FileCollectionRegistry(); - $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class)); + $className = TestingFileCollection::class; $className2 = get_class($this->getMockForAbstractClass(StaticFileCollection::class)); $subject->registerFileCollectionClass($className, 'foobar'); $subject->registerFileCollectionClass($className2, 'foobar'); @@ -80,7 +80,7 @@ public function registerFileCollectionClassThrowsExceptionIfTypeIsAlreadyRegiste */ public function registerFileCollectionClassOverridesExistingRegisteredFileCollectionClass(): void { - $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class)); + $className = TestingFileCollection::class; $className2 = get_class($this->getMockForAbstractClass(StaticFileCollection::class)); $subject = new FileCollectionRegistry(); $subject->registerFileCollectionClass($className, 'foobar'); @@ -103,7 +103,7 @@ public function getFileCollectionClassThrowsExceptionIfClassIsNotRegistered(): v */ public function getFileCollectionClassAcceptsClassNameIfClassIsRegistered(): void { - $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class)); + $className = TestingFileCollection::class; $subject = new FileCollectionRegistry(); $subject->registerFileCollectionClass($className, 'foobar'); self::assertEquals($className, $subject->getFileCollectionClass('foobar')); @@ -114,7 +114,7 @@ public function getFileCollectionClassAcceptsClassNameIfClassIsRegistered(): voi */ public function fileCollectionRegistryIsInitializedWithPreconfiguredFileCollections(): void { - $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class)); + $className = TestingFileCollection::class; $type = substr(StringUtility::getUniqueId('type_'), 0, 30); $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [ $type => $className, @@ -128,7 +128,7 @@ public function fileCollectionRegistryIsInitializedWithPreconfiguredFileCollecti */ public function fileCollectionExistsReturnsTrueForAllExistingFileCollections(): void { - $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class)); + $className = TestingFileCollection::class; $type = 'foo'; $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [ $type => $className, diff --git a/Tests/Unit/Resource/Collection/Fixtures/TestingFileCollection.php b/Tests/Unit/Resource/Collection/Fixtures/TestingFileCollection.php new file mode 100644 index 0000000000..2ac7ddef96 --- /dev/null +++ b/Tests/Unit/Resource/Collection/Fixtures/TestingFileCollection.php @@ -0,0 +1,31 @@ +getMockForAbstractClass(AbstractDriver::class, [], '', false); + $subject = new TestingDriver(); self::assertTrue($subject->isCaseSensitiveFileSystem()); } } diff --git a/Tests/Unit/Resource/Driver/DriverRegistryTest.php b/Tests/Unit/Resource/Driver/DriverRegistryTest.php index 33bd8d0d93..582b4c43fd 100644 --- a/Tests/Unit/Resource/Driver/DriverRegistryTest.php +++ b/Tests/Unit/Resource/Driver/DriverRegistryTest.php @@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Resource\Driver\DriverInterface; use TYPO3\CMS\Core\Resource\Driver\DriverRegistry; +use TYPO3\CMS\Core\Tests\Unit\Resource\Driver\Fixtures\TestingDriver; use TYPO3\CMS\Core\Utility\StringUtility; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; @@ -55,7 +56,7 @@ public function registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAno $this->expectException(\InvalidArgumentException::class); $this->expectExceptionCode(1314979451); $className = get_class($this->createMock(DriverInterface::class)); - $className2 = get_class($this->getMockForAbstractClass(DriverInterface::class)); + $className2 = TestingDriver::class; $subject = new DriverRegistry(); $subject->registerDriverClass($className, 'foobar'); $subject->registerDriverClass($className2, 'foobar'); diff --git a/Tests/Unit/Resource/Driver/Fixtures/TestingDriver.php b/Tests/Unit/Resource/Driver/Fixtures/TestingDriver.php new file mode 100644 index 0000000000..69994323a4 --- /dev/null +++ b/Tests/Unit/Resource/Driver/Fixtures/TestingDriver.php @@ -0,0 +1,280 @@ +expectException(\InvalidArgumentException::class); $this->expectExceptionCode(1316779798); - $subject = $this->getMockForAbstractClass(AbstractRepository::class, [], '', false); + $subject = new TestingRepository(); $subject->findByUid('asdf'); } - - /** - * @test - */ - public function findByUidAcceptsNumericUidInString(): void - { - $statementMock = $this->createMock(Result::class); - $statementMock->expects(self::once())->method('fetchAssociative')->willReturn(['uid' => 123]); - - $queryBuilderMock = $this->createDatabaseMock(); - $queryBuilderMock->expects(self::once())->method('select')->with('*')->willReturn($queryBuilderMock); - $queryBuilderMock->expects(self::once())->method('from')->with('')->willReturn($queryBuilderMock); - $queryBuilderMock->expects(self::once())->method('where')->with(self::anything())->willReturn($queryBuilderMock); - $queryBuilderMock->method('createNamedParameter')->with(self::anything())->willReturnArgument(0); - $queryBuilderMock->expects(self::once())->method('executeQuery')->willReturn($statementMock); - - $subject = $this->getMockForAbstractClass(AbstractRepository::class, [], '', false); - $subject->findByUid('123'); - } } diff --git a/Tests/Unit/Resource/Repository/Fixtures/TestingRepository.php b/Tests/Unit/Resource/Repository/Fixtures/TestingRepository.php new file mode 100644 index 0000000000..362f96bf45 --- /dev/null +++ b/Tests/Unit/Resource/Repository/Fixtures/TestingRepository.php @@ -0,0 +1,36 @@ +subject->method('resolvePageId')->willReturn(42); - - $cacheFrontendMock = $this->getMockForAbstractClass( - AbstractFrontend::class, - [], - '', - false - ); + $cacheFrontend = new NullFrontend('some-frontend'); $context = new Context(); $context->setAspect('workspace', new WorkspaceAspect(15)); $context->setAspect('language', new LanguageAspect(8, 8, LanguageAspect::OVERLAYS_OFF)); - $this->subject->__construct(42, '47-11,48-12', $context); - self::assertTrue($cacheFrontendMock->isValidEntryIdentifier($this->subject->getCacheIdentifier())); + self::assertTrue($cacheFrontend->isValidEntryIdentifier($this->subject->getCacheIdentifier())); } }