Skip to content

Instantly share code, notes, and snippets.

@hhamon
Created December 30, 2024 15:15
Show Gist options
  • Select an option

  • Save hhamon/e7cdba9d08200dcb1304c5266dec5c84 to your computer and use it in GitHub Desktop.

Select an option

Save hhamon/e7cdba9d08200dcb1304c5266dec5c84 to your computer and use it in GitHub Desktop.
Convert Behat annotations to PHP attributes with Rector
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\ValueObject\PhpVersion;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->parallel();
$rectorConfig->phpVersion(PhpVersion::PHP_83);
$rectorConfig->importNames();
$rectorConfig->paths([
'features/bootstrap',
]);
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
new AnnotationToAttribute('AfterFeature', \Behat\Hook\AfterFeature::class),
new AnnotationToAttribute('AfterScenario', \Behat\Hook\AfterScenario::class),
new AnnotationToAttribute('AfterStep', \Behat\Hook\AfterStep::class),
new AnnotationToAttribute('AfterSuite', \Behat\Hook\AfterSuite::class),
new AnnotationToAttribute('BeforeFeature', \Behat\Hook\BeforeFeature::class),
new AnnotationToAttribute('BeforeScenario', \Behat\Hook\BeforeScenario::class),
new AnnotationToAttribute('BeforeStep', \Behat\Hook\BeforeStep::class),
new AnnotationToAttribute('BeforeSuite', \Behat\Hook\BeforeSuite::class),
new AnnotationToAttribute('Given', \Behat\Step\Given::class, useValueAsAttributeArgument: true),
new AnnotationToAttribute('Then', \Behat\Step\Then::class, useValueAsAttributeArgument: true),
new AnnotationToAttribute('Transform', \Behat\Transformation\Transform::class, useValueAsAttributeArgument: true),
new AnnotationToAttribute('When', \Behat\Step\When::class, useValueAsAttributeArgument: true),
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment