From 72035799704e40aadeefac19b7d5455c2d900185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Mon, 21 Mar 2022 14:45:27 +0100 Subject: [PATCH] Fixed Solr integration tests (#92) * [Behat] Changed when test services are loaded * [Unit tests] Fixed Solr setup factory namespace * Fixed SolrSetup usage and detection * Excluded Filtering tests --- phpstan-baseline.neon | 8 ++++---- phpunit-integration-legacy-solr.xml | 3 ++- .../DependencyInjection/IbexaCoreExtension.php | 9 +++++++-- .../Regression/EZP20018LanguageTest.php | 2 +- .../Core/Repository/SearchServiceLocationTest.php | 2 +- .../Core/Repository/SearchServiceTest.php | 15 ++++++++++----- ...archServiceTranslationLanguageFallbackTest.php | 2 +- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b4cc7de6f5..ee31e72acd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -381,22 +381,22 @@ parameters: path: tests/integration/Core/Repository/FieldType/UserIntegrationTest.php - - message: "#^Class Ibexa\\\\Solr\\\\LegacySetupFactory not found\\.$#" + message: "#^Class Ibexa\\\\Tests\\\\Solr\\\\SetupFactory\\\\LegacySetupFactory not found\\.$#" count: 1 path: tests/integration/Core/Repository/Regression/EZP20018LanguageTest.php - - message: "#^Class Ibexa\\\\Solr\\\\LegacySetupFactory not found\\.$#" + message: "#^Class Ibexa\\\\Tests\\\\Solr\\\\SetupFactory\\\\LegacySetupFactory not found\\.$#" count: 1 path: tests/integration/Core/Repository/SearchServiceLocationTest.php - - message: "#^Class Ibexa\\\\Solr\\\\LegacySetupFactory not found\\.$#" + message: "#^Class Ibexa\\\\Tests\\\\Solr\\\\SetupFactory\\\\LegacySetupFactory not found\\.$#" count: 5 path: tests/integration/Core/Repository/SearchServiceTest.php - - message: "#^Class Ibexa\\\\Solr\\\\LegacySetupFactory not found\\.$#" + message: "#^Class Ibexa\\\\Tests\\\\Solr\\\\SetupFactory\\\\LegacySetupFactory not found\\.$#" count: 3 path: tests/integration/Core/Repository/SearchServiceTranslationLanguageFallbackTest.php diff --git a/phpunit-integration-legacy-solr.xml b/phpunit-integration-legacy-solr.xml index de4a92757f..3dce726268 100644 --- a/phpunit-integration-legacy-solr.xml +++ b/phpunit-integration-legacy-solr.xml @@ -11,7 +11,7 @@ failOnWarning="true" > - + @@ -24,6 +24,7 @@ tests/integration/Core + tests/integration/Core/Repository/Filtering diff --git a/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php b/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php index 1ef01ed5a8..15bfacc667 100644 --- a/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php +++ b/src/bundle/Core/DependencyInjection/IbexaCoreExtension.php @@ -103,8 +103,7 @@ public function load(array $configs, ContainerBuilder $container) $configuration = $this->getConfiguration($configs, $container); - $environment = $container->getParameter('kernel.environment'); - if (in_array($environment, ['behat', 'test'])) { + if ($this->shouldLoadTestBehatServices($container)) { $loader->load('feature_contexts.yml'); } @@ -1016,6 +1015,12 @@ private function configurePlatformShSetup(ContainerBuilder $container): void $container->setParameter('liip_imagine_driver', 'imagick'); } } + + private function shouldLoadTestBehatServices(ContainerBuilder $container): bool + { + return $container->hasParameter('ibexa.behat.browser.enabled') + && $container->getParameter('ibexa.behat.browser.enabled'); + } } class_alias(IbexaCoreExtension::class, 'eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension'); diff --git a/tests/integration/Core/Repository/Regression/EZP20018LanguageTest.php b/tests/integration/Core/Repository/Regression/EZP20018LanguageTest.php index 87bfefc876..d5b46d5c10 100644 --- a/tests/integration/Core/Repository/Regression/EZP20018LanguageTest.php +++ b/tests/integration/Core/Repository/Regression/EZP20018LanguageTest.php @@ -9,8 +9,8 @@ use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Contracts\Core\Repository\Values\Content\Query; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LanguageCode; -use Ibexa\Solr\LegacySetupFactory; use Ibexa\Tests\Integration\Core\Repository\BaseTest; +use Ibexa\Tests\Solr\SetupFactory\LegacySetupFactory; /** * Test case for language issues in EZP-20018. diff --git a/tests/integration/Core/Repository/SearchServiceLocationTest.php b/tests/integration/Core/Repository/SearchServiceLocationTest.php index 68dfcea8f4..374ae91784 100644 --- a/tests/integration/Core/Repository/SearchServiceLocationTest.php +++ b/tests/integration/Core/Repository/SearchServiceLocationTest.php @@ -16,8 +16,8 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult; use Ibexa\Contracts\Core\Test\Repository\SetupFactory\Legacy; use Ibexa\Core\Repository\Values\Content\Location; -use Ibexa\Solr\LegacySetupFactory as LegacySolrSetupFactory; use Ibexa\Tests\Core\Repository\Common; +use Ibexa\Tests\Solr\SetupFactory\LegacySetupFactory as LegacySolrSetupFactory; /** * Test case for Location operations in the SearchService. diff --git a/tests/integration/Core/Repository/SearchServiceTest.php b/tests/integration/Core/Repository/SearchServiceTest.php index cdc4b12ea7..3cce5fae6b 100644 --- a/tests/integration/Core/Repository/SearchServiceTest.php +++ b/tests/integration/Core/Repository/SearchServiceTest.php @@ -20,8 +20,8 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult; use Ibexa\Contracts\Core\Test\Repository\SetupFactory\Legacy; -use Ibexa\Solr\LegacySetupFactory as LegacySolrSetupFactory; use Ibexa\Tests\Core\Repository\Common; +use Ibexa\Tests\Solr\SetupFactory\LegacySetupFactory as LegacySolrSetupFactory; /** * Test case for operations in the SearchService. @@ -1241,7 +1241,7 @@ public function testFindNoPerformCount() $searchHit = $searchService->findContent($query); - if ($this->getSetupFactory() instanceof Legacy) { + if ($this->isRunningOnLegacySetup()) { $this->assertNull( $searchHit->totalCount ); @@ -1257,7 +1257,7 @@ public function testFindNoPerformCountException() { $this->expectException(\RuntimeException::class); - if (!$this->getSetupFactory() instanceof Legacy) { + if (!$this->isRunningOnLegacySetup()) { $this->markTestSkipped('Only applicable to Legacy/DB based search'); } @@ -1287,7 +1287,7 @@ public function testFindLocationsNoPerformCount() $searchHit = $searchService->findLocations($query); - if ($this->getSetupFactory() instanceof Legacy) { + if ($this->isRunningOnLegacySetup()) { $this->assertNull( $searchHit->totalCount ); @@ -1303,7 +1303,7 @@ public function testFindLocationsNoPerformCountException() { $this->expectException(\RuntimeException::class); - if (!$this->getSetupFactory() instanceof Legacy) { + if (!$this->isRunningOnLegacySetup()) { $this->markTestSkipped('Only applicable to Legacy/DB based search'); } @@ -5250,6 +5250,11 @@ public function providerForTestSortingByNumericFieldsWithValuesOfDifferentLength [15, 5], ]; } + + private function isRunningOnLegacySetup(): bool + { + return get_class($this->getSetupFactory()) === Legacy::class; + } } class_alias(SearchServiceTest::class, 'eZ\Publish\API\Repository\Tests\SearchServiceTest'); diff --git a/tests/integration/Core/Repository/SearchServiceTranslationLanguageFallbackTest.php b/tests/integration/Core/Repository/SearchServiceTranslationLanguageFallbackTest.php index 3839be6492..f9a919e276 100644 --- a/tests/integration/Core/Repository/SearchServiceTranslationLanguageFallbackTest.php +++ b/tests/integration/Core/Repository/SearchServiceTranslationLanguageFallbackTest.php @@ -12,7 +12,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause; use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; -use Ibexa\Solr\LegacySetupFactory as LegacySolrSetupFactory; +use Ibexa\Tests\Solr\SetupFactory\LegacySetupFactory as LegacySolrSetupFactory; use RuntimeException; /**