Skip to content

Commit 7251237

Browse files
committed
NEXT-13918 - Fix deprecations in migration, storefront and integration suites
1 parent bf6e010 commit 7251237

22 files changed

+104
-70
lines changed

.gitlab/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ecs.php @product/enginee
2727
phpstan.neon @product/engineering/platform-group/core
2828
phpunit.xml.dist @product/engineering/platform-group/core
2929
.bc-exclude.php @product/engineering/platform-group/core
30+
deprecation.ignore @product/engineering/platform-group/core
3031
/src/Core/Framework/Resources/config/packages/shopware.yaml @product/engineering/platform-group/core
3132
/src/Core/Framework/Resources/**/feature.yaml
3233
# shared code ownership of multiple groups seems only to work for the last entries

.gitlab/stages/20-unit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ PHP Full:
288288
- >
289289
if [ "$PREFER_LOWEST" == "true" ]; then
290290
composer update --prefer-lowest --optimize-autoloader
291+
# disable symfony deprecation check, when running with lowest dependency versions
292+
export SYMFONY_DEPRECATIONS_HELPER=disabled
291293
fi
292294
- >
293295
if [ "$ONLY_CORE" == "true" ]; then

adr/testing/2022-10-20-deprecation-handling-during-phpunit-test-execution.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
## Context
44

5-
To stay innovative and on the bleeding edge of technology it is important, that to don't rely on deprecated functionality, as it prevents you from using the latest and greatest versions of libraries, that may include important bug fixes, performance improvements or new features.
5+
To stay innovative and on the bleeding edge of technology it is important, that we don't rely on deprecated functionality, as it prevents us from using the latest and greatest versions of libraries, that may include important bug fixes, performance improvements or new features.
66
Relying on deprecated functionality makes continuously upgrading the dependencies harder, as you have a lot of work to remove the deprecated usages before being able to do the upgrades.
7-
This is not just important for external dependencies, but also for internal deprecations, as when we still rely on some deprecated functionality it makes removing the deprecation very hard.
7+
This is not just important for external dependencies, but also for internal deprecations, that is we still rely on some deprecated functionality it makes removing the deprecation very hard.
88

99
One opportunity is to rely on our PHPUnit test suite to detect usages of deprecated functionality, so we can continuously remove them as they appear and ensure that the code base is always forward compatible.
1010

1111
## Solution
1212

1313
Because the handling for internal and external deprecations is quite different we probably need different solutions for those cases.
14-
Especially as for internal deprecations we still want to ensure that they continue working and that those deprecated code paths are also covered by tests.
14+
Especially as for internal deprecations we still want to ensure that they continue to work and that those deprecated code paths are also covered by tests.
1515

1616
### Using Symfony's Deprecation Helper for external deprecations
1717

1818
Symfony offers a tool to report all deprecations that are encountered when running the test inside their [PHPUnit Bridge](https://symfony.com/doc/current/components/phpunit_bridge.html).
19-
With enabling the [`SYMFONY_DEPRECATIONS_HELPER`](https://symfony.com/doc/current/components/phpunit_bridge.html#trigger-deprecation-notices) fo our testsuite we can ensure that no deprecations are triggered while executing the tests.
19+
With enabling the [`SYMFONY_DEPRECATIONS_HELPER`](https://symfony.com/doc/current/components/phpunit_bridge.html#trigger-deprecation-notices) for our testsuite we can ensure that no deprecations are triggered while executing the tests.
2020
Previously we could not enable this as it also reported all deprecation usages for internal deprecations and also reported on deprecations that were triggered from inside external dependencies that we could not fix from inside shopware.
2121

2222
But since lately a feature was added to use a [`ignoreFile`](https://symfony.com/doc/current/components/phpunit_bridge.html#ignoring-deprecations), in order to ignore specific deprecations by regex.
@@ -28,9 +28,9 @@ We leverage this feature by using it in a way to ignore all deprecations that we
2828

2929
### Using our Feature Flag system for internal deprecations
3030

31-
Internally we use the feature flag system to trigger deprecations messages, or throw exceptions if the major feature flag is activated as explained in the [deprecation handling ADR](../workflow/2022-02-28-consistent-deprecation-notices-in-core.md).
31+
Internally we use the feature flag system to trigger deprecation messages, or throw exceptions if the major feature flag is activated as explained in the [deprecation handling ADR](../workflow/2022-02-28-consistent-deprecation-notices-in-core.md).
3232
We already use that system in our new unit test suite with a custom `@ActiveFeatures()` annotations, that allows us to run single test cases with a specific set of feature flags.
33-
But the current implementation has the big drawback that feature flags have to actively be enabled, this leads to following problems:
33+
But the current implementation has the big drawback that feature flags have to be actively enabled, this leads to following problems:
3434
1. There are already tests that are not passing after all deprecations are removed, because they rely on deprecated behaviour.
3535
2. We can't check automatically that our implementation is forward compatible, as the default way of executing tests is without any major flag activated.
3636
3. It is hard to directly see which test cases are there only to cover legacy/deprecated functionality and can safely be removed after the deprecations are removed.
@@ -39,5 +39,5 @@ Therefore, the workflow is updated in the following way:
3939
1. All unit tests get executed with all major feature flags activated.
4040
2. The `@ActiveFeatures()` will be removed, and we introduce a `@DisableFeatures` annotation, that works in the exact opposite way => disabling all feature flags that are passed.
4141

42-
This has the upside that now the default behaviour of our test suite is the new/not-deprecated behaviour, and the deprecated code paths are treated as teh exceptional case instead the other way around.
42+
This has the upside that now the default behaviour of our test suite is the new/not-deprecated behaviour, and the deprecated code paths are treated as the exceptional case instead the other way around.
4343
Additionally, all tests that are relying on deprecated behaviour are marked with the `@DisableFeatures` annotations, so it is easy to detect them and simply remove them, if the underlying deprecation was removed.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
"brianium/paratest": "^6.2",
159159
"dg/bypass-finals": "^1.3",
160160
"dms/phpunit-arraysubset-asserts": "^0.2.1",
161-
"fakerphp/faker": "~1.14.1",
161+
"fakerphp/faker": "^1.20",
162162
"johnkary/phpunit-speedtrap": "~4.0.0",
163163
"league/construct-finder": "^1.1",
164164
"maltyxx/images-generator": "~1.0.0",

deprecation-baseline.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

deprecation.ignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
%mb_strtolower\(\)\: Passing null to parameter #1 \(\$string\) of type string is deprecated%
1616
# Triggered by MessengerEnqueueTransport, which we will remove in 6.5
1717
%Enqueue\\MessengerAdapter\\EnvelopeItem\\TransportConfiguration%
18+
# should be fixed with NEXT-23859
19+
%Returning a file to import for CSS or external references in custom importer callables is deprecated%

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
<server name="HTTPS" value="off"/>
8787
<!--To see the full stackTrace of a Deprecation set the value to a regex matching the deprecation warning-->
8888
<!--https://symfony.com/doc/current/components/phpunit_bridge.html#display-the-full-stack-trace-->
89-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="baselineFile=./deprecation-baseline.json&amp;ignoreFile=./deprecation.ignore" />
90-
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="/fetchFirstColumn/" />-->
89+
<!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=./deprecation.ignore" />-->
90+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
9191
</php>
9292
<testsuites>
9393
<testsuite name="administration">

src/Core/Checkout/Customer/Api/CustomerGroupRegistrationActionController.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ private function getRequestCustomerIds(Request $request): array
162162

163163
$requestCustomerIds = $request->request->all('customerIds');
164164

165-
if (\is_string($requestCustomerIds)) {
166-
$requestCustomerIds = \json_decode($requestCustomerIds, true);
167-
}
168-
169165
if (!empty($requestCustomerIds)) {
170166
$customerIds = array_unique(array_merge($customerIds, $requestCustomerIds));
171167
}

src/Core/Content/Product/SearchKeyword/ProductSearchKeywordAnalyzer.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@ class ProductSearchKeywordAnalyzer implements ProductSearchKeywordAnalyzerInterf
1313
{
1414
private const MAXIMUM_KEYWORD_LENGTH = 500;
1515

16-
/**
17-
* @var TokenizerInterface
18-
*/
19-
private $tokenizer;
16+
private TokenizerInterface $tokenizer;
2017

21-
/**
22-
* @var AbstractTokenFilter
23-
*/
24-
private $tokenFilter;
18+
private AbstractTokenFilter $tokenFilter;
2519

2620
/**
2721
* @internal
@@ -47,24 +41,29 @@ public function analyze(ProductEntity $product, Context $context, array $configF
4741
$values = array_filter($this->resolveEntityValue($product, $path));
4842

4943
if ($isTokenize) {
50-
try {
51-
$values = $this->tokenize($values, $context);
52-
} catch (\Throwable $error) {
53-
// Can occur if the resolved value is a nested array. This prevents the implode() from being executed. We ignore this error at this point to allow some error tolerance in the configuration
44+
$nonScalarValues = array_filter($values, function ($value) {
45+
return !\is_scalar($value);
46+
});
47+
48+
if ($nonScalarValues !== []) {
5449
continue;
5550
}
51+
52+
/** @var array<int, string> $onlyScalarValues */
53+
$onlyScalarValues = $values;
54+
$values = $this->tokenize($onlyScalarValues, $context);
5655
}
5756

5857
foreach ($values as $value) {
59-
try {
60-
// even the field is non tokenize, if it reached 500 chars, we should break it anyway
61-
$parts = array_filter(mb_str_split((string) $value, self::MAXIMUM_KEYWORD_LENGTH));
58+
if (!\is_scalar($value)) {
59+
continue;
60+
}
6261

63-
foreach ($parts as $part) {
64-
$keywords->add(new AnalyzedKeyword((string) $part, $ranking));
65-
}
66-
} catch (\Throwable $error) {
67-
// Can occur if the resolved value is a nested array. This prevents the string cast from being executed (Array to string conversion). We ignore this error at this point to allow some error tolerance in the configuration
62+
// even the field is non tokenize, if it reached 500 chars, we should break it anyway
63+
$parts = array_filter(mb_str_split((string) $value, self::MAXIMUM_KEYWORD_LENGTH));
64+
65+
foreach ($parts as $part) {
66+
$keywords->add(new AnalyzedKeyword((string) $part, $ranking));
6867
}
6968
}
7069
}
@@ -87,7 +86,7 @@ private function tokenize(array $values, Context $context): array
8786
}
8887

8988
/**
90-
* @return array<int, string>
89+
* @return array<int, string|array<mixed>>
9190
*/
9291
private function resolveEntityValue(Entity $entity, string $path): array
9392
{

src/Core/Content/Test/Media/Api/MediaUploadControllerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ private function getMediaEntity(): MediaEntity
269269

270270
static::assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode(), (string) $response->getContent());
271271

272-
273272
$location = $response->headers->get('Location');
274273
static::assertIsString($location);
275274
static::assertStringEndsWith(

0 commit comments

Comments
 (0)