From 5e047c5202506deaddd9311a4c02bf24aade6478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20K=C3=A4hm?= Date: Fri, 29 Oct 2021 16:31:50 +0200 Subject: [PATCH] [TASK-11.5C] Fix - "Unit" Tests Notes: * Replaces `GeneralUtility::isFirstPartOfStr()` with PHP8(or Symfony Polyfills 8.0) `str_starts_with()` Fixes: #3089 Relates: #2976, #2977 --- Build/Test/UnitTests.xml | 14 +++++----- Build/Test/cibuild.sh | 8 +++--- .../Search/Query/ParameterBuilder/Filters.php | 2 +- Classes/IndexQueue/PageIndexer.php | 3 +- .../UserFunctions/FlexFormUserFunctions.php | 5 ++-- .../Unit/ContentObject/ClassificationTest.php | 2 +- Tests/Unit/ContentObject/MultivalueTest.php | 2 +- .../ApacheSolrDocument/RepositoryTest.php | 27 +++++++++++------- .../Domain/Search/Query/QueryBuilderTest.php | 10 +++---- .../Facets/DefaultFacetQueryBuilderTest.php | 4 +-- .../ResultSet/Facets/FacetRegistryTest.php | 18 ++++++------ .../NumericRangeUrlDecoderTest.php | 8 ++++-- .../Search/ResultSet/SearchResultSetTest.php | 12 ++++++-- .../Score/ScoreCalculationServiceTest.php | 14 +++++----- .../Search/Uri/SearchUriBuilderTest.php | 2 +- .../FrontendEnvironment/TypoScriptTest.php | 3 ++ Tests/Unit/IndexQueue/AbstractIndexerTest.php | 5 ++-- Tests/Unit/IndexQueue/IndexerTest.php | 2 ++ Tests/Unit/Query/Modifier/FacetingTest.php | 28 +++++++++---------- Tests/Unit/System/TCA/TCAServiceTest.php | 8 +++--- Tests/Unit/Typo3PageContentExtractorTest.php | 10 +++---- composer.json | 3 +- 22 files changed, 109 insertions(+), 81 deletions(-) diff --git a/Build/Test/UnitTests.xml b/Build/Test/UnitTests.xml index bac807bdee..18e2b172c9 100644 --- a/Build/Test/UnitTests.xml +++ b/Build/Test/UnitTests.xml @@ -1,4 +1,5 @@ - + - + + + ../../Classes/ + + ../../Tests/Unit/ - - - ../../Classes/ - - diff --git a/Build/Test/cibuild.sh b/Build/Test/cibuild.sh index 89f65608a7..48be4a449f 100755 --- a/Build/Test/cibuild.sh +++ b/Build/Test/cibuild.sh @@ -61,28 +61,28 @@ fi # Map the travis and shell variable names to the expected # casing of the TYPO3 core. # -if [ -n $TYPO3_DATABASE_NAME ]; then +if [[ -n $TYPO3_DATABASE_NAME ]]; then export typo3DatabaseName=$TYPO3_DATABASE_NAME else echo "No environment variable TYPO3_DATABASE_NAME set. Please set it to run the integration tests." exit 1 fi -if [ -n $TYPO3_DATABASE_HOST ]; then +if [[ -n $TYPO3_DATABASE_HOST ]]; then export typo3DatabaseHost=$TYPO3_DATABASE_HOST else echo "No environment variable TYPO3_DATABASE_HOST set. Please set it to run the integration tests." exit 1 fi -if [ -n $TYPO3_DATABASE_USERNAME ]; then +if [[ -n $TYPO3_DATABASE_USERNAME ]]; then export typo3DatabaseUsername=$TYPO3_DATABASE_USERNAME else echo "No environment variable TYPO3_DATABASE_USERNAME set. Please set it to run the integration tests." exit 1 fi -if [ -n $TYPO3_DATABASE_PASSWORD ]; then +if [[ -n $TYPO3_DATABASE_PASSWORD ]]; then export typo3DatabasePassword=$TYPO3_DATABASE_PASSWORD else echo "No environment variable TYPO3_DATABASE_PASSWORD set. Please set it to run the integration tests." diff --git a/Classes/Domain/Search/Query/ParameterBuilder/Filters.php b/Classes/Domain/Search/Query/ParameterBuilder/Filters.php index fb09d0ed05..120dd3713f 100644 --- a/Classes/Domain/Search/Query/ParameterBuilder/Filters.php +++ b/Classes/Domain/Search/Query/ParameterBuilder/Filters.php @@ -56,7 +56,7 @@ public function removeByFieldName($filterFieldName) public function removeByPrefix($filterFieldName) { foreach ($this->filters as $key => $filterString) { - if (GeneralUtility::isFirstPartOfStr($filterString, $filterFieldName)) { + if (\str_starts_with($filterString, $filterFieldName)) { unset($this->filters[$key]); } } diff --git a/Classes/IndexQueue/PageIndexer.php b/Classes/IndexQueue/PageIndexer.php index 771458a163..4c827c49e3 100644 --- a/Classes/IndexQueue/PageIndexer.php +++ b/Classes/IndexQueue/PageIndexer.php @@ -29,6 +29,7 @@ use ApacheSolrForTypo3\Solr\Domain\Index\PageIndexer\Helper\UriBuilder\AbstractUriStrategy; use ApacheSolrForTypo3\Solr\Domain\Index\PageIndexer\Helper\UriStrategyFactory; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; +use TYPO3\CMS\Core\Type\Bitmask\PageTranslationVisibility; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -119,7 +120,7 @@ protected function getSolrConnectionsByItem(Item $item) unset($solrConnections[0]); } - if (GeneralUtility::hideIfNotTranslated($page['l18n_cfg'])) { + if ((new PageTranslationVisibility((int)$page['l18n_cfg'] ?? 0))->shouldHideTranslationIfNoTranslatedRecordExists()) { $accessibleSolrConnections = []; if (isset($solrConnections[0])) { $accessibleSolrConnections[0] = $solrConnections[0]; diff --git a/Classes/System/UserFunctions/FlexFormUserFunctions.php b/Classes/System/UserFunctions/FlexFormUserFunctions.php index 0e7119621c..e7fc02ed73 100644 --- a/Classes/System/UserFunctions/FlexFormUserFunctions.php +++ b/Classes/System/UserFunctions/FlexFormUserFunctions.php @@ -19,6 +19,7 @@ use ApacheSolrForTypo3\Solr\System\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; +use function str_starts_with; /** * This class contains all user functions for flexforms. @@ -82,9 +83,9 @@ protected function getParsedSolrFieldsFromSchema($configuredFacets, $pageRecord) $configuredFacet = array_values($configuredFacets); $label = $configuredFacet[0]['label']; // try to translate LLL: label or leave it unchanged - if (GeneralUtility::isFirstPartOfStr($label, 'LLL:') && $this->getTranslation($label) != '') { + if (str_starts_with($label, 'LLL:') && $this->getTranslation($label) != '') { $label = $this->getTranslation($label); - } elseif (!GeneralUtility::isFirstPartOfStr($label, 'LLL:') && $configuredFacet[0]['label.']) { + } elseif (!str_starts_with($label, 'LLL:') && $configuredFacet[0]['label.']) { $label = sprintf('cObject[...faceting.facets.%slabel]', array_keys($configuredFacets)[0]); } $label = sprintf('%s (Facet Label: "%s")', $value, $label); diff --git a/Tests/Unit/ContentObject/ClassificationTest.php b/Tests/Unit/ContentObject/ClassificationTest.php index 2401b2a573..de7ac3cb5f 100644 --- a/Tests/Unit/ContentObject/ClassificationTest.php +++ b/Tests/Unit/ContentObject/ClassificationTest.php @@ -119,7 +119,7 @@ protected function setUp(): void $GLOBALS['TSFE'] = $this->getDumbMock(TypoScriptFrontendController::class); $this->contentObject = $this->getMockBuilder(ContentObjectRenderer::class) - ->setMethods(['getResourceFactory', 'getEnvironmentVariable']) + ->onlyMethods(['getResourceFactory', 'getEnvironmentVariable', 'getRequest']) ->setConstructorArgs([$GLOBALS['TSFE']])->getMock(); } diff --git a/Tests/Unit/ContentObject/MultivalueTest.php b/Tests/Unit/ContentObject/MultivalueTest.php index 1f2b16de49..7e716da4fa 100644 --- a/Tests/Unit/ContentObject/MultivalueTest.php +++ b/Tests/Unit/ContentObject/MultivalueTest.php @@ -93,7 +93,7 @@ protected function setUp(): void $GLOBALS['TSFE'] = $this->getDumbMock(TypoScriptFrontendController::class); $this->contentObject = $this->getMockBuilder(ContentObjectRenderer::class) - ->setMethods(['getResourceFactory', 'getEnvironmentVariable']) + ->setMethods(['getResourceFactory', 'getEnvironmentVariable', 'getRequest']) ->setConstructorArgs([$GLOBALS['TSFE']])->getMock(); } diff --git a/Tests/Unit/Domain/Search/ApacheSolrDocument/RepositoryTest.php b/Tests/Unit/Domain/Search/ApacheSolrDocument/RepositoryTest.php index c6b6159a52..a0e9c624f0 100644 --- a/Tests/Unit/Domain/Search/ApacheSolrDocument/RepositoryTest.php +++ b/Tests/Unit/Domain/Search/ApacheSolrDocument/RepositoryTest.php @@ -28,14 +28,14 @@ use ApacheSolrForTypo3\Solr\Domain\Search\ApacheSolrDocument\Repository; use ApacheSolrForTypo3\Solr\Domain\Search\Query\QueryBuilder; use ApacheSolrForTypo3\Solr\Domain\Search\Query\Query; -use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result\Parser\DocumentEscapeService; use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException; use ApacheSolrForTypo3\Solr\Search; use ApacheSolrForTypo3\Solr\Domain\Site\Site; -use ApacheSolrForTypo3\Solr\SolrService; +use ApacheSolrForTypo3\Solr\System\Solr\Service\AbstractSolrService; use ApacheSolrForTypo3\Solr\System\Solr\Document\Document; use ApacheSolrForTypo3\Solr\System\Solr\ResponseAdapter; use ApacheSolrForTypo3\Solr\Tests\Unit\UnitTest; +use InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -66,7 +66,10 @@ public function findOneByPageIdAndByLanguageIdReturnsFirstFoundDocument() { $apacheSolrDocumentCollection = [new Document(), new Document()]; $apacheSolrDocumentRepository = $this->getAccessibleMock(Repository::class, ['findByPageIdAndByLanguageId']); - $apacheSolrDocumentRepository->expects($this->at(0))->method('findByPageIdAndByLanguageId')->will($this->returnValue($apacheSolrDocumentCollection)); + $apacheSolrDocumentRepository + ->expects($this->exactly(1)) + ->method('findByPageIdAndByLanguageId') + ->will($this->returnValue($apacheSolrDocumentCollection)); /* @var $apacheSolrDocumentRepository Repository */ $this->assertSame($apacheSolrDocumentCollection[0], $apacheSolrDocumentRepository->findOneByPageIdAndByLanguageId(0, 0)); @@ -74,11 +77,12 @@ public function findOneByPageIdAndByLanguageIdReturnsFirstFoundDocument() /** * @test - * @expectedException \InvalidArgumentException - * @expectedExceptionCode 1487332926 */ public function findByPageIdAndByLanguageIdThrowsInvalidArgumentExceptionIfPageIdIsNotSet() { + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionCode(1487332926); /* @var $apacheSolrDocumentRepository Repository */ $apacheSolrDocumentRepository = GeneralUtility::makeInstance(Repository::class); $apacheSolrDocumentRepository->findByPageIdAndByLanguageId(null, 3); @@ -86,11 +90,11 @@ public function findByPageIdAndByLanguageIdThrowsInvalidArgumentExceptionIfPageI /** * @test - * @expectedException \InvalidArgumentException - * @expectedExceptionCode 1487335178 */ public function findByPageIdAndByLanguageIdThrowsInvalidArgumentExceptionIfLanguageIdIsNotInteger() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionCode(1487335178); /* @var $apacheSolrDocumentRepository Repository */ $apacheSolrDocumentRepository = GeneralUtility::makeInstance(Repository::class); $apacheSolrDocumentRepository->findByPageIdAndByLanguageId(1, 'Abc'); @@ -103,7 +107,10 @@ public function findByPageIdAndByLanguageIdReturnsEmptyCollectionIfConnectionToS { /* @var $apacheSolrDocumentRepository Repository */ $apacheSolrDocumentRepository = $this->getAccessibleMock(Repository::class, ['initializeSearch']); - $apacheSolrDocumentRepository->expects($this->at(0))->method('initializeSearch')->will($this->throwException(new NoSolrConnectionFoundException())); + $apacheSolrDocumentRepository + ->expects($this->exactly(1)) + ->method('initializeSearch') + ->will($this->throwException(new NoSolrConnectionFoundException())); $apacheSolrDocumentCollection = $apacheSolrDocumentRepository->findByPageIdAndByLanguageId(777, 0); $this->assertEmpty($apacheSolrDocumentCollection); @@ -116,9 +123,9 @@ public function findByPageIdAndByLanguageIdReturnsEmptyCollectionIfConnectionToS public function findByPageIdAndByLanguageIdReturnsResultFromSearch() { - $solrServiceMock = $this->getDumbMock(SolrService::class); + $AbstractSolrServiceMock = $this->getDumbMock(AbstractSolrService::class); $solrConnectionManager = $this->getAccessibleMock(ConnectionManager::class, ['getConnectionByPageId'], [], '', false); - $solrConnectionManager->expects($this->any())->method('getConnectionByPageId')->will($this->returnValue($solrServiceMock)); + $solrConnectionManager->expects($this->any())->method('getConnectionByPageId')->will($this->returnValue($AbstractSolrServiceMock)); $mockedSingletons = [ConnectionManager::class => $solrConnectionManager]; $search = $this->getAccessibleMock(Search::class, ['search', 'getResultDocumentsEscaped'], [], '', false); diff --git a/Tests/Unit/Domain/Search/Query/QueryBuilderTest.php b/Tests/Unit/Domain/Search/Query/QueryBuilderTest.php index 4265a9d16e..e8afdbf74b 100644 --- a/Tests/Unit/Domain/Search/Query/QueryBuilderTest.php +++ b/Tests/Unit/Domain/Search/Query/QueryBuilderTest.php @@ -28,7 +28,6 @@ use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Elevation; use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Faceting; use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\FieldCollapsing; -use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Filters; use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Grouping; use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Highlighting; use ApacheSolrForTypo3\Solr\Domain\Search\Query\ParameterBuilder\Operator; @@ -47,6 +46,7 @@ use ApacheSolrForTypo3\Solr\Tests\Unit\UnitTest; use Solarium\QueryType\Select\RequestBuilder; use TYPO3\CMS\Core\Utility\GeneralUtility; +use function str_starts_with; /** * @author Timo Hund @@ -456,7 +456,7 @@ public function groupingIsNotActiveAfterInitialization() $queryParameters = $query->getQueryParameters(); foreach ($queryParameters as $queryParameter => $value) { $this->assertTrue( - !GeneralUtility::isFirstPartOfStr($queryParameter, 'group'), + !str_starts_with($queryParameter, 'group'), 'Query already contains grouping parameter "' . $queryParameter . '"' ); } @@ -496,7 +496,7 @@ public function settingGroupingFalseDeactivatesGrouping(SearchQuery $query) $queryParameters = $this->getAllQueryParameters($query); foreach ($queryParameters as $queryParameter => $value) { $this->assertTrue( - !GeneralUtility::isFirstPartOfStr($queryParameter, 'group'), + !str_starts_with($queryParameter, 'group'), 'Query contains grouping parameter "' . $queryParameter . '"' ); } @@ -1201,7 +1201,7 @@ public function canSetQueryElevation() $this->assertNull($queryParameters['enableElevation']); $this->assertNull($queryParameters['forceElevation']); - $this->assertNotContains('isElevated:[elevated]', $queryParameters['fl']); + $this->assertStringNotContainsString('isElevated:[elevated]', $queryParameters['fl']); // do we get the expected default values, when calling setQueryElevantion with no arguments? @@ -1210,7 +1210,7 @@ public function canSetQueryElevation() $queryParameters = $this->getAllQueryParameters($query); $this->assertSame('true', $queryParameters['enableElevation'], 'enabledElevation was not set after enabling elevation'); $this->assertSame('true', $queryParameters['forceElevation'], 'forceElevation was not set after enabling elevation'); - $this->assertContains('isElevated:[elevated]', $queryParameters['fl'], 'isElevated should be in the list of return fields'); + $this->assertStringContainsString('isElevated:[elevated]', $queryParameters['fl'], 'isElevated should be in the list of return fields'); // can we reset the elevantion? $elevation->setIsEnabled(false); diff --git a/Tests/Unit/Domain/Search/ResultSet/Facets/DefaultFacetQueryBuilderTest.php b/Tests/Unit/Domain/Search/ResultSet/Facets/DefaultFacetQueryBuilderTest.php index 187e5f8486..80841ec566 100644 --- a/Tests/Unit/Domain/Search/ResultSet/Facets/DefaultFacetQueryBuilderTest.php +++ b/Tests/Unit/Domain/Search/ResultSet/Facets/DefaultFacetQueryBuilderTest.php @@ -58,7 +58,7 @@ public function testWhenKeepAllOptionsOnSelectionIsNotConfiguredNoExcludeTagIsAd $defaultQueryBuilder = new DefaultFacetQueryBuilder(); $result = $defaultQueryBuilder->build('color', $fakeConfiguration); - $this->assertNotContains('{!ex', $result['facet.field'][0]); + $this->assertStringNotContainsString('{!ex', $result['facet.field'][0]); } -} \ No newline at end of file +} diff --git a/Tests/Unit/Domain/Search/ResultSet/Facets/FacetRegistryTest.php b/Tests/Unit/Domain/Search/ResultSet/Facets/FacetRegistryTest.php index b3e9481a58..98bd013b6c 100644 --- a/Tests/Unit/Domain/Search/ResultSet/Facets/FacetRegistryTest.php +++ b/Tests/Unit/Domain/Search/ResultSet/Facets/FacetRegistryTest.php @@ -18,6 +18,8 @@ use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\FacetRegistry; use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Options\OptionsPackage; use ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Search\ResultSet\Facets\TestPackage\TestPackage; +use InvalidArgumentException; +use PHPUnit\Framework\MockObject\MockObject; use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; @@ -45,14 +47,14 @@ public function setUp(): void { /** * Initialize a RendererRegistry and mock createRendererInstance() * - * @param array $createsParserInstances - * @return \PHPUnit_Framework_MockObject_MockObject|FacetRegistry + * @param array $createsPackageInstances + * @return MockObject|FacetRegistry */ protected function getTestFacetPackageRegistry(array $createsPackageInstances = []) { - /** @var $facetRegistry FacetRegistry */ + /** @var $facetRegistry MockObject|FacetRegistry */ $facetRegistry = $this->getMockBuilder(FacetRegistry::class) - ->setMethods(['createInstance']) + ->onlyMethods(['createInstance']) ->getMock(); // @extensionScannerIgnoreLine @@ -84,22 +86,22 @@ public function registeredPackageClassCanBeRetrievedByType() /** * @test - * @expectedException \InvalidArgumentException - * @expectedExceptionCode 1462883324 */ public function registerParserClassThrowsExceptionIfClassDoesNotExist() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionCode(1462883324); $facetParserRegistry = $this->getTestFacetPackageRegistry(); $facetParserRegistry->registerPackage($this->getUniqueId(), 'unknown'); } /** * @test - * @expectedException \InvalidArgumentException - * @expectedExceptionCode 1462883325 */ public function registerParserClassThrowsExceptionIfClassDoesNotImplementFacetPackageInterface() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionCode(1462883325); $className = __CLASS__; $facetParserRegistry = $this->getTestFacetPackageRegistry(); $facetParserRegistry->registerPackage($className, 'unknown'); diff --git a/Tests/Unit/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoderTest.php b/Tests/Unit/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoderTest.php index 6232371602..39a808090a 100644 --- a/Tests/Unit/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoderTest.php +++ b/Tests/Unit/Domain/Search/ResultSet/Facets/RangeBased/NumericRange/NumericRangeUrlDecoderTest.php @@ -28,6 +28,7 @@ use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RangeBased\NumericRange\NumericRangeUrlDecoder; use ApacheSolrForTypo3\Solr\Tests\Unit\UnitTest; +use InvalidArgumentException; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -56,7 +57,7 @@ public function setUp(): void * * @return array */ - public function rangeQueryParsingDataProvider() + public function rangeQueryParsingDataProvider(): array { return [ ['firstValue' => '50', 'secondValue' => '100', 'expected' => '[50 TO 100]'], @@ -76,7 +77,7 @@ public function rangeQueryParsingDataProvider() * @param string $expectedResult * @return void */ - public function canParseRangeQuery($firstValue, $secondValue, $expectedResult) + public function canParseRangeQuery(string $firstValue, string $secondValue, string $expectedResult) { $actual = $this->rangeParser->decode($firstValue . '-' . $secondValue); $this->assertEquals($expectedResult, $actual); @@ -86,11 +87,12 @@ public function canParseRangeQuery($firstValue, $secondValue, $expectedResult) * Test the handling of invalid parameters * * @test - * @expectedException \InvalidArgumentException + * * @return void */ public function canHandleInvalidParameters() { + $this->expectException(InvalidArgumentException::class); $this->rangeParser->decode('invalid-value'); } } diff --git a/Tests/Unit/Domain/Search/ResultSet/SearchResultSetTest.php b/Tests/Unit/Domain/Search/ResultSet/SearchResultSetTest.php index 58706815b9..209d67f515 100644 --- a/Tests/Unit/Domain/Search/ResultSet/SearchResultSetTest.php +++ b/Tests/Unit/Domain/Search/ResultSet/SearchResultSetTest.php @@ -206,8 +206,16 @@ public function canRegisterSearchResultSetProcessor() $fakeRequest = new SearchRequest(['tx_solr' => ['q' => 'my 4. search']]); $fakeRequest->setResultsPerPage(10); - $this->objectManagerMock->expects($this->at(0))->method('get')->with(SearchResultSet::class)->willReturn(new SearchResultSet()); - $this->objectManagerMock->expects($this->at(1))->method('get')->with($testProcessor)->willReturn(new TestSearchResultSetProcessor()); + $this->objectManagerMock + ->expects($this->exactly(2)) + ->method('get') + ->withConsecutive( + [SearchResultSet::class], + [$testProcessor] + )->will($this->onConsecutiveCalls( + new SearchResultSet(), + new TestSearchResultSetProcessor() + )); $resultSet = $this->searchResultSetService->search($fakeRequest); diff --git a/Tests/Unit/Domain/Search/Score/ScoreCalculationServiceTest.php b/Tests/Unit/Domain/Search/Score/ScoreCalculationServiceTest.php index cfa0f3de75..312aa7ba8f 100644 --- a/Tests/Unit/Domain/Search/Score/ScoreCalculationServiceTest.php +++ b/Tests/Unit/Domain/Search/Score/ScoreCalculationServiceTest.php @@ -36,7 +36,7 @@ class ScoreCalculationServiceTest extends UnitTest /** * @var ScoreCalculationService */ - protected $scoreCalculationService; + protected ScoreCalculationService $scoreCalculationService; /** * @return void @@ -56,12 +56,12 @@ public function canGetRenderedScoreAnalysis() $scoreAnalysis = $this->scoreCalculationService->getRenderedScores($fakeDebugData, $fakeQueryFields); - $this->assertContains('+ 98.444336assertContains('content', $scoreAnalysis); - $this->assertContains('40.0', $scoreAnalysis); + $this->assertStringContainsString('+ 98.444336assertStringContainsString('content', $scoreAnalysis); + $this->assertStringContainsString('40.0', $scoreAnalysis); - $this->assertContains('+ 6.2762194', $scoreAnalysis); - $this->assertContains('tagsH2H3', $scoreAnalysis); - $this->assertContains('3.0', $scoreAnalysis); + $this->assertStringContainsString('+ 6.2762194', $scoreAnalysis); + $this->assertStringContainsString('tagsH2H3', $scoreAnalysis); + $this->assertStringContainsString('3.0', $scoreAnalysis); } } diff --git a/Tests/Unit/Domain/Search/Uri/SearchUriBuilderTest.php b/Tests/Unit/Domain/Search/Uri/SearchUriBuilderTest.php index ef8db88adb..02bf6c5516 100644 --- a/Tests/Unit/Domain/Search/Uri/SearchUriBuilderTest.php +++ b/Tests/Unit/Domain/Search/Uri/SearchUriBuilderTest.php @@ -350,7 +350,7 @@ public function canSetGroupPageForQueryGroup() ->method('reviseFilterVariables') ->will($this->returnValue(['###tx_solr:groupPage:smallPidRange:pid0to5###' => '5'])); $uri = $this->searchUrlBuilder->getResultGroupItemPageUri($previousRequest, $groupItem, 5); - $this->assertContains(urlencode('tx_solr[groupPage][smallPidRange][pid0to5]') . '=5', $uri, 'Uri did not contain link segment for query group'); + $this->assertStringContainsString(urlencode('tx_solr[groupPage][smallPidRange][pid0to5]') . '=5', $uri, 'Uri did not contain link segment for query group'); } /* diff --git a/Tests/Unit/FrontendEnvironment/TypoScriptTest.php b/Tests/Unit/FrontendEnvironment/TypoScriptTest.php index cb6ab6ec15..b42c49f270 100644 --- a/Tests/Unit/FrontendEnvironment/TypoScriptTest.php +++ b/Tests/Unit/FrontendEnvironment/TypoScriptTest.php @@ -20,11 +20,14 @@ use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; use ApacheSolrForTypo3\Solr\Tests\Unit\UnitTest; use PHPUnit\Framework\MockObject\MockObject; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use TYPO3\CMS\Core\Utility\GeneralUtility; class TypoScriptTest extends UnitTest { + use ProphecyTrait; + /** * @var TypoScript */ diff --git a/Tests/Unit/IndexQueue/AbstractIndexerTest.php b/Tests/Unit/IndexQueue/AbstractIndexerTest.php index 418e68b54a..04591094b2 100644 --- a/Tests/Unit/IndexQueue/AbstractIndexerTest.php +++ b/Tests/Unit/IndexQueue/AbstractIndexerTest.php @@ -26,6 +26,7 @@ use ApacheSolrForTypo3\Solr\IndexQueue\AbstractIndexer; use ApacheSolrForTypo3\Solr\Tests\Unit\UnitTest; +use UnexpectedValueException; /** * @author Timo Hund @@ -69,8 +70,8 @@ public function isSerializedValueCanHandleCustomInvalidSerializedValueDetector() { // register invalid detector $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['detectSerializedValue'][] = InvalidSerializedValueDetector::class; - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessageRegExp('/.*InvalidSerializedValueDetector must implement interface.*/'); + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessageMatches('/.*InvalidSerializedValueDetector must implement interface.*/'); $indexingConfiguration = [ 'topic_stringM' => 'SOLR_CLASSIFICATION' diff --git a/Tests/Unit/IndexQueue/IndexerTest.php b/Tests/Unit/IndexQueue/IndexerTest.php index 814331b8e5..a4d83d84a3 100644 --- a/Tests/Unit/IndexQueue/IndexerTest.php +++ b/Tests/Unit/IndexQueue/IndexerTest.php @@ -23,6 +23,7 @@ use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository; use ApacheSolrForTypo3\Solr\Tests\Unit\UnitTest; use PHPUnit\Framework\MockObject\MockBuilder; +use Prophecy\PhpUnit\ProphecyTrait; use ReflectionClass; use ReflectionException; @@ -32,6 +33,7 @@ */ class IndexerTest extends UnitTest { + use ProphecyTrait; public function setUp(): void { diff --git a/Tests/Unit/Query/Modifier/FacetingTest.php b/Tests/Unit/Query/Modifier/FacetingTest.php index a05780d03c..dc19e4e6f0 100644 --- a/Tests/Unit/Query/Modifier/FacetingTest.php +++ b/Tests/Unit/Query/Modifier/FacetingTest.php @@ -95,7 +95,7 @@ public function testCanAddASimpleFacet() $fakeRequest->expects($this->once())->method('getArguments')->will($this->returnValue([])); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); $expectedJsonFacet = '{"type":{"type":"terms","field":"type","limit":100,"mincount":1}}'; $this->assertSame($expectedJsonFacet, $queryParameter['json.facet'], 'Query string did not contain expected snipped'); @@ -129,8 +129,8 @@ public function testCanAddSortByIndexArgument() $fakeRequest->expects($this->once())->method('getArguments')->will($this->returnValue([])); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); - $this->assertContains('"sort":"index"', $queryParameter['json.facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('"sort":"index"', $queryParameter['json.facet'], 'Query string did not contain expected snipped'); } /** @@ -161,9 +161,9 @@ public function testCanAddSortByCountArgument() $fakeRequest->expects($this->once())->method('getArguments')->will($this->returnValue([])); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); - $this->assertContains('"sort":"count"', $queryParameter['json.facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('"sort":"count"', $queryParameter['json.facet'], 'Query string did not contain expected snipped'); } /** @@ -204,7 +204,7 @@ public function testCanHandleKeepAllFacetsOnSelectionOnAllFacetWhenGloballyConfi $fakeRequest->expects($this->any())->method('getContextTypoScriptConfiguration')->will($this->returnValue($fakeConfiguration)); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); $jsonData = \json_decode($queryParameter['json.facet']); $this->assertEquals('type,color', $jsonData->type->domain->excludeTags, 'Query string did not contain expected snipped'); @@ -246,7 +246,7 @@ public function testExcludeTagsAreEmptyWhenKeepAllFacetsOnSelectionIsNotSet() $fakeRequest->expects($this->any())->method('getContextTypoScriptConfiguration')->will($this->returnValue($fakeConfiguration)); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); $jsonData = \json_decode($queryParameter['json.facet']); $this->assertEmpty($jsonData->type->domain->excludeTags, 'Query string did not contain expected snipped'); @@ -292,7 +292,7 @@ public function testCanHandleKeepAllOptionsOnSelectionForASingleFacet() $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); $jsonData = \json_decode($queryParameter['json.facet']); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); $this->assertEquals('type', $jsonData->type->domain->excludeTags, 'Query string did not contain expected snipped'); $this->assertEquals('color', $jsonData->color->field, 'Query string did not contain expected snipped'); } @@ -323,7 +323,7 @@ public function testCanHandleCombinationOfKeepAllFacetsOnSelectionAndKeepAllOpti $fakeRequest->expects($this->any())->method('getContextTypoScriptConfiguration')->will($this->returnValue($fakeConfiguration)); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); $jsonData = \json_decode($queryParameter['json.facet']); @@ -362,7 +362,7 @@ public function testCanHandleCombinationOfKeepAllFacetsOnSelectionAndKeepAllOpti $fakeRequest->expects($this->any())->method('getContextTypoScriptConfiguration')->will($this->returnValue($fakeConfiguration)); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); $jsonData = \json_decode($queryParameter['json.facet']); @@ -398,7 +398,7 @@ public function testCanAddQueryFilters() $fakeRequest->expects($this->any())->method('getContextTypoScriptConfiguration')->will($this->returnValue($fakeConfiguration)); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); //do we have a filter query for both present? $this->assertEquals('(color:"red")', $queryParameter['fq'][0], 'Did not build filter query from color'); @@ -429,7 +429,7 @@ public function testCanAddQueryFiltersWithKeepAllOptionsOnSelectionFacet() $fakeRequest->expects($this->any())->method('getContextTypoScriptConfiguration')->will($this->returnValue($fakeConfiguration)); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); //do we have a filter query for both present? $this->assertEquals('(color:"red")', $queryParameter['fq'][0], 'Did not build filter query from color'); @@ -461,7 +461,7 @@ public function testCanAddQueryFiltersWithGlobalKeepAllOptionsOnSelection() $fakeRequest->expects($this->any())->method('getContextTypoScriptConfiguration')->will($this->returnValue($fakeConfiguration)); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); //do we have a filter query for both present? $this->assertEquals('{!tag=color}(color:"red")', $queryParameter['fq'][0], 'Did not build filter query from color'); @@ -494,7 +494,7 @@ public function testCanAddExcludeTagWithAdditionalExcludeTagConfiguration() $fakeRequest->expects($this->any())->method('getContextTypoScriptConfiguration')->will($this->returnValue($fakeConfiguration)); $queryParameter = $this->getQueryParametersFromExecutedFacetingModifier($fakeConfiguration, $fakeRequest); - $this->assertContains('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); + $this->assertStringContainsString('true', $queryParameter['facet'], 'Query string did not contain expected snipped'); $jsonData = \json_decode($queryParameter['json.facet']); $this->assertEquals('type,color', $jsonData->type->domain->excludeTags, 'Query string did not contain expected snipped'); diff --git a/Tests/Unit/System/TCA/TCAServiceTest.php b/Tests/Unit/System/TCA/TCAServiceTest.php index 7eac34b6c6..9be3312960 100644 --- a/Tests/Unit/System/TCA/TCAServiceTest.php +++ b/Tests/Unit/System/TCA/TCAServiceTest.php @@ -326,8 +326,8 @@ public function getVisibilityAffectingFieldsByTableCanReturnDefaultFieldsWhenNoT $tcaService = new TCAService([]); $visibilityFields = $tcaService->getVisibilityAffectingFieldsByTable('pages'); - $this->assertContains('doktype', $visibilityFields, 'Expected to have doktype as visibility affecting field as default for pages'); - $this->assertContains('no_search', $visibilityFields, 'Expected to have no_search as visibility affecting field as default for pages'); + $this->assertStringContainsString('doktype', $visibilityFields, 'Expected to have doktype as visibility affecting field as default for pages'); + $this->assertStringContainsString('no_search', $visibilityFields, 'Expected to have no_search as visibility affecting field as default for pages'); } /** @@ -355,7 +355,7 @@ public function getVisibilityAffectingFieldsByTableCanReturnConfiguredDeleteFiel $tcaService = new TCAService($fakeTCA); $visibilityFields = $tcaService->getVisibilityAffectingFieldsByTable('tx_domain_model_faketable'); - $this->assertContains('deleted', $visibilityFields, 'The deleted field should be retrieved as visibility affecting field'); + $this->assertStringContainsString('deleted', $visibilityFields, 'The deleted field should be retrieved as visibility affecting field'); } /** @@ -375,7 +375,7 @@ public function getVisibilityAffectingFieldsByTableCanReturnConfiguredEnableConf $tcaService = new TCAService($fakeTCA); $visibilityFields = $tcaService->getVisibilityAffectingFieldsByTable('tx_domain_model_faketable'); - $this->assertContains('fe_groups', $visibilityFields, 'The field fe_groups should be retrieved as visbility affecting field'); + $this->assertStringContainsString('fe_groups', $visibilityFields, 'The field fe_groups should be retrieved as visbility affecting field'); } /** diff --git a/Tests/Unit/Typo3PageContentExtractorTest.php b/Tests/Unit/Typo3PageContentExtractorTest.php index ec85cb7743..240d3f304c 100644 --- a/Tests/Unit/Typo3PageContentExtractorTest.php +++ b/Tests/Unit/Typo3PageContentExtractorTest.php @@ -90,8 +90,8 @@ public function excludeContentKeepsEncodingForUmlaut() $actualResult = $contentExtractor->excludeContentByClass($content); - $this->assertContains('Was ein schöner Tag', $actualResult); - $this->assertNotContains('Remove me', $actualResult); + $this->assertStringContainsString('Was ein schöner Tag', $actualResult); + $this->assertStringNotContainsString('Remove me', $actualResult); } /** @@ -106,8 +106,8 @@ public function excludeContentKeepsEncodingForEuroSign() $actualResult = $contentExtractor->excludeContentByClass($content); - $this->assertContains('100€', $actualResult); - $this->assertNotContains('Remove me', $actualResult); + $this->assertStringContainsString('100€', $actualResult); + $this->assertStringNotContainsString('Remove me', $actualResult); } public function canGetIndexableContentDataProvider() { @@ -160,6 +160,6 @@ public function canGetIndexableContent($content, $expectedResult) $contentExtractor->setConfiguration($this->typoScripConfigurationMock); $actualResult = $contentExtractor->getIndexableContent(); - $this->assertContains($expectedResult, $actualResult); + $this->assertStringContainsString($expectedResult, $actualResult); } } diff --git a/composer.json b/composer.json index 261105f2d0..a0da170dae 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "solarium/solarium": "6.1.4" }, "require-dev": { - "phpunit/phpunit": "^7.5.6 || ^8", + "phpunit/phpunit": "^9.5", + "phpspec/prophecy-phpunit":"*", "nimut/testing-framework": "^6.0.0" }, "replace": {