Skip to content

Commit

Permalink
[TASK] Fix tests for TYPO3 13 @ 2024.07.02
Browse files Browse the repository at this point in the history
  • Loading branch information
dkd-kaehm committed Jul 2, 2024
1 parent 4c13753 commit 3ef0f20
Show file tree
Hide file tree
Showing 42 changed files with 109 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@

namespace ApacheSolrForTypo3\Solr\Event\Indexing;

use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\System\Solr\Document\Document;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* Allows to add more documents to the Solr index.
*
* Previously used with
* $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments']
*/
class BeforePageDocumentIsProcessedForIndexingEvent extends BeforeDocumentIsProcessedForIndexingEvent
{
}
class BeforePageDocumentIsProcessedForIndexingEvent extends BeforeDocumentIsProcessedForIndexingEvent {}
1 change: 0 additions & 1 deletion Classes/IndexQueue/AbstractIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
Expand Down
1 change: 1 addition & 0 deletions Tests/Integration/Backend/SettingsPreviewOnPluginsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected function getFakePageContentPreviewRenderingEvent(string $table = 'tt_c
{
return new PageContentPreviewRenderingEvent(
$table,
(string)($record[(string)($GLOBALS['TCA'][$table]['ctrl']['type'] ?? '')] ?? ''),
$record,
$this->createMock(PageLayoutContext::class)
);
Expand Down
15 changes: 9 additions & 6 deletions Tests/Integration/Domain/Index/Queue/QueueItemRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTestBase;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\MockEventDispatcher;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -108,7 +108,8 @@ public function canFindItems(): void
public function canFindItemsAndModifyViaEventListener(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/pages_and_news_queueitems.csv');
$eventDispatcher = new MockEventDispatcher();
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);

$queueItemRepository = GeneralUtility::makeInstance(QueueItemRepository::class, null, $eventDispatcher);
$items = $queueItemRepository->findItems([], ['pages']);

Expand All @@ -117,11 +118,13 @@ public function canFindItemsAndModifyViaEventListener(): void
self::assertSame(2, count($items));
self::assertSame('pages', $firstItem->getType(), 'First item has unexpected type');

$eventDispatcher->addListener(function(AfterRecordsForIndexQueueItemsHaveBeenRetrievedEvent $event): void {
if ($event->getTable() === 'pages') {
$event->setRecords([]);
$eventDispatcher->expects(self::once())->method('dispatch')->willReturnCallback(
static function(AfterRecordsForIndexQueueItemsHaveBeenRetrievedEvent $event): void {
if ($event->getTable() === 'pages') {
$event->setRecords([]);
}
}
});
);

$items = $queueItemRepository->findItems([], ['pages']);
self::assertCount(0, $items);
Expand Down
2 changes: 2 additions & 0 deletions Tests/Unit/Backend/SettingsPreviewOnPluginsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function doesNotPrintPreviewOnNonExtSolrPlugins(): void
'tt_content',
[
'list_type' => 'some_other_CE',
//'CType' => '',
]
)
);
Expand All @@ -74,6 +75,7 @@ protected function getFakePageContentPreviewRenderingEvent(
$pageLayoutContextMock = $this->createMock(PageLayoutContext::class);
return new PageContentPreviewRenderingEvent(
$table,
(string)($record[(string)($GLOBALS['TCA'][$table]['ctrl']['type'] ?? '')] ?? ''),
$record,
$pageLayoutContextMock
);
Expand Down
4 changes: 3 additions & 1 deletion Tests/Unit/ConnectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Psr\Http\Message\StreamFactoryInterface;
use Symfony\Component\DependencyInjection\Container;
use Traversable;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

Expand Down Expand Up @@ -67,6 +68,7 @@ protected function setUp(): void
$container->set(RequestFactoryInterface::class, $this->createMock(RequestFactoryInterface::class));
$container->set(StreamFactoryInterface::class, $this->createMock(StreamFactoryInterface::class));
$container->set(EventDispatcherInterface::class, $this->createMock(EventDispatcherInterface::class));
$container->set(SiteFinder::class, $this->createMock(SiteFinder::class));
GeneralUtility::setContainer($container);

parent::setUp();
Expand Down Expand Up @@ -119,7 +121,7 @@ public static function connectDataProvider(): Traversable
}

/**
* Tests the connect
* Tests the connection
*/
#[DataProvider('connectDataProvider')]
#[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@

/**
* Testcase for IndexQueueModuleController
*
* @property IndexAdministrationModuleController|MockObject $controller
*/
class IndexAdministrationModuleControllerTest extends AbstractModuleController
class IndexAdministrationModuleControllerTest extends SetUpSolrModuleControllerTestCase
{
/**
* @var IndexAdministrationModuleController|MockObject
*/
protected $controller;

protected function setUp(): void
{
parent::setUpConcreteModuleController(IndexAdministrationModuleController::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,25 @@
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\MockEventDispatcher;
use Psr\EventDispatcher\EventDispatcherInterface;

/**
* Testcase for IndexQueueModuleController
*
* @property IndexQueueModuleController|MockObject $controller
*/
class IndexQueueModuleControllerTest extends AbstractModuleController
class IndexQueueModuleControllerTest extends SetUpSolrModuleControllerTestCase
{
protected Queue|MockObject $indexQueueMock;

/**
* @var IndexQueueModuleController|MockObject
*/
protected $controller;

protected MockEventDispatcher $eventDispatcher;
protected EventDispatcherInterface|MockObject $eventDispatcher;

protected function setUp(): void
{
parent::setUpConcreteModuleController(
IndexQueueModuleController::class,
['addIndexQueueFlashMessage']
);
$this->eventDispatcher = new MockEventDispatcher();
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->indexQueueMock = $this->getMockBuilder(Queue::class)
->onlyMethods(['updateOrAddItemForAllRelatedRootPages'])
->setConstructorArgs([
Expand Down Expand Up @@ -78,9 +74,11 @@ public function requeueDocumentActionIsTriggeringReIndexOnIndexQueue(): void
#[Test]
public function hookIsTriggeredWhenRegistered(): void
{
$this->eventDispatcher->addListener(function(AfterIndexQueueItemHasBeenMarkedForReindexingEvent $event) {
$event->setUpdateCount(5);
});
$this->eventDispatcher->expects(self::once())->method('dispatch')->willReturnCallback(
static function(AfterIndexQueueItemHasBeenMarkedForReindexingEvent $event) {
$event->setUpdateCount(5);
}
);

$this->indexQueueMock->expects(self::once())->method('updateOrAddItemForAllRelatedRootPages')->willReturn(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace ApacheSolrForTypo3\Solr\Tests\Unit\Controller\Backend\Search;

use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\Controller\Backend\Search\AbstractModuleController as ModuleController;
use ApacheSolrForTypo3\Solr\Controller\Backend\Search\AbstractModuleController as AbstractSolrModuleController;
use ApacheSolrForTypo3\Solr\Domain\Site\Site;
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
Expand All @@ -28,13 +28,9 @@
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;

abstract class AbstractModuleController extends SetUpUnitTestCase
abstract class SetUpSolrModuleControllerTestCase extends SetUpUnitTestCase
{
/**
* @var ModuleController|MockObject
*/
protected $controller;

protected AbstractSolrModuleController|MockObject $controller;
protected Site|MockObject $selectedSiteMock;
protected ConnectionManager|MockObject $connectionManagerMock;

Expand All @@ -46,7 +42,8 @@ protected function setUpConcreteModuleController(
array $mockMethods = ['addFlashMessage']
): void {
$this->selectedSiteMock = $this->createMock(Site::class);
/** @var ModuleController|MockObject $subject */
/** @var AbstractSolrModuleController|MockObject $subject */
/** @noinspection PhpUnitInvalidMockingEntityInspection The dg/bypass-finals is used in project */
$subject = $this->getMockBuilder($concreteModuleControllerClass)
->setConstructorArgs(
[
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;

use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\AbstractBaseEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\DelayedProcessingEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\Events\DelayedProcessingQueuingFinishedEvent;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\RecordUpdatedEvent;
Expand All @@ -25,14 +24,11 @@

/**
* Testcase for the DelayedProcessingEventListener
*
* @property DelayedProcessingEventListener $listener
*/
class DelayedProcessingEventListenerTest extends SetUpEventListener
{
/**
* @var DelayedProcessingEventListener
*/
protected AbstractBaseEventListener $listener;

#[Test]
public function canHandleEvents(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
namespace ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Index\Queue\UpdateHandler\EventListener;

use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\DataUpdateHandler;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\AbstractBaseEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\Events\ProcessingFinishedEvent;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\ImmediateProcessingEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\ContentElementDeletedEvent;
Expand All @@ -36,14 +35,11 @@

/**
* Testcase for the ImmediateProcessingEventListener
*
* @property ImmediateProcessingEventListener $listener
*/
class ImmediateProcessingEventListenerTest extends SetUpEventListener
{
/**
* @var ImmediateProcessingEventListener
*/
protected AbstractBaseEventListener $listener;

protected function setUp(): void
{
if (!class_exists('SolrUnitTestsInvalidDataUpdateEvent')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@

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

use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\AbstractBaseEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\EventListener\NoProcessingEventListener;
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events\RecordUpdatedEvent;
use PHPUnit\Framework\Attributes\Test;

/**
* Testcase for the NoProcessingEventListener
*
* @property NoProcessingEventListener $listener;
*/
class NoProcessingEventListenerTest extends SetUpEventListener
{
/**
* @var NoProcessingEventListener
*/
protected AbstractBaseEventListener $listener;

#[Test]
public function canHandleEvents(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
*/
class GarbageHandlerTest extends SetUpUpdateHandler
{
/**
* @var GarbageHandler
*/
protected $garbageHandler;
protected GarbageHandler $garbageHandler;

protected function setUp(): void
{
Expand Down
33 changes: 5 additions & 28 deletions Tests/Unit/Domain/Index/Queue/UpdateHandler/SetUpUpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,11 @@
*/
abstract class SetUpUpdateHandler extends SetUpUnitTestCase
{
/**
* @var ConfigurationAwareRecordService|MockObject
*/
protected $recordServiceMock;

/**
* @var FrontendEnvironment|MockObject
*/
protected $frontendEnvironmentMock;

/**
* @var TypoScriptConfiguration|MockObject
*/
protected $typoScriptConfigurationMock;

/**
* @var TCAService|MockObject
*/
protected $tcaServiceMock;

/**
* @var Queue|MockObject
*/
protected $indexQueueMock;

/**
* @var PagesRepository|MockObject
*/
protected ConfigurationAwareRecordService|MockObject $recordServiceMock;
protected FrontendEnvironment|MockObject $frontendEnvironmentMock;
protected TypoScriptConfiguration|MockObject $typoScriptConfigurationMock;
protected TCAService|MockObject $tcaServiceMock;
protected Queue|MockObject $indexQueueMock;
protected PagesRepository|MockObject $pagesRepositoryMock;

protected function setUp(): void
Expand Down
17 changes: 3 additions & 14 deletions Tests/Unit/Domain/Search/ApacheSolrDocument/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,9 @@
*/
class RepositoryTest extends SetUpUnitTestCase
{
/**
* @var Search
*/
protected $search;

/**
* @var ConnectionManager
*/
protected $solrConnectionManager;

/**
* @var Site
*/
protected $mockedAsSingletonSite;
protected Search $search;
protected ConnectionManager $solrConnectionManager;
protected Site $mockedAsSingletonSite;

#[Test]
public function findOneByPageIdAndByLanguageIdReturnsFirstFoundDocument(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
*/
class HierarchyUrlDecoderTest extends SetUpUnitTestCase
{
/**
* @var HierarchyUrlDecoder
*/
protected $parser;
protected HierarchyUrlDecoder $parser;

protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
*/
class DateRangeUrlDecoderTest extends SetUpUnitTestCase
{
/**
* @var DateRangeUrlDecoder
*/
protected $rangeParser;
protected DateRangeUrlDecoder $rangeParser;

protected function setUp(): void
{
Expand Down
Loading

0 comments on commit 3ef0f20

Please sign in to comment.