Skip to content

Commit

Permalink
Merge branch '4.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p committed Oct 5, 2022
2 parents b5ccc4c + 1b7b566 commit b576e91
Show file tree
Hide file tree
Showing 11 changed files with 2,688 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ jobs:
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPStan analysis
run: composer run-script phpstan

- name: Run unit test suite
run: composer test
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"ibexa/doctrine-schema": "~4.3.0@dev",
"phpunit/phpunit": "^8.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"ibexa/code-style": "^1.0"
"ibexa/code-style": "^1.0",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-symfony": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -59,7 +62,8 @@
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
"check-cs": "php-cs-fixer fix --dry-run -v --show-progress=dots",
"test": "phpunit --bootstrap tests/bootstrap.php -c phpunit.xml",
"test-integration-solr": "phpunit --bootstrap tests/bootstrap.php -c vendor/ibexa/core/phpunit-integration-legacy-solr.xml"
"test-integration-solr": "phpunit --bootstrap tests/bootstrap.php -c vendor/ibexa/core/phpunit-integration-legacy-solr.xml",
"phpstan": "phpstan analyse"
},
"extra": {
"branch-alias": {
Expand Down
17 changes: 17 additions & 0 deletions ignore-by-php-version.neon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

$includes = [];
if (PHP_VERSION_ID < 80000) {
$includes[] = __DIR__ . '/ignore-lte-php7.4-errors.neon';
}

$config = [];
$config['includes'] = $includes;

return $config;
6 changes: 6 additions & 0 deletions ignore-lte-php7.4-errors.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Anonymous function should return array but returns array\\<string\\>\\|false\\.$#"
count: 1
path: tests/lib/Search/ResultExtractor/AggregationResultExtractor/TermAggregationResultExtractorTest.php
2,511 changes: 2,511 additions & 0 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
includes:
- ignore-by-php-version.neon.php
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- phpstan-baseline.neon

parameters:
ignoreErrors:
-
message: "#^Cannot call method (fetchOne|fetchAll|fetchAllAssociative|fetchAssociative|fetchAllKeyValue)\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
paths:
- tests/*
level: 8
paths:
- src
- tests
treatPhpDocTypesAsCertain: false
25 changes: 25 additions & 0 deletions src/bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

class Configuration implements ConfigurationInterface
{
public const SOLR_HTTP_CLIENT_DEFAULT_TIMEOUT = 10;
public const SOLR_HTTP_CLIENT_DEFAULT_MAX_RETRIES = 3;

protected $rootNodeName;

/**
Expand Down Expand Up @@ -46,6 +49,7 @@ public function getConfigTreeBuilder()

$this->addEndpointsSection($rootNode);
$this->addConnectionsSection($rootNode);
$this->addHttpClientConfigurationSection($rootNode);

return $treeBuilder;
}
Expand Down Expand Up @@ -392,6 +396,27 @@ function (array $v) {
->end()
->end();
}

private function addHttpClientConfigurationSection(ArrayNodeDefinition $node): void
{
$node->children()
->arrayNode('http_client')
->info('Configuration settings for HTTP Client used to communicate with Solr instance')
->children()
->integerNode('timeout')
->info('HTTP Client timeout')
->min(0)
->defaultValue(self::SOLR_HTTP_CLIENT_DEFAULT_TIMEOUT)
->end()
->integerNode('max_retries')
->info('HTTP Client max retries after failure')
->min(0)
->defaultValue(self::SOLR_HTTP_CLIENT_DEFAULT_MAX_RETRIES)
->end()
->end()
->end()
->end();
}
}

class_alias(Configuration::class, 'EzSystems\EzPlatformSolrSearchEngineBundle\DependencyInjection\Configuration');
19 changes: 19 additions & 0 deletions src/bundle/DependencyInjection/IbexaSolrExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* @phpstan-type SolrHttpClientConfigArray = array{timeout: int, max_retries: int}
*/
class IbexaSolrExtension extends Extension
{
/**
Expand Down Expand Up @@ -175,6 +178,10 @@ protected function processConnectionConfiguration(ContainerBuilder $container, a
// Factory for BoostFactorProvider uses mapping configured for the connection in use
$boostFactorProviderDef = $container->findDefinition(self::BOOST_FACTOR_PROVIDER_ID);
$boostFactorProviderDef->setFactory([new Reference(BoostFactorProviderFactory::class), 'buildService']);

if (isset($config['http_client'])) {
$this->configureHttpClient($container, $config['http_client']);
}
}

/**
Expand Down Expand Up @@ -321,6 +328,18 @@ protected function buildBoostFactorMap(array $config)

return $boostFactorMap;
}

/**
* @phpstan-param SolrHttpClientConfigArray $httpClientConfig
*/
private function configureHttpClient(ContainerBuilder $container, array $httpClientConfig): void
{
$container->setParameter('ibexa.solr.http_client.timeout', $httpClientConfig['timeout']);
$container->setParameter(
'ibexa.solr.http_client.max_retries',
$httpClientConfig['max_retries']
);
}
}

class_alias(IbexaSolrExtension::class, 'EzSystems\EzPlatformSolrSearchEngineBundle\DependencyInjection\EzSystemsEzPlatformSolrSearchEngineExtension');
29 changes: 28 additions & 1 deletion src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
parameters:
ibexa.solr.default_connection: ~
ibexa.solr.http_client.timeout: !php/const \EzSystems\EzPlatformSolrSearchEngineBundle\DependencyInjection\Configuration::SOLR_HTTP_CLIENT_DEFAULT_TIMEOUT
ibexa.solr.http_client.max_retries: !php/const \EzSystems\EzPlatformSolrSearchEngineBundle\DependencyInjection\Configuration::SOLR_HTTP_CLIENT_DEFAULT_MAX_RETRIES

services:
ibexa.solr.http_client.retryable:
class: Symfony\Component\HttpClient\RetryableHttpClient
decorates: ibexa.solr.http_client
arguments:
$client: '@.inner'
$strategy: null
$maxRetries: '%ibexa.solr.http_client.max_retries%'
$logger: '@?logger'
tags:
- { name: monolog.logger, channel: ibexa.solr }

ibexa.solr.http_client:
class: Symfony\Contracts\HttpClient\HttpClientInterface
factory: [ \Symfony\Component\HttpClient\HttpClient, 'create' ]
calls:
- setLogger: [ '@logger' ]
tags:
- { name: monolog.logger, channel: ibexa.solr }

Ibexa\Solr\Gateway\HttpClient\Stream:
autoconfigure: true
arguments:
$client: '@ibexa.solr.http_client'
$timeout: '%ibexa.solr.http_client.timeout%'

Ibexa\Bundle\Solr\ApiLoader\SolrEngineFactory:
arguments:
$repositoryConfigurationProvider: '@Ibexa\Bundle\Core\ApiLoader\RepositoryConfigurationProvider'
Expand Down Expand Up @@ -31,7 +58,7 @@ services:
- [setContainer, ["@service_container"]]

Ibexa\Solr\FieldMapper\IndexingDepthProvider:
class: \Ibexa\Solr\FieldMapper\IndexingDepthProvider
class: Ibexa\Solr\FieldMapper\IndexingDepthProvider
factory: ['@Ibexa\Bundle\Solr\ApiLoader\IndexingDepthProviderFactory', 'buildService']

ibexa.solr.gateway.distribution_strategy.abstract_standalone:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\UserMetadataTermAggregation;
use Ibexa\Contracts\Solr\ResultExtractor\AggregationResultExtractor\TermAggregationKeyMapper;
use InvalidArgumentException;

final class UserMetadataAggregationKeyMapper implements TermAggregationKeyMapper
{
Expand Down Expand Up @@ -49,13 +50,22 @@ public function map(Aggregation $aggregation, array $languageFilter, array $keys

private function resolveKeyLoader(Aggregation $aggregation): callable
{
switch ($aggregation->getType()) {
$type = $aggregation->getType();
switch ($type) {
case UserMetadataTermAggregation::OWNER:
case UserMetadataTermAggregation::MODIFIER:
return [$this->userService, 'loadUser'];
case UserMetadataTermAggregation::GROUP:
return [$this->userService, 'loadUserGroup'];
}

throw new InvalidArgumentException(sprintf(
'Expected one of: "%s". Received "%s"',
implode('", "', [
UserMetadataTermAggregation::OWNER, UserMetadataTermAggregation::MODIFIER, UserMetadataTermAggregation::GROUP,
]),
$type,
));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
*/
namespace Ibexa\Tests\Bundle\Solr\DependencyInjection;

use Ibexa\Bundle\Solr\DependencyInjection\Configuration;
use Ibexa\Bundle\Solr\DependencyInjection\IbexaSolrExtension;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

/**
* @phpstan-import-type SolrHttpClientConfigArray from IbexaSolrExtension
*/
class IbexaSolrExtensionExtensionTest extends AbstractExtensionTestCase
{
/**
Expand Down Expand Up @@ -646,6 +650,47 @@ public function testBoostFactorMap(array $configuration, array $map)
$map
);
}

/**
* @dataProvider getDataForTestHttpClientConfiguration
*
* @phpstan-param SolrHttpClientConfigArray $httpClientConfig
*/
public function testHttpClientConfiguration(array $config): void
{
$this->load(
[
'http_client' => $config,
]
);

$this->assertContainerBuilderHasParameter(
'ibexa.solr.http_client.timeout',
$config['timeout'],
);

$this->assertContainerBuilderHasParameter(
'ibexa.solr.http_client.max_retries',
$config['max_retries'],
);
}

public function getDataForTestHttpClientConfiguration(): iterable
{
yield 'default values' => [
[
'timeout' => Configuration::SOLR_HTTP_CLIENT_DEFAULT_TIMEOUT,
'max_retries' => Configuration::SOLR_HTTP_CLIENT_DEFAULT_MAX_RETRIES,
],
];

yield 'custom values' => [
[
'timeout' => 16,
'max_retries' => 2,
],
];
}
}

class_alias(IbexaSolrExtensionExtensionTest::class, 'EzSystems\EzPlatformSolrSearchEngineBundle\Tests\DependencyInjection\EzPublishEzPlatformSolrSearchEngineExtensionTest');

0 comments on commit b576e91

Please sign in to comment.