Skip to content

Commit 4572a90

Browse files
committed
NEXT-25276 - phpunit v10 update remaining tasks
- Migrated extension - Fixed and refactored unit tests - Fixed phpstan errors
1 parent b96697d commit 4572a90

File tree

197 files changed

+1282
-879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+1282
-879
lines changed

.gitlab/stages/20-unit.yml

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ PHP integration:
6666
FEATURE_ALL: "major"
6767
GIT_DEPTH: 0 # we need all commits for composer to detect the version which is then checked in a unit test
6868
REDIS_URL: redis://redis:6379
69+
SYMFONY_DEPRECATIONS_HELPER: "disabled" # remove line when phpunit-bridge supports phpunit 10
6970
rules:
7071
# do not run in merge trains - PHP Full should cover all tests
7172
- if: $CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"
@@ -158,6 +159,7 @@ PHP unit coverage:
158159
services: []
159160
variables:
160161
APP_ENV: "test"
162+
SYMFONY_DEPRECATIONS_HELPER: "disabled" # remove line when phpunit-bridge supports phpunit 10
161163
rules:
162164
- !reference [.rules, skip]
163165
- !reference [.rules, run]
@@ -201,6 +203,7 @@ PHP migration coverage:
201203
variables:
202204
APP_ENV: "test"
203205
FEATURE_ALL: "false"
206+
SYMFONY_DEPRECATIONS_HELPER: "disabled" # remove line when phpunit-bridge supports phpunit 10
204207
rules:
205208
- !reference [.rules, skip]
206209
- !reference [.rules, run]
@@ -245,6 +248,7 @@ PHP Full:
245248
REDIS_URL: redis://redis:6379
246249
SWAGGER_VALIDATOR_URL: http://swagger:8080/validator/debug
247250
FEATURE_ALL: 'false'
251+
SYMFONY_DEPRECATIONS_HELPER: "disabled" # remove line when phpunit-bridge supports phpunit 10
248252
rules:
249253
- !reference [.rules, skip]
250254
- if: !reference [.rules, run-allow-failure, if ]

UPGRADE-6.1.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Core
132132
// or with a static plugin list
133133
$plugins = [
134134
[
135-
'baseClass' => 'SwagTest\\SwagTest',
135+
'baseClass' => 'SwagTest\\SwagTestPlugin',
136136
'active' => true,
137137
'path' => 'platform/src/Core/Framework/Test/Plugin/_fixture/plugins/SwagTest',
138138
'autoload' => ['psr-4' => ['SwagTest\\' => 'src/']],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Updated PHPUnit to version 10+
3+
issue: NEXT-25276
4+
author: Jozsef Damokos
5+
author_email: [email protected]
6+
author_github: jozsefdamokos
7+
---
8+
# Core
9+
* Added support for PHPUnit v10+. Changed all `@covers` annotations to attributes. Migrated extensions.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
"ezyang/htmlpurifier": "^4.16",
7373
"guzzlehttp/guzzle": "^7.5.0",
7474
"guzzlehttp/psr7": "^2.4",
75-
"lcobucci/clock": "^3.1.0",
7675
"lcobucci/jwt": "^5.0",
76+
"lcobucci/clock": "^3.1.0",
7777
"league/flysystem": "^3.10.3",
7878
"league/flysystem-memory": "^3.10.3",
7979
"league/mime-type-detection": "^1.13.0",

phpstan-baseline.neon

-10
Original file line numberDiff line numberDiff line change
@@ -2660,11 +2660,6 @@ parameters:
26602660
count: 2
26612661
path: src/Core/Content/Test/Media/Aggregate/MediaFolderConfigurationThumbnailSize/MediaFolderConfigurationMediaThumbnailSizeTest.php
26622662

2663-
-
2664-
message: "#^Cannot call method all\\(\\) on Shopware\\\\Core\\\\Content\\\\Cms\\\\DataResolver\\\\CriteriaCollection\\|null\\.$#"
2665-
count: 1
2666-
path: src/Core/Content/Test/Media/Cms/Type/ImageTypeDataResolverTest.php
2667-
26682663
-
26692664
message: "#^Cannot call method getFileExtension\\(\\) on Shopware\\\\Core\\\\Content\\\\Media\\\\MediaEntity\\|null\\.$#"
26702665
count: 1
@@ -2690,11 +2685,6 @@ parameters:
26902685
count: 1
26912686
path: src/Core/Content/Test/Media/Cms/Type/ImageTypeDataResolverTest.php
26922687

2693-
-
2694-
message: "#^Parameter \\#2 \\$haystack of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertCount\\(\\) expects Countable\\|iterable, Shopware\\\\Core\\\\Content\\\\Cms\\\\DataResolver\\\\CriteriaCollection\\|null given\\.$#"
2695-
count: 1
2696-
path: src/Core/Content/Test/Media/Cms/Type/ImageTypeDataResolverTest.php
2697-
26982688
-
26992689
message: "#^Cannot call method getConfigurationId\\(\\) on Shopware\\\\Core\\\\Framework\\\\DataAbstractionLayer\\\\Entity\\|null\\.$#"
27002690
count: 6

phpstan.neon.dist

-4
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ parameters:
170170
- src/Core/Checkout/Payment/PaymentMethodDefinition.php
171171
- src/Core/System/NumberRange/NumberRangeDefinition.php
172172

173-
- # NEXT-25276 - Needs to be fixed with the update ot PHPUnit 10
174-
message: '#deprecated interface PHPUnit\\Framework\\TestListener#'
175-
path: src/Core/Test/PHPUnit/Extension/DatadogListener.php
176-
177173
# Internal deprecations of Shopware are handled in other places
178174
- '#deprecated.*class Shopware\\#'
179175

phpunit.xml.dist

+4-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@
5858
</testsuites>
5959
<extensions>
6060
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
61-
<!-- <extension class="Shopware\Core\Test\PHPUnit\Extension\FeatureFlagExtension"/>-->
62-
<!--Enable to see the db sideeffects of the tests. -->
63-
<!--<extension class="Shopware\Core\Framework\Test\TestCaseBase\DatabaseCleanTestExtension" />-->
61+
<bootstrap class="Shopware\Core\Test\PHPUnit\Extension\FeatureFlag\FeatureFlagExtension"/>
62+
<bootstrap class="Shopware\Core\Test\PHPUnit\Extension\Datadog\DatadogExtension"/>
63+
<!-- Enable to see the db side effects of the tests. -->
64+
<!-- <bootstrap class="Shopware\Core\Test\PHPUnit\Extension\DatabaseDiff\DatabaseDiffExtension"/>-->
6465
</extensions>
6566
<source>
6667
<include>

rector.php

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
]
3939
);
4040

41+
// PHPUnit v10 update
42+
// $rectorConfig->rule(\Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector::class);
43+
// $rectorConfig->rule(\Rector\PHPUnit\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector::class);
44+
// $rectorConfig->rule(\Rector\PHPUnit\AnnotationsToAttributes\Rector\ClassMethod\DependsAnnotationWithValueToAttributeRector::class);
45+
// $rectorConfig->rule(\Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector::class);
46+
4147
// $rectorConfig->rule(ClassPackageRector::class);
4248
// $rectorConfig->ruleWithConfiguration(
4349
// ChangeMethodVisibilityRector::class,

src/Core/Content/Test/Cms/SlotDataResolver/CriteriaCollectionTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testAddSingleCriteria(): void
2424
static::assertCount(1, $collection->all());
2525

2626
// test iterator
27-
static::assertCount(1, $collection);
27+
static::assertCount(1, iterator_to_array($collection));
2828
}
2929

3030
public function testAddMultipleCriteriaOfDifferentDefinition(): void
@@ -38,7 +38,7 @@ public function testAddMultipleCriteriaOfDifferentDefinition(): void
3838
static::assertCount(3, $collection->all());
3939

4040
// test iterator
41-
static::assertCount(3, $collection);
41+
static::assertCount(3, iterator_to_array($collection));
4242
}
4343

4444
public function testAddMultipleCriteriaOfSameDefinition(): void
@@ -52,7 +52,7 @@ public function testAddMultipleCriteriaOfSameDefinition(): void
5252
static::assertCount(1, $collection->all());
5353

5454
// test iterator
55-
static::assertCount(1, $collection);
55+
static::assertCount(1, iterator_to_array($collection));
5656

5757
// test indexed by definition
5858
static::assertCount(3, $collection->all()[ProductDefinition::class]);

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\Attributes\CoversClass;
66
use PHPUnit\Framework\TestCase;
7+
use Shopware\Core\Content\Media\Api\MediaUploadController;
78
use Shopware\Core\Content\Media\Event\MediaUploadedEvent;
89
use Shopware\Core\Content\Media\MediaEntity;
910
use Shopware\Core\Content\Media\MediaType\ImageType;

src/Core/Content/Test/Media/Cms/Type/ImageSliderTypeDataResolverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testCollectWithStaticConfig(): void
8383

8484
$criteriaCollection = $this->imageSliderResolver->collect($slot, $resolverContext);
8585
static::assertNotNull($criteriaCollection);
86-
static::assertCount(1, $criteriaCollection);
86+
static::assertCount(1, iterator_to_array($criteriaCollection));
8787

8888
$expectedCriteria = new Criteria(['media123', 'media456']);
8989

src/Core/Content/Test/Media/Cms/Type/ImageTypeDataResolverTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public function testCollectWithMediaId(): void
8080

8181
$criteriaCollection = $this->imageResolver->collect($slot, $resolverContext);
8282

83-
static::assertCount(1, $criteriaCollection);
83+
static::assertNotNull($criteriaCollection);
84+
static::assertCount(1, iterator_to_array($criteriaCollection));
8485

8586
$expectedCriteria = new Criteria(['media123']);
8687

src/Core/Content/Test/Media/File/FileSaverTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public function testPersistFileToMediaDoesNotAddSuffixOnReplacement(): void
242242
$this->getPublicFilesystem()->writeStream($pathName, $resource);
243243

244244
static::assertIsString($png->getFileName());
245+
static::assertNotEmpty($png->getFileName());
245246

246247
try {
247248
$this->fileSaver->persistFileToMedia(

src/Core/Content/Test/Newsletter/SalesChannel/NewsletterUnsubscribeRouteTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPUnit\Framework\Attributes\CoversClass;
77
use PHPUnit\Framework\TestCase;
88
use Shopware\Core\Content\Newsletter\Event\NewsletterUnsubscribeEvent;
9+
use Shopware\Core\Content\Newsletter\SalesChannel\NewsletterUnsubscribeRoute;
910
use Shopware\Core\Framework\Log\Package;
1011
use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour;
1112
use Shopware\Core\Framework\Test\TestCaseBase\SalesChannelApiTestBehaviour;

src/Core/Content/Test/Seo/SeoUrlUpdaterTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ protected function setUp(): void
103103
* Checks whether the seo url updater is using the correct language for translations.
104104
*
105105
* @param list<string> $translations
106+
* @param non-empty-string $pathInfo
106107
*/
107108
#[DataProvider('seoLanguageDataProvider')]
108109
public function testSeoLanguageInheritance(array $translations, string $pathInfo): void
@@ -165,7 +166,7 @@ public function testSeoLanguageInheritance(array $translations, string $pathInfo
165166
}
166167

167168
/**
168-
* @return list<array{translations: list<string>, pathInfo: string}>
169+
* @return list<array{translations: list<string>, pathInfo: non-empty-string}>
169170
*/
170171
public static function seoLanguageDataProvider(): array
171172
{

src/Core/DevOps/StaticAnalyze/Coverage/Command/GetClassesPerAreaCommand.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
111111
if ($unitDocument === null) {
112112
return 1;
113113
}
114-
$coverage = $unitDocument->getElementsByTagName('coverage')->item(0);
115-
if ($coverage === null) {
114+
$source = $unitDocument->getElementsByTagName('source')->item(0);
115+
if ($source === null) {
116116
return 1;
117117
}
118-
$includeChildElement = $coverage->getElementsByTagName('include')->item(0);
118+
$includeChildElement = $source->getElementsByTagName('include')->item(0);
119119
if ($includeChildElement === null) {
120120
return 1;
121121
}
122-
// Remove include from coverage to create our own includes
123-
$coverage->removeChild($includeChildElement);
122+
// Remove include from source to create our own includes
123+
$source->removeChild($includeChildElement);
124124
$includeElement = $unitFile->createElement('include');
125125

126126
foreach ($classToFile as $class => $file) {
127127
$fileElement = $unitFile->createElement('file', $file);
128128
$includeElement->appendChild($fileElement);
129129
}
130-
$coverage->appendChild($includeElement);
130+
$source->appendChild($includeElement);
131131

132132
// Create phpunit file per area
133133
file_put_contents("phpunit.$area.xml", $unitFile->saveXML());

src/Core/DevOps/StaticAnalyze/PHPStan/Rules/Tests/CoversAttributeRule.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use PHPStan\Node\InClassNode;
88
use PHPStan\Rules\Rule;
99
use PHPStan\Rules\RuleError;
10+
use PHPUnit\Framework\Attributes\CoversClass;
11+
use PHPUnit\Framework\Attributes\CoversFunction;
12+
use PHPUnit\Framework\Attributes\CoversNothing;
1013
use PHPUnit\Framework\TestCase;
1114
use Shopware\Core\Framework\Log\Package;
1215

@@ -35,7 +38,7 @@ public function processNode(Node $node, Scope $scope): array
3538
}
3639

3740
if ($this->isTestClass($node)) {
38-
return ['Test classes must have @covers annotation'];
41+
return ['Test classes must have CoversClass, CoversFunction or CoversNothing attribute'];
3942
}
4043

4144
return [];
@@ -64,17 +67,11 @@ private function hasCovers(InClassNode $class): bool
6467
/** @var Node\Name\FullyQualified $name */
6568
$name = $attribute->name;
6669

67-
if ($name->toString() === 'PHPUnit\Metadata\CoversClass\CoversClass') {
70+
if (\in_array($name->toString(), [CoversClass::class, CoversFunction::class, CoversNothing::class], true)) {
6871
return true;
6972
}
7073
}
7174

72-
$doc = $class->getDocComment();
73-
74-
if ($doc === null) {
75-
return false;
76-
}
77-
78-
return \str_contains($doc->getText(), '@covers') || \str_contains($doc->getText(), '@coversNothing');
75+
return false;
7976
}
8077
}

src/Core/Framework/Test/DataAbstractionLayer/Dbal/CriteriaQueryHelperTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testSortByScoreIfScoreQueryIsSet(): void
6868
$productDefinition = $this->getContainer()->get(ProductDefinition::class);
6969
$criteria = new Criteria();
7070
$criteria->addQuery(new ScoreQuery(new ContainsFilter('name', 'test matching'), 1000));
71-
$queryMock = $this->createTestProxy(QueryBuilder::class, [$this->createMock(Connection::class)]);
71+
$queryMock = $this->createMock(QueryBuilder::class);
7272
$queryMock
7373
->expects(static::once())
7474
->method('addOrderBy')
@@ -83,7 +83,7 @@ public function testSortByScoreIfSearchTermIsSet(): void
8383
$productDefinition = $this->getContainer()->get(ProductDefinition::class);
8484
$criteria = new Criteria();
8585
$criteria->setTerm('searchTerm');
86-
$queryMock = $this->createTestProxy(QueryBuilder::class, [$this->createMock(Connection::class)]);
86+
$queryMock = $this->createMock(QueryBuilder::class);
8787
$queryMock
8888
->expects(static::once())
8989
->method('addOrderBy')

src/Core/Framework/Test/Plugin/KernelPluginLoader/StaticKernelPluginLoaderTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use Shopware\Core\Framework\Test\Plugin\_fixture\bundles\FooBarBundle;
1212
use Shopware\Core\Framework\Test\Plugin\_fixture\bundles\GizmoBundle;
1313
use Shopware\Core\Framework\Test\Plugin\PluginIntegrationTestBehaviour;
14-
use SwagTest\SwagTest;
15-
use SwagTest\SwagTestFake;
14+
use SwagTestPlugin\SwagTestFake;
15+
use SwagTestPlugin\SwagTestPlugin;
1616
use SwagTestWithBundle\SwagTestWithBundle;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\Definition;
@@ -91,7 +91,7 @@ public function testExpectExceptionOnMissingAutoload(): void
9191
$loader = new StaticKernelPluginLoader($this->classLoader, null, $plugins);
9292

9393
$this->expectException(KernelPluginLoaderException::class);
94-
$this->expectExceptionMessage('Failed to load plugin "SwagTest". Reason: Unable to register plugin "SwagTest\SwagTest" in autoload. Required property `autoload` missing.');
94+
$this->expectExceptionMessage('Failed to load plugin "SwagTestPlugin". Reason: Unable to register plugin "SwagTestPlugin\SwagTestPlugin" in autoload. Required property `autoload` missing.');
9595
$loader->initializePlugins(TEST_PROJECT_DIR);
9696
}
9797

@@ -104,7 +104,7 @@ public function testExpectExceptionOnMissingAutoloadPsr(): void
104104
$loader = new StaticKernelPluginLoader($this->classLoader, null, $plugins);
105105

106106
$this->expectException(KernelPluginLoaderException::class);
107-
$this->expectExceptionMessage('Failed to load plugin "SwagTest". Reason: Unable to register plugin "SwagTest\SwagTest" in autoload. Required property `psr-4` or `psr-0` missing in property autoload.');
107+
$this->expectExceptionMessage('Failed to load plugin "SwagTestPlugin". Reason: Unable to register plugin "SwagTestPlugin\SwagTestPlugin" in autoload. Required property `psr-4` or `psr-0` missing in property autoload.');
108108
$loader->initializePlugins(TEST_PROJECT_DIR);
109109
}
110110

@@ -195,7 +195,7 @@ public function testGetBundles(): void
195195

196196
static::assertCount(4, $bundles);
197197
static::assertInstanceOf(GizmoBundle::class, $bundles[0]);
198-
static::assertInstanceOf(SwagTest::class, $bundles[1]);
198+
static::assertInstanceOf(SwagTestPlugin::class, $bundles[1]);
199199
static::assertInstanceOf(FooBarBundle::class, $bundles[2]);
200200
static::assertSame($loader, $bundles[3]);
201201
}
@@ -213,7 +213,7 @@ public function testGetBundlesWithAdditionalBundlesThatAreDuplicatesButKeepOrder
213213

214214
static::assertCount(5, $bundles);
215215
static::assertInstanceOf(GizmoBundle::class, $bundles[0]);
216-
static::assertInstanceOf(SwagTest::class, $bundles[1]);
216+
static::assertInstanceOf(SwagTestPlugin::class, $bundles[1]);
217217
static::assertInstanceOf(FooBarBundle::class, $bundles[2]);
218218
static::assertInstanceOf(SwagTestWithBundle::class, $bundles[3]);
219219
static::assertSame($loader, $bundles[4]);
@@ -237,7 +237,7 @@ public function testExpectExceptionWithFakePlugin(): void
237237
$loader = new StaticKernelPluginLoader($this->classLoader, null, [$fakePluginData]);
238238

239239
$this->expectException(KernelPluginLoaderException::class);
240-
$this->expectExceptionMessage('Failed to load plugin "SwagTest". Reason: Plugin class "SwagTest\SwagTestFake" must extend "Shopware\Core\Framework\Plugin"');
240+
$this->expectExceptionMessage('Failed to load plugin "SwagTestPlugin". Reason: Plugin class "SwagTestPlugin\SwagTestFake" must extend "Shopware\Core\Framework\Plugin"');
241241
$loader->initializePlugins(TEST_PROJECT_DIR);
242242
}
243243

@@ -278,7 +278,7 @@ public function testBuild(): void
278278
$container = new ContainerBuilder();
279279
$loader->build($container);
280280

281-
$definition = $container->getDefinition(SwagTest::class);
281+
$definition = $container->getDefinition(SwagTestPlugin::class);
282282
static::assertNotNull($definition);
283283
static::assertTrue($definition->isAutowired());
284284
static::assertTrue($definition->isPublic());
@@ -295,11 +295,11 @@ public function testBuildWithExistingDefinition(): void
295295
$definition = new Definition();
296296
$definition->setAutowired(false);
297297
$definition->setPublic(false);
298-
$container->setDefinition(SwagTest::class, $definition);
298+
$container->setDefinition(SwagTestPlugin::class, $definition);
299299

300300
$loader->build($container);
301301

302-
$actualDefinition = $container->getDefinition(SwagTest::class);
302+
$actualDefinition = $container->getDefinition(SwagTestPlugin::class);
303303
static::assertSame($definition, $actualDefinition);
304304
static::assertTrue($actualDefinition->isAutowired());
305305
static::assertTrue($actualDefinition->isPublic());

src/Core/Framework/Test/Plugin/PluginIntegrationTestBehaviour.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Shopware\Core\Framework\Test\TestCaseBase\KernelLifecycleManager;
1010
use Shopware\Core\Framework\Uuid\Uuid;
1111
use Shopware\Core\Kernel;
12-
use SwagTest\SwagTest;
12+
use SwagTestPlugin\SwagTestPlugin;
1313
use SwagTestSkipRebuild\SwagTestSkipRebuild;
1414
use SwagTestWithBundle\SwagTestWithBundle;
1515

@@ -78,7 +78,7 @@ protected function getNotInstalledPlugin(): PluginEntity
7878
$plugin->assign([
7979
'id' => Uuid::randomHex(),
8080
'name' => 'SwagTest',
81-
'baseClass' => SwagTest::class,
81+
'baseClass' => SwagTestPlugin::class,
8282
'version' => '1.0.1',
8383
'active' => false,
8484
'path' => __DIR__ . '/_fixture/plugins/SwagTest',

0 commit comments

Comments
 (0)