Skip to content

Commit b6d253e

Browse files
Basic working version!
1 parent 61aa04a commit b6d253e

27 files changed

+496
-96
lines changed

Zend/tests/attributes/034_target_values.phpt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@ showFlag("TARGET_PROPERTY", Attribute::TARGET_PROPERTY);
1616
showFlag("TARGET_CLASS_CONSTANT", Attribute::TARGET_CLASS_CONSTANT);
1717
showFlag("TARGET_PARAMETER", Attribute::TARGET_PARAMETER);
1818
showFlag("TARGET_CONSTANT", Attribute::TARGET_CONSTANT);
19+
showFlag("TARGET_CLASS_ALIAS", Attribute::TARGET_CLASS_ALIAS);
1920
showFlag("IS_REPEATABLE", Attribute::IS_REPEATABLE);
2021

2122
$all = Attribute::TARGET_CLASS | Attribute::TARGET_FUNCTION
2223
| Attribute::TARGET_METHOD | Attribute::TARGET_PROPERTY
2324
| Attribute::TARGET_CLASS_CONSTANT | Attribute::TARGET_PARAMETER
24-
| Attribute::TARGET_CONSTANT;
25+
| Attribute::TARGET_CONSTANT | Attribute::TARGET_CLASS_ALIAS;
2526
var_dump($all, Attribute::TARGET_ALL, $all === Attribute::TARGET_ALL);
2627

2728
?>
2829
--EXPECT--
29-
Attribute::TARGET_CLASS = 1 (127 & 1 === 1)
30-
Attribute::TARGET_FUNCTION = 2 (127 & 2 === 2)
31-
Attribute::TARGET_METHOD = 4 (127 & 4 === 4)
32-
Attribute::TARGET_PROPERTY = 8 (127 & 8 === 8)
33-
Attribute::TARGET_CLASS_CONSTANT = 16 (127 & 16 === 16)
34-
Attribute::TARGET_PARAMETER = 32 (127 & 32 === 32)
35-
Attribute::TARGET_CONSTANT = 64 (127 & 64 === 64)
36-
Attribute::IS_REPEATABLE = 128 (127 & 128 === 0)
37-
int(127)
38-
int(127)
30+
Attribute::TARGET_CLASS = 1 (255 & 1 === 1)
31+
Attribute::TARGET_FUNCTION = 2 (255 & 2 === 2)
32+
Attribute::TARGET_METHOD = 4 (255 & 4 === 4)
33+
Attribute::TARGET_PROPERTY = 8 (255 & 8 === 8)
34+
Attribute::TARGET_CLASS_CONSTANT = 16 (255 & 16 === 16)
35+
Attribute::TARGET_PARAMETER = 32 (255 & 32 === 32)
36+
Attribute::TARGET_CONSTANT = 64 (255 & 64 === 64)
37+
Attribute::TARGET_CLASS_ALIAS = 128 (255 & 128 === 128)
38+
Attribute::IS_REPEATABLE = 256 (255 & 256 === 0)
39+
int(255)
40+
int(255)
3941
bool(true)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Alias attributes must not be associative
3+
--FILE--
4+
<?php
5+
6+
#[ClassAlias('Other', ['test' => new Deprecated()])]
7+
class Demo {}
8+
9+
$attr = new ReflectionClass( Demo::class )->getAttributes()[0];
10+
$attr->newInstance();
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Uncaught Error: ClassAlias::__construct(): Argument #2 ($attributes) must be a list, not an associative array in %s:%d
15+
Stack trace:
16+
#0 %s(%d): ClassAlias->__construct('Other', Array)
17+
#1 %s(%d): ReflectionAttribute->newInstance()
18+
#2 {main}
19+
thrown in %s on line %d
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Alias attributes must be an array
3+
--FILE--
4+
<?php
5+
6+
#[ClassAlias('Other', true)]
7+
class Demo {}
8+
9+
$attr = new ReflectionClass( Demo::class )->getAttributes()[0];
10+
$attr->newInstance();
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: ClassAlias::__construct(): Argument #2 ($attributes) must be of type array, true given in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Alias attributes do not need to exist for declaration
3+
--FILE--
4+
<?php
5+
6+
#[ClassAlias('Other', [new MissingAttribute()])]
7+
class Demo {}
8+
9+
echo "Done\n"
10+
?>
11+
--EXPECT--
12+
Done

Zend/tests/attributes/class_alias/parameter_invalid.phpt renamed to Zend/tests/attributes/class_alias/name_invalid.phpt

File renamed without changes.

Zend/tests/attributes/class_alias/parameter_nonstring.phpt renamed to Zend/tests/attributes/class_alias/name_nonstring.phpt

File renamed without changes.

Zend/tests/attributes/class_alias/parameter_required.phpt renamed to Zend/tests/attributes/class_alias/name_required.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Demo {}
88

99
?>
1010
--EXPECTF--
11-
Fatal error: Uncaught ArgumentCountError: ClassAlias::__construct() expects exactly 1 argument, 0 given in %s:%d
11+
Fatal error: Uncaught ArgumentCountError: ClassAlias::__construct() expects at least 1 argument, 0 given in %s:%d
1212
Stack trace:
1313
#0 %s(%d): ClassAlias->__construct()
1414
#1 {main}

Zend/tests/attributes/class_alias_target/must_target_class_alias-internal.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ Error when attribute does not target class alias (internal attribute)
77
class Demo {}
88

99
?>
10-
--EXPECT--
11-
NO
10+
--EXPECTF--
11+
Fatal error: Attribute "Override" cannot target class alias (allowed targets: method) in %s on line %d

Zend/tests/attributes/class_alias_target/must_target_class_alias-userland.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ array(1) {
2020
[0]=>
2121
object(ReflectionAttribute)#%d (1) {
2222
["name"]=>
23-
string(10) "ClassAlias"
23+
string(19) "MyFunctionAttribute"
2424
}
2525
}
26+
27+
Fatal error: Uncaught Error: Attribute "MyFunctionAttribute" cannot target class alias (allowed targets: function) in %s:%d
28+
Stack trace:
29+
#0 %s(%d): ReflectionAttribute->newInstance()
30+
#1 {main}
31+
thrown in %s on line %d

Zend/tests/attributes/class_alias_target/not_repeatable-internal.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ Validation of attribute repetition (not allowed; internal attribute)
77
class Demo {}
88

99
?>
10-
--EXPECT--
11-
12-
e
10+
--EXPECTF--
11+
Fatal error: Attribute "Deprecated" must not be repeated in %s on line %d

0 commit comments

Comments
 (0)