Skip to content

Commit

Permalink
[TASK] Use Attributes for PHPUnit tests
Browse files Browse the repository at this point in the history
This change utilizes PHP8 attributes, which
is possible since PHPUnit 10, and the only way
to define Tests and DataProviders in PHPUnit 11.

Done via rector:

    return RectorConfig::configure()
        ->withSets([
            PHPUnitSetList::PHPUNIT_100,
        ])
        ->withImportNames();

Fixes: #4047
  • Loading branch information
bmack authored and dkd-kaehm committed May 16, 2024
1 parent 7844e6b commit 5a05d76
Show file tree
Hide file tree
Showing 199 changed files with 1,376 additions and 3,070 deletions.
5 changes: 2 additions & 3 deletions Tests/Integration/Access/RootlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

use ApacheSolrForTypo3\Solr\Access\Rootline;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTestBase;
use PHPUnit\Framework\Attributes\Test;

/**
* Class RootlineTest
*/
class RootlineTest extends IntegrationTestBase
{
/**
* @test
*/
#[Test]
public function canGetAccessRootlineByPageId()
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/user_protected_page.csv');
Expand Down
5 changes: 2 additions & 3 deletions Tests/Integration/Backend/SettingsPreviewOnPluginsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ApacheSolrForTypo3\Solr\Backend\SettingsPreviewOnPlugins;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTestBase;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent;
use TYPO3\CMS\Backend\View\PageLayoutContext;
Expand Down Expand Up @@ -62,9 +63,7 @@ protected function setUp(): void
$GLOBALS['LANG'] = $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->create('default');
}

/**
* @test
*/
#[Test]
public function printsPreviewOnExtSolrPluginsCorrectly()
{
$settingsPreviewOnPlugins = new SettingsPreviewOnPlugins(
Expand Down
21 changes: 9 additions & 12 deletions Tests/Integration/ConnectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Traversable;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -58,10 +60,9 @@ public static function canFindSolrConnectionsByRootPageIdDataProvider(): Travers
* ——[ 1] First site
* |
* ——[111] Second site
*
* @test
* @dataProvider canFindSolrConnectionsByRootPageIdDataProvider
*/
#[DataProvider('canFindSolrConnectionsByRootPageIdDataProvider')]
#[Test]
public function canFindSolrConnectionsByRootPageId(int $rootPageId, string $siteName, string $expectedSolrHost): void
{
$this->mergeSiteConfiguration($siteName, ['solr_host_read' => $expectedSolrHost]);
Expand Down Expand Up @@ -103,10 +104,9 @@ public static function canFindSolrConnectionsByPageIdDataProvider(): Traversable
* —— [31] Subpage 1 of Detached
* |
* —— [32] Subpage 2 of Detached
*
* @test
* @dataProvider canFindSolrConnectionsByPageIdDataProvider
*/
#[DataProvider('canFindSolrConnectionsByPageIdDataProvider')]
#[Test]
public function canFindSolrConnectionsByPageId(int $pageId, string $siteName, string $expectedSolrHost): void
{
$this->mergeSiteConfiguration($siteName, ['solr_host_read' => $expectedSolrHost]);
Expand Down Expand Up @@ -157,9 +157,8 @@ protected function setupNotFullyConfiguredSite(): void
* [0]
* |
* ——[ 3] Detached and non Root Page-Tree
*
* @test
*/
#[Test]
public function exceptionIsThrownForUnAvailableSolrConnectionOnGetConnectionByRootPageId()
{
$this->setupNotFullyConfiguredSite();
Expand All @@ -183,9 +182,8 @@ public function exceptionIsThrownForUnAvailableSolrConnectionOnGetConnectionByRo
* —— [31] Subpage 1 of Detached
* |
* —— [32] Subpage 2 of Detached
*
* @test
*/
#[Test]
public function exceptionIsThrownForUnAvailableSolrConnectionOnGetConnectionByPageId()
{
$this->setupNotFullyConfiguredSite();
Expand All @@ -212,9 +210,8 @@ public function exceptionIsThrownForUnAvailableSolrConnectionOnGetConnectionByPa
* ——[ 1] Page (Root)
* |
* ——[14] Mount Point 1 (to [24] to show contents from)
*
* @test
*/
#[Test]
public function canFindSolrConnectionForMountedPageIfMountPointIsGiven()
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/connection_for_mounted_page.csv');
Expand Down
26 changes: 10 additions & 16 deletions Tests/Integration/ContentObject/RelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

use ApacheSolrForTypo3\Solr\ContentObject\Relation;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTestBase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use Traversable;
use TYPO3\CMS\Backend\Utility\BackendUtility;
Expand All @@ -37,10 +39,8 @@ class RelationTest extends IntegrationTestBase
'../vendor/apache-solr-for-typo3/solr/Tests/Integration/Fixtures/Extensions/fake_extension',
];

/**
* @test
* @dataProvider fixturesProviderForFallbackToPagesTableIfPagesLanguageOverlayTCAHasNoDefinitionForLocalColumn
*/
#[DataProvider('fixturesProviderForFallbackToPagesTableIfPagesLanguageOverlayTCAHasNoDefinitionForLocalColumn')]
#[Test]
public function canFallbackToPagesTableIfPagesLanguageOverlayTCAHasNoDefinitionForLocalColumn(string $fixtureName): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/' . $fixtureName);
Expand All @@ -61,10 +61,8 @@ public static function fixturesProviderForFallbackToPagesTableIfPagesLanguageOve
=> ['solr_relation_can_get_related_items_using_original_uid_if_sys_lang_overlay_has_no_tca.csv'];
}

/**
* @test
* @dataProvider canResolveOneToOneRelationDataProvider
*/
#[DataProvider('canResolveOneToOneRelationDataProvider')]
#[Test]
public function canResolveOneToOneRelation(string $expected, array $config): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/solr_relation_can_resolve_one_to_one_relations.csv');
Expand Down Expand Up @@ -109,10 +107,8 @@ public static function canResolveOneToOneRelationDataProvider(): Traversable
];
}

/**
* @test
* @dataProvider canResolveMToNRelationDataProvider
*/
#[DataProvider('canResolveMToNRelationDataProvider')]
#[Test]
public function canResolveMToNRelation(string $expected, string $table, int $recordUid, array $config): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/solr_relation_can_resolve_m_to_n_relations.csv');
Expand Down Expand Up @@ -219,10 +215,8 @@ public static function canResolveMToNRelationDataProvider(): Traversable
];
}

/**
* @test
* @dataProvider canResolveOneToNRelationDataProvider
*/
#[DataProvider('canResolveOneToNRelationDataProvider')]
#[Test]
public function canResolveOneToNRelation(string $expected, string $table, int $recordUid, array $config): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/solr_relation_can_resolve_one_to_n_relations.csv');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use ApacheSolrForTypo3\Solr\System\Mvc\Backend\Service\ModuleDataStorageService;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTestBase;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Imaging\IconFactory;
Expand Down Expand Up @@ -68,9 +69,7 @@ protected function getControllerMockObject(): IndexAdministrationModuleControlle
return $controller;
}

/**
* @test
*/
#[Test]
public function testReloadIndexConfigurationAction()
{
/** @var SiteRepository $siteRepository */
Expand All @@ -84,9 +83,7 @@ public function testReloadIndexConfigurationAction()
$controller->reloadIndexConfigurationAction();
}

/**
* @test
*/
#[Test]
public function testEmptyIndexAction()
{
/** @var SiteRepository $siteRepository */
Expand Down
Loading

0 comments on commit 5a05d76

Please sign in to comment.