|
11 | 11 |
|
12 | 12 | namespace Symfony\Polyfill\Tests\Php85;
|
13 | 13 |
|
14 |
| -use Attribute; |
15 |
| -use DelayedTargetValidation; |
16 | 14 | use PHPUnit\Framework\TestCase;
|
17 |
| -use ReflectionClass; |
18 |
| -use ReflectionClassConstant; |
19 |
| -use ReflectionFunction; |
20 |
| -use ReflectionMethod; |
21 |
| -use ReflectionParameter; |
22 |
| -use ReflectionProperty; |
23 | 15 |
|
24 |
| -#[DelayedTargetValidation] |
25 |
| -class HasAttribute { |
26 |
| - #[DelayedTargetValidation] |
27 |
| - private $prop; |
| 16 | +#[\DelayedTargetValidation] |
| 17 | +class HasAttribute |
| 18 | +{ |
| 19 | + #[\DelayedTargetValidation] |
| 20 | + private $prop; |
28 | 21 |
|
29 |
| - #[DelayedTargetValidation] |
30 |
| - public const FOO = 'BAR'; |
| 22 | + #[\DelayedTargetValidation] |
| 23 | + public const FOO = 'BAR'; |
31 | 24 |
|
32 |
| - #[DelayedTargetValidation] |
33 |
| - public function __construct( |
34 |
| - #[DelayedTargetValidation] $param |
35 |
| - ) {} |
| 25 | + #[\DelayedTargetValidation] |
| 26 | + public function __construct( |
| 27 | + #[\DelayedTargetValidation] $param, |
| 28 | + ) { |
| 29 | + } |
36 | 30 | }
|
37 | 31 |
|
38 |
| -#[DelayedTargetValidation] |
39 |
| -function globalFunc() {} |
| 32 | +#[\DelayedTargetValidation] |
| 33 | +function globalFunc() |
| 34 | +{ |
| 35 | +} |
40 | 36 |
|
41 | 37 | /**
|
42 | 38 | * @author Daniel Scherzer <[email protected]>
|
| 39 | + * |
43 | 40 | * @requires PHP >= 8.0
|
44 | 41 | */
|
45 | 42 | class DelayedTargetValidationTest extends TestCase
|
46 | 43 | {
|
47 | 44 | public function testAttributeAttribute()
|
48 | 45 | {
|
49 |
| - $ref = new ReflectionClass(\DelayedTargetValidation::class); |
50 |
| - $attributes = $ref->getAttributes(); |
51 |
| - $this->assertCount(1, $attributes); |
52 |
| - $attribute = $attributes[0]; |
53 |
| - $this->assertSame('Attribute', $attribute->getName()); |
54 |
| - $args = $attribute->getArguments(); |
55 |
| - $this->assertCount(1, $args); |
56 |
| - $this->assertSame(Attribute::TARGET_ALL, $args[0]); |
| 46 | + $ref = new \ReflectionClass(\DelayedTargetValidation::class); |
| 47 | + $attributes = $ref->getAttributes(); |
| 48 | + $this->assertCount(1, $attributes); |
| 49 | + $attribute = $attributes[0]; |
| 50 | + $this->assertSame('Attribute', $attribute->getName()); |
| 51 | + $args = $attribute->getArguments(); |
| 52 | + $this->assertCount(1, $args); |
| 53 | + $this->assertSame(\Attribute::TARGET_ALL, $args[0]); |
57 | 54 | $this->expectException(\ReflectionException::class);
|
58 | 55 | $this->expectExceptionMessage('Constant "missing" does not exist');
|
59 | 56 | new \ReflectionConstant('missing');
|
60 | 57 | }
|
61 | 58 |
|
62 |
| - /** |
63 |
| - * @dataProvider provideReflectionInstances |
64 |
| - */ |
65 |
| - public function testTargetValidation($reflectionSource) |
66 |
| - { |
67 |
| - $attributes = $reflectionSource->getAttributes(); |
68 |
| - $this->assertCount(1, $attributes); |
69 |
| - $attrib = $attributes[0]; |
70 |
| - $this->assertSame('DelayedTargetValidation', $attrib->getName()); |
71 |
| - $this->assertSame([], $attrib->getArguments()); |
72 |
| - $this->assertInstanceOf( |
73 |
| - DelayedTargetValidation::class, |
74 |
| - $attrib->newInstance() |
75 |
| - ); |
76 |
| - } |
| 59 | + /** |
| 60 | + * @dataProvider provideReflectionInstances |
| 61 | + */ |
| 62 | + public function testTargetValidation($reflectionSource) |
| 63 | + { |
| 64 | + $attributes = $reflectionSource->getAttributes(); |
| 65 | + $this->assertCount(1, $attributes); |
| 66 | + $attrib = $attributes[0]; |
| 67 | + $this->assertSame('DelayedTargetValidation', $attrib->getName()); |
| 68 | + $this->assertSame([], $attrib->getArguments()); |
| 69 | + $this->assertInstanceOf( |
| 70 | + \DelayedTargetValidation::class, |
| 71 | + $attrib->newInstance() |
| 72 | + ); |
| 73 | + } |
77 | 74 |
|
78 |
| - public static function provideReflectionInstances() { |
79 |
| - yield 'Class' => [ new ReflectionClass(HasAttribute::class) ]; |
80 |
| - yield 'Property' => [ new ReflectionProperty(HasAttribute::class, 'prop')]; |
81 |
| - yield 'Class constant' => [ new ReflectionClassConstant(HasAttribute::class, 'FOO')]; |
82 |
| - yield 'Method' => [ new ReflectionMethod(HasAttribute::class, '__construct')]; |
83 |
| - yield 'Parameter' => [ |
84 |
| - new ReflectionParameter([HasAttribute::class, '__construct'], 'param') |
85 |
| - ]; |
86 |
| - yield 'Function' => [ new ReflectionFunction(__NAMESPACE__ . '\\globalFunc') ]; |
87 |
| - } |
| 75 | + public static function provideReflectionInstances() |
| 76 | + { |
| 77 | + yield 'Class' => [new \ReflectionClass(HasAttribute::class)]; |
| 78 | + yield 'Property' => [new \ReflectionProperty(HasAttribute::class, 'prop')]; |
| 79 | + yield 'Class constant' => [new \ReflectionClassConstant(HasAttribute::class, 'FOO')]; |
| 80 | + yield 'Method' => [new \ReflectionMethod(HasAttribute::class, '__construct')]; |
| 81 | + yield 'Parameter' => [ |
| 82 | + new \ReflectionParameter([HasAttribute::class, '__construct'], 'param'), |
| 83 | + ]; |
| 84 | + yield 'Function' => [new \ReflectionFunction(__NAMESPACE__.'\\globalFunc')]; |
| 85 | + } |
88 | 86 | }
|
0 commit comments