Skip to content

Commit d31f656

Browse files
authored
[Php80] Handle Behat transform annotation (#7899)
1 parent 730c316 commit d31f656

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

config/set/behat-annotations-to-attributes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
new AnnotationToAttribute('AfterScenario', 'Behat\Hook\AfterScenario', useValueAsAttributeArgument: true),
2020
new AnnotationToAttribute('BeforeStep', 'Behat\Hook\BeforeStep', useValueAsAttributeArgument: true),
2121
new AnnotationToAttribute('AfterStep', 'Behat\Hook\AfterStep', useValueAsAttributeArgument: true),
22+
new AnnotationToAttribute('Transform', 'Behat\Transformation\Transform', useValueAsAttributeArgument: true),
2223
]);
2324
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture\Behat;
4+
5+
final class TransformMethod
6+
{
7+
/**
8+
* @Transform :user
9+
*/
10+
public function transformUser($user)
11+
{
12+
return $user;
13+
}
14+
}
15+
16+
?>
17+
-----
18+
<?php
19+
20+
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture\Behat;
21+
22+
final class TransformMethod
23+
{
24+
#[\Behat\Transformation\Transform(':user')]
25+
public function transformUser($user)
26+
{
27+
return $user;
28+
}
29+
}
30+
31+
?>

rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Behat\Step\Then;
66
use Behat\Step\When;
7+
use Behat\Transformation\Transform;
78
use Rector\Config\RectorConfig;
89
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
910
use Rector\Php80\ValueObject\AnnotationToAttribute;
@@ -62,6 +63,7 @@
6263
// special case with following comment becoming a inner value
6364
new AnnotationToAttribute('When', When::class, useValueAsAttributeArgument: true),
6465
new AnnotationToAttribute('Then', Then::class, useValueAsAttributeArgument: true),
66+
new AnnotationToAttribute('Transform', Transform::class, useValueAsAttributeArgument: true),
6567

6668
// simple tag to attribute
6769
new AnnotationToAttribute('OldName1', NewName1::class),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Behat\Transformation;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_METHOD)]
10+
final class Transform
11+
{
12+
public function __construct(
13+
public string $value
14+
) {
15+
}
16+
}

0 commit comments

Comments
 (0)