Skip to content

Commit

Permalink
[TASK] Update all code pieces for phpstan within Tests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bmack authored and dkd-kaehm committed May 26, 2023
1 parent f56aa50 commit 355203f
Show file tree
Hide file tree
Showing 22 changed files with 140 additions and 202 deletions.
4 changes: 4 additions & 0 deletions Classes/Domain/Search/Query/AbstractQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ abstract class AbstractQueryBuilder
{
protected SolariumQuery|SearchQuery|SuggestQuery|null $queryToBuild;

/**
* @return static
*/
public function startFrom(SolariumQuery $query): self
{
$this->queryToBuild = $query;
Expand Down Expand Up @@ -256,6 +259,7 @@ public function useReturnFields(ReturnFields $returnFields): self

/**
* Can be used to use a specific filter string in the solr query.
* @return static
*/
public function useFilter(string $filterString, string $filterName = ''): self
{
Expand Down
7 changes: 2 additions & 5 deletions Classes/Task/IndexQueueWorkerTaskAdditionalFieldProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct()
* items to index per run when adding or editing a task.
*
* @param array $taskInfo reference to the array containing the info used in the add/edit form
* @param AbstractTask $task when editing, reference to the current task object. Null when adding.
* @param IndexQueueWorkerTask $task when editing, reference to the current task object. Null when adding.
* @param SchedulerModuleController $schedulerModule Reference to the calling object (Scheduler's BE module)
* @return array Array containing all the information pertaining to the additional fields
* The array is multidimensional, keyed to the task class name and each field's id
Expand All @@ -64,7 +64,6 @@ public function getAdditionalFields(
$task,
SchedulerModuleController $schedulerModule
): array {
/* @var IndexQueueWorkerTask $task */
$additionalFields = [];
$siteSelectorField = GeneralUtility::makeInstance(SiteSelectorField::class);

Expand Down Expand Up @@ -146,9 +145,7 @@ public function validateAdditionalFields(
* class matches.
*
* @param array $submittedData array containing the data submitted by the user
* @param AbstractTask|AbstractSolrTask|IndexQueueWorkerTask $task reference to the current task object
*
* @noinspection PhpDocSignatureInspection
* @param IndexQueueWorkerTask $task reference to the current task object
*/
public function saveAdditionalFields(
array $submittedData,
Expand Down
4 changes: 3 additions & 1 deletion Tests/Integration/ContentObject/RelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ protected function getSolrRelation(string $table, int $uid): Relation
$table,
$requestMock
);
return $contentObjectRenderer->getContentObject(Relation::CONTENT_OBJECT_NAME);
/** @var Relation $relation */
$relation = $contentObjectRenderer->getContentObject(Relation::CONTENT_OBJECT_NAME);
return $relation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function tearDown(): void
/**
* @test
*/
public function canGetDocumentById()
public function canGetDocumentById(): void
{
// trigger a search
$this->importCSVDataSet(__DIR__ . '/../../../Controller/Fixtures/indexing_data.csv');
Expand All @@ -73,7 +73,7 @@ public function canGetDocumentById()
/**
* @test
*/
public function canGetVariants()
public function canGetVariants(): void
{
$this->importCSVDataSet(__DIR__ . '/../../../Controller/Fixtures/indexing_data.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/can_get_searchResultSet.csv');
Expand Down Expand Up @@ -121,7 +121,7 @@ public function canGetVariants()
/**
* @test
*/
public function canGetCaseSensitiveVariants()
public function canGetCaseSensitiveVariants(): void
{
$this->importCSVDataSet(__DIR__ . '/../../../Controller/Fixtures/indexing_data.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/can_get_searchResultSet.csv');
Expand Down Expand Up @@ -153,15 +153,13 @@ public function canGetCaseSensitiveVariants()
self::assertSame(3, count($searchResults), 'There should be three results at all');

// We assume that the first result has 6 variants.
/** @var SearchResult $firstResult */
$firstResult = $searchResults[0];
self::assertSame(2, count($firstResult->getVariants()));
self::assertSame('Jane Doe', $firstResult->getAuthor());
self::assertSame(2, $firstResult->getVariantsNumFound());
self::assertSame('Jane Doe', $firstResult->getVariantFieldValue());

// We assume that the second result has 5 variants.
/** @var SearchResult $secondResult */
$secondResult = $searchResults[1];
self::assertSame(5, count($secondResult->getVariants()));
self::assertSame('John Doe', $secondResult->getAuthor());
Expand Down Expand Up @@ -191,7 +189,7 @@ public function canGetCaseSensitiveVariants()
/**
* @test
*/
public function canGetZeroResultsWithVariantsOnEmptyIndex()
public function canGetZeroResultsWithVariantsOnEmptyIndex(): void
{
$this->importCSVDataSet(__DIR__ . '/../../../Controller/Fixtures/indexing_data.csv');
$this->importCSVDataSet(__DIR__ . '/Fixtures/can_get_searchResultSet.csv');
Expand All @@ -215,7 +213,7 @@ public function canGetZeroResultsWithVariantsOnEmptyIndex()
/**
* @test
*/
public function cantGetHiddenElementWithoutPermissions()
public function cantGetHiddenElementWithoutPermissions(): void
{
$this->importFrontendRestrictedPageScenario();

Expand All @@ -231,7 +229,7 @@ public function cantGetHiddenElementWithoutPermissions()
/**
* @test
*/
public function canGetHiddenElementWithPermissions()
public function canGetHiddenElementWithPermissions(): void
{
$this->importFrontendRestrictedPageScenario();

Expand All @@ -247,7 +245,7 @@ public function canGetHiddenElementWithPermissions()
/**
* Imports a simple page with user restricted content
*/
protected function importFrontendRestrictedPageScenario()
protected function importFrontendRestrictedPageScenario(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/fe_user_page.csv');
$this->addSimpleFrontendRenderingToTypoScriptRendering(1);
Expand Down
19 changes: 7 additions & 12 deletions Tests/Unit/Controller/Backend/Search/AbstractModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,8 @@ abstract class AbstractModuleController extends SetUpUnitTestCase
*/
protected $controller;

/**
* @var Site|MockObject
*/
protected $selectedSiteMock;

/**
* @var ConnectionManager|MockObject
*/
protected $connectionManagerMock;
protected Site|MockObject $selectedSiteMock;
protected ConnectionManager|MockObject $connectionManagerMock;

/**
* Initializes the concrete backend module controller
Expand All @@ -53,7 +46,8 @@ protected function setUpConcreteModuleController(
array $mockMethods = ['addFlashMessage']
): void {
$this->selectedSiteMock = $this->createMock(Site::class);
$this->controller = $this->getMockBuilder($concreteModuleControllerClass)
/** @var ModuleController|MockObject $subject */
$subject = $this->getMockBuilder($concreteModuleControllerClass)
->setConstructorArgs(
[
'moduleTemplateFactory' => $this->createMock(ModuleTemplateFactory::class),
Expand All @@ -73,7 +67,8 @@ protected function setUpConcreteModuleController(
$uriBuilderMock->expects(self::any())
->method('uriFor')
->willReturn('index');
$this->controller->injectUriBuilder($uriBuilderMock);
$this->controller->setSelectedSite($this->selectedSiteMock);
$subject->injectUriBuilder($uriBuilderMock);
$subject->setSelectedSite($this->selectedSiteMock);
$this->controller = $subject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace ApacheSolrForTypo3\Solr\Tests\Unit\Controller\Backend\Search;

use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\Controller\Backend\Search\IndexAdministrationModuleController;
use ApacheSolrForTypo3\Solr\System\Solr\ResponseAdapter;
use ApacheSolrForTypo3\Solr\System\Solr\Service\SolrAdminService;
Expand All @@ -31,9 +30,9 @@
class IndexAdministrationModuleControllerTest extends AbstractModuleController
{
/**
* @var ConnectionManager|MockObject
* @var IndexAdministrationModuleController|MockObject
*/
protected $connectionManagerMock;
protected $controller;

protected function setUp(): void
{
Expand All @@ -44,7 +43,7 @@ protected function setUp(): void
/**
* @test
*/
public function testReloadIndexConfigurationAction()
public function testReloadIndexConfigurationAction(): void
{
$responseMock = $this->createMock(ResponseAdapter::class);
$responseMock->expects(self::once())->method('getHttpStatus')->willReturn(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\AccessibleProxyTrait;
use TYPO3\TestingFramework\Core\AccessibleObjectInterface;

/**
* Abstract strategy tests
*/
abstract class AbstractStrategyTest extends SetUpUnitTestCase
{
/**
* @var AbstractStrategy|AccessibleProxyTrait $subject
*/
protected AbstractStrategy $subject;
protected AbstractStrategy|AccessibleObjectInterface $subject;

protected function tearDown(): void
{
Expand All @@ -41,9 +38,6 @@ protected function tearDown(): void
}

/**
* @param int $status
* @param bool $commit
*
* @test
* @dataProvider canDeleteRecordInAllSolrConnectionsDataProvider
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
*/
class DelayedProcessingEventListenerTest extends SetUpEventListener
{
/**
* @var DelayedProcessingEventListener
*/
protected AbstractBaseEventListener $listener;

/**
* @test
*/
Expand Down Expand Up @@ -86,20 +91,13 @@ public function canSkipEventHandlingIfDisabled(): void
$this->listener->__invoke($event);
}

/**
* Init listener
*
* @return AbstractBaseEventListener
*/
protected function initListener(): AbstractBaseEventListener
protected function initListener(): DelayedProcessingEventListener
{
return new DelayedProcessingEventListener($this->extensionConfigurationMock, $this->eventDispatcherMock);
}

/**
* Returns the current monitoring type
*
* @return int
*/
protected function getMonitoringType(): int
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Index\Queue\UpdateHandler\EventListener\Events;

use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\Events\ProcessingFinishedEventInterface;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\RecordUpdatedEvent;
use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase;

Expand All @@ -26,14 +25,14 @@
*/
abstract class SetUpProcessingFinishedEvent extends SetUpUnitTestCase
{
protected const EVENT_CLASS = 'stdClass';
/**
* @test
*/
public function canSetAndReturnProcessedEvent(): void
{
$processedEvent = new RecordUpdatedEvent(123, 'tx_foo_bar');

/** @var ProcessingFinishedEventInterface $event */
$eventClass = static::EVENT_CLASS;
$event = new $eventClass($processedEvent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\RecordUpdatedEvent;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\VersionSwappedEvent;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\GarbageHandler;
use Psr\EventDispatcher\StoppableEventInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -37,6 +38,11 @@
*/
class ImmediateProcessingEventListenerTest extends SetUpEventListener
{
/**
* @var ImmediateProcessingEventListener
*/
protected AbstractBaseEventListener $listener;

protected function setUp(): void
{
if (!class_exists('SolrUnitTestsInvalidDataUpdateEvent')) {
Expand All @@ -49,11 +55,6 @@ protected function setUp(): void
}

/**
* @param string $eventClass
* @param string $handlerClass
* @param array $eventArguments
* @param bool $eventHandled
*
* @test
* @dataProvider canHandleEventsDataProvider
*/
Expand All @@ -74,11 +75,6 @@ public function canHandleEvents(
}

/**
* @param string $eventClass
* @param string $handlerClass
* @param array $eventArguments
* @param bool $eventHandled
*
* @test
* @dataProvider canHandleEventsDataProvider
*/
Expand All @@ -101,9 +97,6 @@ public function canHandleEventsIfHandlingInactiveButForced(

/**
* Checks the event handling
*
* @param DataUpdateEventInterface $event
* @param bool $eventHandled
*/
protected function checkEventHandling(
DataUpdateEventInterface $event,
Expand All @@ -130,15 +123,15 @@ protected function checkEventHandling(
$this->listener->__invoke($event);
if ($eventHandled) {
self::assertTrue($dispatchedEvent instanceof ProcessingFinishedEvent);
self::assertEquals($dispatchedEvent->getDataUpdateEvent(), $event);
self::assertTrue($dispatchedEvent->getDataUpdateEvent()->isPropagationStopped());
/** @var DataUpdateEventInterface|StoppableEventInterface $dataUpdateEvent */
$dataUpdateEvent = $dispatchedEvent->getDataUpdateEvent();
self::assertEquals($dataUpdateEvent, $event);
self::assertTrue($dataUpdateEvent->isPropagationStopped());
}
}

/**
* Data provider for canDispatchEvents
*
* @return array
*/
public function canHandleEventsDataProvider(): array
{
Expand All @@ -154,20 +147,13 @@ public function canHandleEventsDataProvider(): array
];
}

/**
* Init listener
*
* @return AbstractBaseEventListener
*/
protected function initListener(): AbstractBaseEventListener
protected function initListener(): ImmediateProcessingEventListener
{
return new ImmediateProcessingEventListener($this->extensionConfigurationMock, $this->eventDispatcherMock);
}

/**
* Returns the current monitoring type
*
* @return int
*/
protected function getMonitoringType(): int
{
Expand Down
Loading

0 comments on commit 355203f

Please sign in to comment.