- Issue created by @mondrake
- 🇮🇹Italy mondrake 🇮🇹
Out of curiosity I tried run Rector with this config
<?php declare(strict_types=1); use Rector\Config\RectorConfig; use Rector\PHPUnit\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector; return RectorConfig::configure() ->withPaths([ __DIR__ . '/composer', __DIR__ . '/core', ]) ->withSkipPath( __DIR__ . '/core/tests/Drupal/Tests/Component/Annotation/Doctrine/Fixtures', ) ->withSkipPath( '*/ProxyClass/*', ) ->withSkipPath( '*.api.php', ) ->withRules([ DataProviderAnnotationToAttributeRector::class, ]) ->withImportNames( importDocBlockNames: false, importShortClasses: false, removeUnusedImports: false, );
and it produced the attached patch; it's not perfect but it should fix 95% of the cases. A bit annoying the added
use
import is not sorted alphabeticalyl, but I assume some PHPCS magic could happen to fix that as well. - Status changed to Needs work
9 months ago 3:39am 8 May 2024 - 🇦🇺Australia mstrelan
I think we can continue with this now that 📌 Upgrade PHPUnit to 10, drop Symfony PHPUnit-bridge dependency Fixed is in. The patch looks like a great start!
A bit annoying the added use import is not sorted alphabeticalyl, but I assume some PHPCS magic could happen to fix that as well
There is
SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses
, but see 📌 Coding standards for "use" statements RTBC where it's being discussed as a coding standard. - 🇦🇺Australia mstrelan
I think we should also add
@dataProvider
to theSlevomatCodingStandard.Commenting.ForbiddenAnnotations
configuration in phpcs.xml.dist - Issue was unassigned.
- 🇬🇧United Kingdom longwave UK
As spotted over in #3417066-120: Upgrade PHPUnit to 10, drop Symfony PHPUnit-bridge dependency → , it looks like we can't mix PHPUnit attributes and annotations, we will have to convert them all at once unfortunately:
$metadata = $this->attributeReader->forMethod($className, $methodName); if (!$metadata->isEmpty()) { return $metadata; } return $this->annotationReader->forMethod($className, $methodName);
- Status changed to Closed: won't fix
9 months ago 8:11pm 8 May 2024 - 🇮🇹Italy mondrake 🇮🇹
#6 - ouch that's painful.. however we could keep annotations as well as attributes in the same test file, so for BC to have PHPUnit 9 compatiblity (using annotations) and PHPUnit 10/11 compatibility (using attributes) at the same time. See for example these tests in a library I maintain on GitHub: https://github.com/FileEye/MimeMap/blob/ba0b04e179976e7d6a487fdb166c5f1f...
However, we can't proceed by annotation. Do we need an issue to build a comprehensive Rector that would address all annotations and then use that to proceed by test suite/core-module?
I think having some issue open would be good. I just found this issue after reading about the availability of attributes
https://docs.phpunit.de/en/10.5/writing-tests-for-phpunit.html#data-prov...
- 🇮🇹Italy mondrake 🇮🇹
Filed 📌 [meta] Define a Rector rule to convert test annotations to attributes Active . See you there!