Skip to content

Commit ca58949

Browse files
authored
Merge pull request #3586 from rbayet/feat_php84_compat_step_by_step
[Compat] Fixes #3578 PHP 8.4 deprecation: Implicitly marking parameter as nullable is deprecated
2 parents ddf4c73 + 4159feb commit ca58949

File tree

4 files changed

+67
-15
lines changed

4 files changed

+67
-15
lines changed

src/module-elasticsuite-catalog-graph-ql/Model/Resolver/Products/Query/Search.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
FieldSelection $fieldSelection,
8080
ProductSearch $productProvider,
8181
SearchCriteriaBuilder $searchCriteriaBuilder,
82-
Suggestions $suggestions = null
82+
?Suggestions $suggestions = null
8383
) {
8484
$this->search = $search;
8585
$this->searchResultFactory = $searchResultFactory;

src/module-elasticsuite-catalog-rule/Test/Unit/Model/Rule/Condition/Product/SpecialAttributeProviderTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Smile\ElasticsuiteCatalogRule\Test\Unit\Model\Rule\Condition\Product;
1515

16+
use Error;
1617
use PHPUnit\Framework\TestCase;
1718
use PHPUnit\Framework\Error\Warning;
1819
use Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\SpecialAttributesProvider;
@@ -33,6 +34,7 @@ class SpecialAttributeProviderTest extends TestCase
3334
* Test listing special attributes.
3435
*
3536
* @return void
37+
* @SuppressWarnings(PHPMD.ErrorControlOperator)
3638
*/
3739
public function testGetList()
3840
{
@@ -67,8 +69,14 @@ public function testGetList()
6769
$this->assertEquals('isUpdatedWithinLastXdays', $specialAttributesProvider->getAttribute('is_updated_within_last_x_days'));
6870
$this->assertEquals(StockQty::class, $specialAttributesProvider->getAttribute('stock.qty'));
6971

70-
$this->expectWarning();
71-
$this->expectWarningMessage('Undefined array key "unknownAttribute"');
72-
$specialAttributesProvider->getAttribute('unknownAttribute');
72+
/*
73+
* expectWarning and expectWarningMessage removed in PHPUnit 10
74+
* see https://github.com/sebastianbergmann/phpunit/issues/5062#issuecomment-1416362657.
75+
*/
76+
@$specialAttributesProvider->getAttribute('unknownAttribute');
77+
$lastError = error_get_last();
78+
$this->assertNotNull($lastError);
79+
$this->assertArrayHasKey('message', $lastError);
80+
$this->assertEquals('Undefined array key "unknownAttribute"', $lastError['message']);
7381
}
7482
}

src/module-elasticsuite-core/Search/Request/Query/Vector/Opensearch/Neural.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct(
7272
string $field = self::DEFAULT_EMBEDDING_FIELD,
7373
?string $name = null,
7474
float $boost = QueryInterface::DEFAULT_BOOST_VALUE,
75-
string $modelId = null
75+
?string $modelId = null
7676
) {
7777
$this->field = $field;
7878
$this->queryText = $queryText;

src/module-elasticsuite-thesaurus/Test/Unit/Plugin/QueryRewriteTest.php

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,33 @@ public function testMultipleSearchQueryDepthBuilder()
106106
* ie when the queryBuilder calls itself once for every search terms of the provided array.
107107
*/
108108
$thesaurusIndex->method('getQueryRewrites')->willReturn([]);
109+
/*
110+
* withConsecutive removed in PHPUnit 10 without any alternative \o/.
109111
$thesaurusIndex->expects($this->exactly(2))->method('getQueryRewrites')->withConsecutive(
110112
[$containerConfig, 'foo', 1],
111113
[$containerConfig, 'bar', 1],
112114
);
115+
*/
116+
$invokeCount = $this->exactly(2);
117+
$numberOfInvocationsCallback = 'numberOfInvocations';
118+
if (method_exists($invokeCount, 'getInvocationCount')) {
119+
// Method 'numberOfInvocations' only exists starting from PHPUnit 10.
120+
$numberOfInvocationsCallback = 'getInvocationCount';
121+
}
122+
$thesaurusIndex->expects($invokeCount)->method('getQueryRewrites')->willReturnCallback(
123+
function (...$expectedInputParameters) use ($invokeCount, $containerConfig, $numberOfInvocationsCallback) {
124+
if ($invokeCount->$numberOfInvocationsCallback() === 1) {
125+
$this->assertEquals($containerConfig, $expectedInputParameters[0]);
126+
$this->assertEquals('foo', $expectedInputParameters[1]);
127+
$this->assertEquals(1, $expectedInputParameters[2]);
128+
}
129+
if ($invokeCount->$numberOfInvocationsCallback() === 2) {
130+
$this->assertEquals($containerConfig, $expectedInputParameters[0]);
131+
$this->assertEquals('bar', $expectedInputParameters[1]);
132+
$this->assertEquals(1, $expectedInputParameters[2]);
133+
}
134+
}
135+
);
113136
$initialQuery = $queryBuilderInterceptor->create($containerConfig, ['foo', 'bar'], $spellingType);
114137
$this->assertEquals(QueryInterface::TYPE_BOOL, $initialQuery->getType());
115138

@@ -145,16 +168,39 @@ public function testMultipleSearchQueryDepthBuilderWithRewrites()
145168
$queryRewritePlugin = new QueryRewrite($queryFactory, $thesaurusConfigFactory, $thesaurusIndex);
146169
$queryBuilderInterceptor = $this->getQueryBuilderWithPlugin($queryFactory, $queryRewritePlugin);
147170

171+
/*
172+
* withConsecutive removed in PHPUnit 10 without any alternative \o/.
173+
* ----
148174
$thesaurusIndex->expects($this->exactly(2))->method('getQueryRewrites')->withConsecutive(
149175
[$containerConfig, 'foo', 1],
150176
[$containerConfig, 'bar', 1],
151-
)->willReturnMap(
152-
[
153-
[$containerConfig, 'foo', 1, ['foo bar' => 0.1]],
154-
[$containerConfig, 'bar', 1, ['bar fight' => 0.1]],
155-
]
156-
);
177+
*/
178+
$invokeCount = $this->exactly(2);
179+
$numberOfInvocationsCallback = 'numberOfInvocations';
180+
if (method_exists($invokeCount, 'getInvocationCount')) {
181+
// Method 'numberOfInvocations' only exists starting from PHPUnit 10.
182+
$numberOfInvocationsCallback = 'getInvocationCount';
183+
}
184+
$thesaurusIndex->expects($invokeCount)->method('getQueryRewrites')->willReturnCallback(
185+
function (...$expectedInputParameters) use ($invokeCount, $containerConfig, $numberOfInvocationsCallback) {
186+
if ($invokeCount->$numberOfInvocationsCallback() === 1) {
187+
$this->assertEquals($containerConfig, $expectedInputParameters[0]);
188+
$this->assertEquals('foo', $expectedInputParameters[1]);
189+
$this->assertEquals(1, $expectedInputParameters[2]);
190+
191+
return ['foo bar' => 0.1];
192+
}
193+
if ($invokeCount->$numberOfInvocationsCallback() === 2) {
194+
$this->assertEquals($containerConfig, $expectedInputParameters[0]);
195+
$this->assertEquals('bar', $expectedInputParameters[1]);
196+
$this->assertEquals(1, $expectedInputParameters[2]);
157197

198+
return ['bar fight' => 0.1];
199+
}
200+
201+
return [];
202+
}
203+
);
158204
$query = $queryBuilderInterceptor->create($containerConfig, ['foo', 'bar'], $spellingType);
159205
$this->assertEquals(QueryInterface::TYPE_BOOL, $query->getType());
160206
}
@@ -181,14 +227,12 @@ public function testSingleSearchQueryLimitedRewrites()
181227
->disableOriginalConstructor()
182228
->getMock();
183229

184-
// Passing the mock Query Factory to the plugin to count the occurence of calls to 'create'.
230+
// Passing the mock Query Factory to the plugin to count the occurrence of calls to 'create'.
185231
$queryRewritePlugin = new QueryRewrite($queryFactoryFullMock, $thesaurusConfigFactory, $thesaurusIndex);
186232
// But passing the real Query Factory (with mocked factories) to the query builder itself.
187233
$queryBuilderInterceptor = $this->getQueryBuilderWithPlugin($queryFactory, $queryRewritePlugin);
188234

189-
$thesaurusIndex->expects($this->exactly(1))->method('getQueryRewrites')->withConsecutive(
190-
[$containerConfig, 'foo', 1]
191-
)->willReturnMap(
235+
$thesaurusIndex->expects($this->exactly(1))->method('getQueryRewrites')->willReturnMap(
192236
[
193237
[$containerConfig, 'foo', 1, ['foo bar' => 0.1, 'foo light' => 0.1, 'moo' => 0.1, 'moo bar' => 0.01]],
194238
]

0 commit comments

Comments
 (0)