From c720a21cd7ebf3c6e644392d1707a5e30fccb7e0 Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Mon, 26 Feb 2024 13:28:43 +0100 Subject: [PATCH] [TASK] Use codeception DataProvider attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the attribute in favor of `@dataProvider` annotation. Adapt the acceptance test splitter to deal with it. Clean up annotationChecker to no longer allow `@dataProvider` and disallow a series of further not used annotations along the way. Resolves: #103204 Related: #103180 Releases: main, 12.4 Change-Id: If8e4d5a87d07d574065d596acb4c44a48f265ffa Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83136 Reviewed-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: core-ci <typo3@b13.com> Tested-by: Andreas Kienast <a.fernandez@scripting-base.de> Reviewed-by: Andreas Kienast <a.fernandez@scripting-base.de> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- Build/Scripts/annotationChecker.php | 13 ++++---- Build/Scripts/splitAcceptanceTests.php | 30 +++++++------------ .../Application/DbCheck/DbCheckModuleCest.php | 5 ++-- .../FormEngine/ElementsBasicInputDateCest.php | 17 ++++------- .../FormEngine/ElementsBasicInputEvalCest.php | 5 ++-- .../ElementsBasicInputRangeCest.php | 5 ++-- .../ElementsBasicInputSimpleCest.php | 5 ++-- .../FormEngine/ElementsBasicNumberCest.php | 5 ++-- .../FormEngine/ElementsBasicPasswordCest.php | 5 ++-- .../FormEngine/ElementsEmptyElementsCest.php | 5 ++-- .../Application/Frontend/SitemapXmlCest.php | 5 ++-- .../Application/Info/InfoModuleCest.php | 5 ++-- .../InstallTool/EnvironmentCest.php | 5 ++-- .../Redirect/RedirectModuleCest.php | 5 ++-- .../ContentObject/FileLinkHookInterface.php | 1 - 15 files changed, 43 insertions(+), 73 deletions(-) diff --git a/Build/Scripts/annotationChecker.php b/Build/Scripts/annotationChecker.php index 1cef01ac9ffe..b5933e24f685 100755 --- a/Build/Scripts/annotationChecker.php +++ b/Build/Scripts/annotationChecker.php @@ -1,5 +1,6 @@ #!/usr/bin/env php <?php + declare(strict_types=1); /* @@ -47,16 +48,12 @@ class NodeVisitor extends NodeVisitorAbstract $negativeLookaheadMatches = [ // Annotation tags 'Annotation', 'Attribute', 'Attributes', 'Required', 'Target', - // Widely used tags (but not existent in phpdoc) - 'fix', 'fixme', 'override', // PHPDocumentor 1 tags - 'abstract', 'code', 'deprec', 'endcode', 'exception', 'final', 'ingroup', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', + 'private', 'static', 'staticvar', 'staticVar', // PHPDocumentor 2 tags - 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedby', 'uses', 'var', 'version', - // PHPUnit tags - 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'dataProvider', 'group', 'skip', 'depends', 'expectedException', 'before', 'requires', - // codeception tags - 'env', + 'author', 'category', 'copyright', 'deprecated', 'example', 'internal', 'license', 'link', 'param', 'property', 'return', 'see', 'since', 'throws', 'todo', 'TODO', 'var', 'version', + // PHPUnit & codeception tags + 'depends', 'requires', 'env', // PHPCheckStyle 'SuppressWarnings', 'noinspection', // Extbase related diff --git a/Build/Scripts/splitAcceptanceTests.php b/Build/Scripts/splitAcceptanceTests.php index 5c5d19979b40..a936d96bc576 100755 --- a/Build/Scripts/splitAcceptanceTests.php +++ b/Build/Scripts/splitAcceptanceTests.php @@ -1,5 +1,6 @@ #!/usr/bin/env php <?php + declare(strict_types=1); /* @@ -15,7 +16,6 @@ declare(strict_types=1); * The TYPO3 project - inspiring people to share! */ -use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; @@ -188,12 +188,12 @@ class AcceptanceTestCaseVisitor extends NodeVisitorAbstract /** * @var array[] An array of arrays with test method names and optionally a data provider name */ - private $tests = []; + private array $tests = []; /** * @var string Fully qualified test class name */ - private $fqcn; + private string $fqcn; /** * Create a list of '@test' annotated methods in a test case @@ -215,24 +215,20 @@ class AcceptanceTestCaseVisitor extends NodeVisitorAbstract $node instanceof \PhpParser\Node\Stmt\ClassMethod // The method is public && $node->isPublic() - // The methods does not start with an "_" (eg. _before()) + // The method does not start with an "_" (eg. _before()) && $node->name->name[0] !== '_' ) { // Found a test $test = [ 'methodName' => $node->name->name, ]; - $docComment = $node->getDocComment(); - if ($docComment instanceof Doc) { - preg_match_all( - '/\s*\s@(?<annotations>[^\s.].*)\n/', - $docComment->getText(), - $matches - ); - foreach ($matches['annotations'] as $possibleDataProvider) { - // See if this test has a data provider attached - if (str_starts_with($possibleDataProvider, 'dataProvider')) { - $test['dataProvider'] = trim(ltrim($possibleDataProvider, 'dataProvider')); + foreach ($node->getAttrGroups() as $possibleDataProviderAttributeGroup) { + foreach ($possibleDataProviderAttributeGroup->attrs as $possibleDataProviderAttribute) { + // See if that method has the codeception DataProvider attribute attached, too. + $name = $possibleDataProviderAttribute->name->toCodeString(); + if ($name === '\\Codeception\\Attribute\\DataProvider') { + $dataProviderMethodName = $possibleDataProviderAttribute->args[0]->value->value; + $test['dataProvider'] = $dataProviderMethodName; } } } @@ -242,8 +238,6 @@ class AcceptanceTestCaseVisitor extends NodeVisitorAbstract /** * Return array of found tests and their data providers - * - * @return array */ public function getTests(): array { @@ -252,8 +246,6 @@ class AcceptanceTestCaseVisitor extends NodeVisitorAbstract /** * Return Fully qualified class test name - * - * @return string */ public function getFqcn(): string { diff --git a/typo3/sysext/core/Tests/Acceptance/Application/DbCheck/DbCheckModuleCest.php b/typo3/sysext/core/Tests/Acceptance/Application/DbCheck/DbCheckModuleCest.php index fd0c5447d465..cc6b733da5cd 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/DbCheck/DbCheckModuleCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/DbCheck/DbCheckModuleCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\DbCheck; +use Codeception\Attribute\DataProvider; use Codeception\Example; use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\RemoteWebElement; @@ -71,9 +72,7 @@ final class DbCheckModuleCest ]; } - /** - * @dataProvider recordStatisticsDataProvider - */ + #[DataProvider('recordStatisticsDataProvider')] public function seeRecordStatistics(ApplicationTester $I, Example $testData): void { $this->goToPageAndSeeHeadline($I, 'Record Statistics', 'Records Statistics'); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputDateCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputDateCest.php index 7893711b9166..2522990313e9 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputDateCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputDateCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine; +use Codeception\Attribute\DataProvider; use Codeception\Example; use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester; use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree; @@ -71,9 +72,7 @@ final class ElementsBasicInputDateCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider dbTypeDateEvalDateDataProvider - */ + #[DataProvider('dbTypeDateEvalDateDataProvider')] public function dbTypeDateEvalDate(ApplicationTester $I, Example $testData): void { $this->runInputFieldTest($I, $testData); @@ -109,9 +108,7 @@ final class ElementsBasicInputDateCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider dbTypeDateEvalDatetimeDataProvider - */ + #[DataProvider('dbTypeDateEvalDatetimeDataProvider')] public function dbTypeDateEvalDatetime(ApplicationTester $I, Example $testData): void { $this->runInputFieldTest($I, $testData); @@ -131,9 +128,7 @@ final class ElementsBasicInputDateCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider dbTypeDateEvalTimeDataProvider - */ + #[DataProvider('dbTypeDateEvalTimeDataProvider')] public function dbTypeDateEvalTime(ApplicationTester $I, Example $testData): void { $this->runInputFieldTest($I, $testData); @@ -169,9 +164,7 @@ final class ElementsBasicInputDateCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider dbTypeDateEvalTimeDataProvider_DbTypeDateTime - */ + #[DataProvider('dbTypeDateEvalTimeDataProvider_DbTypeDateTime')] public function checkThatValidationWorks_EvalDateTime_DbTypeDateTime(ApplicationTester $I, Example $testData): void { $this->runInputFieldTest($I, $testData); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputEvalCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputEvalCest.php index e68d9e534aea..62e74201dda9 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputEvalCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputEvalCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine; +use Codeception\Attribute\DataProvider; use Codeception\Example; use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester; use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree; @@ -88,9 +89,7 @@ final class ElementsBasicInputEvalCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider simpleEvalInputFieldsDataProvider - */ + #[DataProvider('simpleEvalInputFieldsDataProvider')] public function simpleEvalInputFields(ApplicationTester $I, Example $testData): void { $this->runInputFieldTest($I, $testData); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputRangeCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputRangeCest.php index 0e9ddb2bbb6b..702a63937b31 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputRangeCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputRangeCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine; +use Codeception\Attribute\DataProvider; use Codeception\Example; use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester; use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree; @@ -101,9 +102,7 @@ final class ElementsBasicInputRangeCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider simpleRangeAndMd5FieldsDataProvider - */ + #[DataProvider('simpleRangeAndMd5FieldsDataProvider')] public function simpleRangeAndMd5Fields(ApplicationTester $I, Example $testData): void { $I->click($testData['tab']); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputSimpleCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputSimpleCest.php index 95c77d801c7f..5e650e45eb7d 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputSimpleCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicInputSimpleCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine; +use Codeception\Attribute\DataProvider; use Codeception\Example; use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester; use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree; @@ -182,9 +183,7 @@ final class ElementsBasicInputSimpleCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider simpleInputFieldsDataProvider - */ + #[DataProvider('simpleInputFieldsDataProvider')] public function simpleInputFields(ApplicationTester $I, Example $testData): void { $this->runInputFieldTest($I, $testData); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicNumberCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicNumberCest.php index 8a476527b2c7..73b5a6558241 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicNumberCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicNumberCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine; +use Codeception\Attribute\DataProvider; use Codeception\Example; use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester; use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree; @@ -149,9 +150,7 @@ final class ElementsBasicNumberCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider simpleNumberFieldsDataProvider - */ + #[DataProvider('simpleNumberFieldsDataProvider')] public function simpleNumberFields(ApplicationTester $I, Example $testData): void { $this->runInputFieldTest($I, $testData); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicPasswordCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicPasswordCest.php index 82fec3f50bf8..20dd043a739d 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicPasswordCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsBasicPasswordCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine; +use Codeception\Attribute\DataProvider; use Codeception\Example; use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester; use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree; @@ -67,9 +68,7 @@ final class ElementsBasicPasswordCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider passwordInputFieldsDataProvider - */ + #[DataProvider('passwordInputFieldsDataProvider')] public function passwordInputFields(ApplicationTester $I, Example $testData): void { $this->runInputFieldTest($I, $testData); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsEmptyElementsCest.php b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsEmptyElementsCest.php index 863a6a28f49e..6a4b887786ec 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsEmptyElementsCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsEmptyElementsCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\FormEngine; +use Codeception\Attribute\DataProvider; use Codeception\Example; use Facebook\WebDriver\WebDriverBy; use Facebook\WebDriver\WebDriverKeys; @@ -142,9 +143,7 @@ final class ElementsEmptyElementsCest extends AbstractElementsBasicCest ]; } - /** - * @dataProvider simpleRadioFieldsDataProvider - */ + #[DataProvider('simpleRadioFieldsDataProvider')] public function simpleRadioFields(ApplicationTester $I, Example $testData): void { $this->runRadioFieldTest($I, $testData); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/Frontend/SitemapXmlCest.php b/typo3/sysext/core/Tests/Acceptance/Application/Frontend/SitemapXmlCest.php index 714e91d18f75..4516dd63d2fe 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/Frontend/SitemapXmlCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/Frontend/SitemapXmlCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\Frontend; +use Codeception\Attribute\DataProvider; use Codeception\Example; use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\RemoteWebElement; @@ -72,9 +73,7 @@ final class SitemapXmlCest ]; } - /** - * @dataProvider sitemapDataProvider - */ + #[DataProvider('sitemapDataProvider')] public function seeSitemapXml(ApplicationTester $I, Example $testData): void { $I->see('TYPO3 XML Sitemap'); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/Info/InfoModuleCest.php b/typo3/sysext/core/Tests/Acceptance/Application/Info/InfoModuleCest.php index 91db5a19262d..fade0e63e43a 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/Info/InfoModuleCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/Info/InfoModuleCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\Info; +use Codeception\Attribute\DataProvider; use Codeception\Example; use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester; use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\PageTree; @@ -42,9 +43,7 @@ final class InfoModuleCest ]; } - /** - * @dataProvider infoMenuDataProvider - */ + #[DataProvider('infoMenuDataProvider')] public function seeInfoSubModules(ApplicationTester $I, Example $exampleData): void { $I->amGoingTo('select ' . $exampleData['option'] . ' in dropdown'); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/InstallTool/EnvironmentCest.php b/typo3/sysext/core/Tests/Acceptance/Application/InstallTool/EnvironmentCest.php index 2dd20f4c7838..9744dd267995 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/InstallTool/EnvironmentCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/InstallTool/EnvironmentCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\InstallTool; +use Codeception\Attribute\DataProvider; use Codeception\Example; use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester; use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\ModalDialog; @@ -45,9 +46,7 @@ final class EnvironmentCest extends AbstractCest ]; } - /** - * @dataProvider cardsDataProvider - */ + #[DataProvider('cardsDataProvider')] public function seeCardsAndModals(ApplicationTester $I, ModalDialog $modalDialog, Example $testData): void { $I->see($testData['title']); diff --git a/typo3/sysext/core/Tests/Acceptance/Application/Redirect/RedirectModuleCest.php b/typo3/sysext/core/Tests/Acceptance/Application/Redirect/RedirectModuleCest.php index f4f6be6e3326..b219db8a3dc7 100644 --- a/typo3/sysext/core/Tests/Acceptance/Application/Redirect/RedirectModuleCest.php +++ b/typo3/sysext/core/Tests/Acceptance/Application/Redirect/RedirectModuleCest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Core\Tests\Acceptance\Application\Redirect; +use Codeception\Attribute\DataProvider; use Codeception\Example; use TYPO3\CMS\Core\Tests\Acceptance\Support\ApplicationTester; @@ -89,9 +90,7 @@ final class RedirectModuleCest ]; } - /** - * @dataProvider possibleRedirectStatusCodes - */ + #[DataProvider('possibleRedirectStatusCodes')] public function seeStatusCodesWhenCreatingNewRedirect(ApplicationTester $I, Example $example): void { $I->amGoingTo('Create a redirect and see the different status codes'); diff --git a/typo3/sysext/frontend/Classes/ContentObject/FileLinkHookInterface.php b/typo3/sysext/frontend/Classes/ContentObject/FileLinkHookInterface.php index 80dcf3e9d6f1..653435ea5609 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/FileLinkHookInterface.php +++ b/typo3/sysext/frontend/Classes/ContentObject/FileLinkHookInterface.php @@ -26,7 +26,6 @@ interface FileLinkHookInterface * Finds alternative previewImage for given File. * * @return File - * @abstract */ public function getPreviewImage(File $file); } -- GitLab