diff options
| author | Johannes Schlüter <johannes@php.net> | 2010-05-30 01:00:45 +0000 |
|---|---|---|
| committer | Johannes Schlüter <johannes@php.net> | 2010-05-30 01:00:45 +0000 |
| commit | 4158f7e1221ef5b69e8ba0aadd547a6ee2baa827 (patch) | |
| tree | 3f97bc78d8b4af792271cf4e152d1ebfad951ba7 /ext/reflection/tests | |
| parent | 2d63683ec3effbddd1a4a6ed5234822a58455198 (diff) | |
| download | php-git-4158f7e1221ef5b69e8ba0aadd547a6ee2baa827.tar.gz | |
- More trait reflection work
#- I'm not happy about ReflectionClass::getTraitAliases, yet
Diffstat (limited to 'ext/reflection/tests')
| -rw-r--r-- | ext/reflection/tests/ReflectionClass_toString_001.phpt | 20 | ||||
| -rw-r--r-- | ext/reflection/tests/traits004.phpt | 58 | ||||
| -rw-r--r-- | ext/reflection/tests/traits005.phpt | 41 |
3 files changed, 118 insertions, 1 deletions
diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt index 790ee4e5e3..a593147293 100644 --- a/ext/reflection/tests/ReflectionClass_toString_001.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -34,7 +34,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { Property [ <default> public $name ] } - - Methods [44] { + - Methods [47] { Method [ <internal:Reflection> final private method __clone ] { - Parameters [0] { @@ -188,6 +188,24 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { } } + Method [ <internal:Reflection> public method getTraits ] { + + - Parameters [0] { + } + } + + Method [ <internal:Reflection> public method getTraitNames ] { + + - Parameters [0] { + } + } + + Method [ <internal:Reflection> public method getTraitAliases ] { + + - Parameters [0] { + } + } + Method [ <internal:Reflection> public method isTrait ] { - Parameters [0] { diff --git a/ext/reflection/tests/traits004.phpt b/ext/reflection/tests/traits004.phpt new file mode 100644 index 0000000000..c9367c1f48 --- /dev/null +++ b/ext/reflection/tests/traits004.phpt @@ -0,0 +1,58 @@ +--TEST-- +ReflectionClass::getTraits() and ReflectionClass::getTraitNames +--FILE-- +<?php +trait T1 { } +trait T2 { } + +class C1 { } +class C2 { use T1; } +class C3 { use T1; use T2; } + +for ($c = "C1"; $c <= "C3"; $c++) { + echo "class $c:\n"; + $r = new ReflectionClass($c); + var_dump($r->getTraitNames()); + var_dump($r->getTraits()); + echo "\n"; +} +--EXPECT-- +class C1: +array(0) { +} +array(0) { +} + +class C2: +array(1) { + [0]=> + string(2) "T1" +} +array(1) { + ["T1"]=> + &object(ReflectionClass)#1 (1) { + ["name"]=> + string(2) "T1" + } +} + +class C3: +array(2) { + [0]=> + string(2) "T1" + [1]=> + string(2) "T2" +} +array(2) { + ["T1"]=> + &object(ReflectionClass)#2 (1) { + ["name"]=> + string(2) "T1" + } + ["T2"]=> + &object(ReflectionClass)#3 (1) { + ["name"]=> + string(2) "T2" + } +} + diff --git a/ext/reflection/tests/traits005.phpt b/ext/reflection/tests/traits005.phpt new file mode 100644 index 0000000000..1496a35ec9 --- /dev/null +++ b/ext/reflection/tests/traits005.phpt @@ -0,0 +1,41 @@ +--TEST-- +ReflectionClass::getTraitAlias +--FILE-- +<?php +trait T1 { function m1() { } function m2() { } } + +class C1 { } +class C2 { use T1; } +class C3 { use T1 { m1 as a1; } } +class C4 { use T1 { m1 as a1; m2 as a2; } } + +for ($c = "C1"; $c <= "C4"; $c++) { + echo "class $c:\n"; + $r = new ReflectionClass($c); + var_dump($r->getTraitAliases()); + echo "\n"; +} +?> +--EXPECT-- +class C1: +array(0) { +} + +class C2: +array(0) { +} + +class C3: +array(1) { + ["a1"]=> + string(10) "(null)::m1" +} + +class C4: +array(2) { + ["a1"]=> + string(10) "(null)::m1" + ["a2"]=> + string(10) "(null)::m2" +} + |
