From 90212cb8c9bf691b1a4cf3f8ab57565fc90e942f Mon Sep 17 00:00:00 2001 From: ciastektk Date: Mon, 18 Sep 2023 14:35:28 +0200 Subject: [PATCH] Moved SearchQueryTypeTest to ibexa/search (#908) * Moved SearchQueryTypeTest to ibexa/search * [PHPStan] Regenerated baseline --- phpstan-baseline.neon | 40 ----- tests/lib/QueryType/SearchQueryTypeTest.php | 160 -------------------- 2 files changed, 200 deletions(-) delete mode 100644 tests/lib/QueryType/SearchQueryTypeTest.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8a959cdf45..d823af36bf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12936,46 +12936,6 @@ parameters: count: 1 path: tests/lib/Permission/PermissionCheckerTest.php - - - message: "#^Call to method getQuery\\(\\) on an unknown class Ibexa\\\\AdminUi\\\\QueryType\\\\SearchQueryType\\.$#" - count: 1 - path: tests/lib/QueryType/SearchQueryTypeTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\AdminUi\\\\QueryType\\\\SearchQueryTypeTest\\:\\:createContentTypesList\\(\\) has parameter \\$ids with no value type specified in iterable type array\\.$#" - count: 1 - path: tests/lib/QueryType/SearchQueryTypeTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\AdminUi\\\\QueryType\\\\SearchQueryTypeTest\\:\\:createContentTypesList\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/lib/QueryType/SearchQueryTypeTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\AdminUi\\\\QueryType\\\\SearchQueryTypeTest\\:\\:createExpectedQueryForAllCriteria\\(\\) has parameter \\$expectedSortClauses with no value type specified in iterable type array\\.$#" - count: 1 - path: tests/lib/QueryType/SearchQueryTypeTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\AdminUi\\\\QueryType\\\\SearchQueryTypeTest\\:\\:dataProviderForGetQuery\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: tests/lib/QueryType/SearchQueryTypeTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\AdminUi\\\\QueryType\\\\SearchQueryTypeTest\\:\\:testGetQuery\\(\\) has parameter \\$parameters with no value type specified in iterable type array\\.$#" - count: 1 - path: tests/lib/QueryType/SearchQueryTypeTest.php - - - - message: "#^Property Ibexa\\\\Tests\\\\AdminUi\\\\QueryType\\\\SearchQueryTypeTest\\:\\:\\$queryType \\(Ibexa\\\\AdminUi\\\\QueryType\\\\SearchQueryType\\) does not accept Ibexa\\\\Search\\\\QueryType\\\\SearchQueryType\\.$#" - count: 1 - path: tests/lib/QueryType/SearchQueryTypeTest.php - - - - message: "#^Property Ibexa\\\\Tests\\\\AdminUi\\\\QueryType\\\\SearchQueryTypeTest\\:\\:\\$queryType has unknown class Ibexa\\\\AdminUi\\\\QueryType\\\\SearchQueryType as its type\\.$#" - count: 1 - path: tests/lib/QueryType/SearchQueryTypeTest.php - - message: "#^Method Ibexa\\\\Tests\\\\AdminUi\\\\Resolver\\\\IconPathResolverTest\\:\\:getConfigResolverMock\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" count: 1 diff --git a/tests/lib/QueryType/SearchQueryTypeTest.php b/tests/lib/QueryType/SearchQueryTypeTest.php deleted file mode 100644 index c9b2b5b59e..0000000000 --- a/tests/lib/QueryType/SearchQueryTypeTest.php +++ /dev/null @@ -1,160 +0,0 @@ -searchService = $this->createMock(SearchService::class); - $this->queryType = new SearchQueryType($this->searchService); - } - - /** - * @dataProvider dataProviderForGetQuery - */ - public function testGetQuery(array $parameters, Query $expectedQuery, bool $isScoringSupported): void - { - $this->searchService - ->method('supports') - ->with(SearchService::CAPABILITY_SCORING) - ->willReturn($isScoringSupported); - - $this->assertEquals($expectedQuery, $this->queryType->getQuery($parameters)); - } - - public function dataProviderForGetQuery(): array - { - return [ - [ - [], - new Query(['sortClauses' => []]), - true, - ], - [ - [ - 'search_data' => $this->createSearchDataWithAllCriteria(), - ], - $this->createExpectedQueryForAllCriteria([]), - true, - ], - [ - [], - new Query([ - 'sortClauses' => [ - new SortClause\DateModified(), - ], - ]), - false, - ], - [ - [ - 'search_data' => $this->createSearchDataWithAllCriteria(), - ], - $this->createExpectedQueryForAllCriteria(), - false, - ], - ]; - } - - private function createContentTypesList(array $ids): array - { - return array_map(static function (int $id): ContentType { - return new ContentType(['id' => $id]); - }, $ids); - } - - private function createSearchDataWithAllCriteria(): SearchData - { - $searchData = new SearchData(); - $searchData->setQuery(self::EXPECTED_QUERY_STRING); - $searchData->setSection(new Section(['id' => self::EXPECTED_SECTION_ID])); - $searchData->setContentTypes($this->createContentTypesList(self::EXPECTED_CONTENT_TYPE_IDS)); - $searchData->setCreated([ - 'start_date' => self::EXPECTED_DATE_RANGE[0], - 'end_date' => self::EXPECTED_DATE_RANGE[1], - ]); - $searchData->setLastModified([ - 'start_date' => self::EXPECTED_DATE_RANGE[0], - 'end_date' => self::EXPECTED_DATE_RANGE[1], - ]); - $searchData->setCreator($this->createUser(self::EXPECTED_USER_ID)); - $searchData->setSubtree(self::EXPECTED_SUBTREE); - - return $searchData; - } - - private function createUser(int $id): User - { - $user = $this->createMock(User::class); - $user->method('__get')->with('id')->willReturn($id); - - return $user; - } - - private function createExpectedQueryForAllCriteria(?array $expectedSortClauses = null): Query - { - if ($expectedSortClauses === null) { - $expectedSortClauses = [ - new SortClause\DateModified(), - ]; - } - - return new Query([ - 'query' => new Criterion\FullText(self::EXPECTED_QUERY_STRING), - 'filter' => new Criterion\LogicalAnd([ - new Criterion\SectionId(self::EXPECTED_SECTION_ID), - new Criterion\ContentTypeId(self::EXPECTED_CONTENT_TYPE_IDS), - new Criterion\DateMetadata( - Criterion\DateMetadata::MODIFIED, - Criterion\Operator::BETWEEN, - self::EXPECTED_DATE_RANGE - ), - new Criterion\DateMetadata( - Criterion\DateMetadata::CREATED, - Criterion\Operator::BETWEEN, - self::EXPECTED_DATE_RANGE - ), - new Criterion\UserMetadata( - Criterion\UserMetadata::OWNER, - Criterion\Operator::EQ, - self::EXPECTED_USER_ID - ), - new Criterion\Subtree(self::EXPECTED_SUBTREE), - ]), - 'sortClauses' => $expectedSortClauses, - ]); - } -} - -class_alias(SearchQueryTypeTest::class, 'EzSystems\EzPlatformAdminUi\Tests\QueryType\SearchQueryTypeTest');