Skip to content

Commit

Permalink
[TASK] Migrate getMockForAbstractClass() calls in EXT:core
Browse files Browse the repository at this point in the history
`getMockForAbstractClass` has been (soft-)deprecated in PHPUnit 10.1:
sebastianbergmann/phpunit#5241

Hence, we should replace its usages to follow best practices and
avoid deprecation warnings later with PHPUnit 11.

We do this by creating dedicated fixture subclasses of the affected
abstract classes.

Resolves: #101666
Related: #101601
Releases: main, 12.4
Change-Id: I0263ff7b0639d72ba1d4f30e3bee12276d364591
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80946
Tested-by: Benjamin Franzke <ben@bnf.dev>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
  • Loading branch information
oliverklee authored and bnf committed Sep 11, 2023
1 parent c454452 commit 3cc3fe3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Expand Up @@ -18,7 +18,7 @@
namespace TYPO3\CMS\Core\Tests\Unit\Resource\Collection;

use TYPO3\CMS\Core\Resource\Collection\FileCollectionRegistry;
use TYPO3\CMS\Core\Resource\Collection\StaticFileCollection;
use TYPO3\CMS\Core\Tests\Unit\Resource\Collection\Fixtures\OtherTestingFileCollection;
use TYPO3\CMS\Core\Tests\Unit\Resource\Collection\Fixtures\TestingFileCollection;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
Expand Down Expand Up @@ -70,7 +70,7 @@ public function registerFileCollectionClassThrowsExceptionIfTypeIsAlreadyRegiste
$this->expectExceptionCode(1391295643);
$subject = new FileCollectionRegistry();
$className = TestingFileCollection::class;
$className2 = get_class($this->getMockForAbstractClass(StaticFileCollection::class));
$className2 = OtherTestingFileCollection::class;
$subject->registerFileCollectionClass($className, 'foobar');
$subject->registerFileCollectionClass($className2, 'foobar');
}
Expand All @@ -81,7 +81,7 @@ public function registerFileCollectionClassThrowsExceptionIfTypeIsAlreadyRegiste
public function registerFileCollectionClassOverridesExistingRegisteredFileCollectionClass(): void
{
$className = TestingFileCollection::class;
$className2 = get_class($this->getMockForAbstractClass(StaticFileCollection::class));
$className2 = OtherTestingFileCollection::class;
$subject = new FileCollectionRegistry();
$subject->registerFileCollectionClass($className, 'foobar');
$subject->registerFileCollectionClass($className2, 'foobar', true);
Expand Down
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace TYPO3\CMS\Core\Tests\Unit\Resource\Collection\Fixtures;

use TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection;

/**
* Testing subclass of the abstract class.
*
* This class exists because some tests need instances of different file collection classes.
*/
final class OtherTestingFileCollection extends AbstractFileCollection
{
public function loadContents(): void
{
// stub
}
}

0 comments on commit 3cc3fe3

Please sign in to comment.