From 29023692ce968b24b2462496cb6944d0c39619b0 Mon Sep 17 00:00:00 2001 From: Ant Phillips Date: Mon, 17 Nov 2008 11:20:19 +0000 Subject: [PATCH] Commit tests for ext/reflection --- .../tests/reflectionClass_export_basic1.phpt | 62 +++++++++++++++++++ .../tests/reflectionClass_export_basic2.phpt | 54 ++++++++++++++++ ...eflectionClass_getExtensionName_basic.phpt | 14 +++++ ...ctionClass_getExtensionName_variation.phpt | 20 ++++++ .../reflectionClass_getExtension_basic.phpt | 17 +++++ ...eflectionClass_getExtension_variation.phpt | 20 ++++++ ...flectionClass_getInterfaceNames_basic.phpt | 25 ++++++++ .../reflectionClass_getModifiers_basic.phpt | 39 ++++++++++++ .../tests/reflectionClass_getParentClass.phpt | 21 +++++++ .../reflectionClass_hasConstant_basic.phpt | 23 +++++++ .../reflectionClass_hasMethod_basic.phpt | 57 +++++++++++++++++ .../reflectionClass_hasProperty_basic.phpt | 38 ++++++++++++ .../reflectionClass_isAbstract_basic.phpt | 23 +++++++ .../tests/reflectionClass_isFinal_basic.phpt | 23 +++++++ .../reflectionClass_isInterface_basic.phpt | 27 ++++++++ .../reflectionClass_isIterateable_basic.phpt | 36 +++++++++++ ...lectionClass_isIterateable_variation1.phpt | 27 ++++++++ .../reflectionObject___toString_basic1.phpt | 36 +++++++++++ .../reflectionObject___toString_basic2.phpt | 39 ++++++++++++ .../tests/reflectionObject_export_basic1.phpt | 36 +++++++++++ .../tests/reflectionObject_export_basic2.phpt | 39 ++++++++++++ .../tests/reflectionObject_export_basic3.phpt | 38 ++++++++++++ ...ectionProperty_constructor_variation1.phpt | 58 +++++++++++++++++ 23 files changed, 772 insertions(+) create mode 100644 ext/reflection/tests/reflectionClass_export_basic1.phpt create mode 100644 ext/reflection/tests/reflectionClass_export_basic2.phpt create mode 100644 ext/reflection/tests/reflectionClass_getExtensionName_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_getExtensionName_variation.phpt create mode 100644 ext/reflection/tests/reflectionClass_getExtension_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_getExtension_variation.phpt create mode 100644 ext/reflection/tests/reflectionClass_getInterfaceNames_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_getModifiers_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_getParentClass.phpt create mode 100644 ext/reflection/tests/reflectionClass_hasConstant_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_hasMethod_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_hasProperty_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isAbstract_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isFinal_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isInterface_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isIterateable_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isIterateable_variation1.phpt create mode 100644 ext/reflection/tests/reflectionObject___toString_basic1.phpt create mode 100644 ext/reflection/tests/reflectionObject___toString_basic2.phpt create mode 100644 ext/reflection/tests/reflectionObject_export_basic1.phpt create mode 100644 ext/reflection/tests/reflectionObject_export_basic2.phpt create mode 100644 ext/reflection/tests/reflectionObject_export_basic3.phpt create mode 100644 ext/reflection/tests/reflectionProperty_constructor_variation1.phpt diff --git a/ext/reflection/tests/reflectionClass_export_basic1.phpt b/ext/reflection/tests/reflectionClass_export_basic1.phpt new file mode 100644 index 0000000000..8729731f56 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_export_basic1.phpt @@ -0,0 +1,62 @@ +--TEST-- +ReflectionClass::export() - various parameters +--FILE-- + +--EXPECTF-- +Class [ class C extends A ] { + @@ %s 14-14 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [2] { + Method [ public method privf ] { + @@ %s 3 - 3 + + - Parameters [1] { + Parameter #0 [ Exception $a ] + } + } + + Method [ public method pubf ] { + @@ %s 4 - 11 + + - Parameters [8] { + Parameter #0 [ A $a ] + Parameter #1 [ $b ] + Parameter #2 [ C or NULL $c = NULL ] + Parameter #3 [ $d = '16 chars long -...' ] + Parameter #4 [ $e = '15 chars long -' ] + Parameter #5 [ $f = NULL ] + Parameter #6 [ $g = false ] + Parameter #7 [ array or NULL $h = NULL ] + } + } + } +} \ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_export_basic2.phpt b/ext/reflection/tests/reflectionClass_export_basic2.phpt new file mode 100644 index 0000000000..b6644883ee --- /dev/null +++ b/ext/reflection/tests/reflectionClass_export_basic2.phpt @@ -0,0 +1,54 @@ +--TEST-- +ReflectionClass::export() - ensure inherited private props are hidden. +--FILE-- + +--EXPECTF-- +Class [ class c ] { + @@ %s 2-5 + + - Constants [0] { + } + + - Static properties [1] { + Property [ private static $b ] + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ private $a ] + } + + - Methods [0] { + } +} + +Class [ class d extends c ] { + @@ %s 7-7 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [0] { + } +} \ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getExtensionName_basic.phpt b/ext/reflection/tests/reflectionClass_getExtensionName_basic.phpt new file mode 100644 index 0000000000..7813cca315 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getExtensionName_basic.phpt @@ -0,0 +1,14 @@ +--TEST-- +ReflectionClass::getExtensionName() method - basic test for getExtensionName() method +--SKIPIF-- + +--CREDITS-- +Rein Velt +#testFest Roosendaal 2008-05-10 +--FILE-- +getExtensionName()) ; +?> +--EXPECT-- +string(3) "dom" diff --git a/ext/reflection/tests/reflectionClass_getExtensionName_variation.phpt b/ext/reflection/tests/reflectionClass_getExtensionName_variation.phpt new file mode 100644 index 0000000000..35372c4f84 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getExtensionName_variation.phpt @@ -0,0 +1,20 @@ +--TEST-- +ReflectionClass::getExtensionName() method - variation test for getExtensionName() +--SKIPIF-- + +--CREDITS-- +Rein Velt +#testFest Roosendaal 2008-05-10 +--FILE-- +getExtensionName()) ; +?> +--EXPECT-- +bool(false) \ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getExtension_basic.phpt b/ext/reflection/tests/reflectionClass_getExtension_basic.phpt new file mode 100644 index 0000000000..efc1ed8eed --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getExtension_basic.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionClass::getExtension() method - basic test for getExtension() method +--SKIPIF-- + +--CREDITS-- +Rein Velt +#testFest Roosendaal 2008-05-10 +--FILE-- +getExtension()) ; +?> +--EXPECTF-- +object(ReflectionExtension)#%d (1) { + ["name"]=> + string(3) "dom" +} \ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getExtension_variation.phpt b/ext/reflection/tests/reflectionClass_getExtension_variation.phpt new file mode 100644 index 0000000000..f2272777a0 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getExtension_variation.phpt @@ -0,0 +1,20 @@ +--TEST-- +ReflectionClass::getExtension() method - variation test for getExtension() +--SKIPIF-- + +--CREDITS-- +Rein Velt +#testFest Roosendaal 2008-05-10 +--FILE-- +getExtension()) ; +?> +--EXPECT-- +NULL \ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getInterfaceNames_basic.phpt b/ext/reflection/tests/reflectionClass_getInterfaceNames_basic.phpt new file mode 100644 index 0000000000..abbaa35f5c --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getInterfaceNames_basic.phpt @@ -0,0 +1,25 @@ +--TEST-- +ReflectionClass::getInterfaceNames() +--SKIPIF-- + +--CREDITS-- +Michelangelo van Dam +#testfest roosendaal on 2008-05-10 +--FILE-- +getInterfaceNames()); +?> +--EXPECT-- +array(2) { + [0]=> + string(3) "Foo" + [1]=> + string(3) "Bar" +} diff --git a/ext/reflection/tests/reflectionClass_getModifiers_basic.phpt b/ext/reflection/tests/reflectionClass_getModifiers_basic.phpt new file mode 100644 index 0000000000..33a2539b95 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getModifiers_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionClass::getModifiers() +--SKIPIF-- + +--CREDITS-- +Felix De Vliegher +--FILE-- +getModifiers()); +} + +dump_modifiers('a'); +dump_modifiers('b'); +dump_modifiers('c'); +dump_modifiers('d'); +dump_modifiers('e'); +dump_modifiers('f'); +dump_modifiers('g'); + +?> +--EXPECT-- +int(0) +int(32) +int(64) +int(128) +int(0) +int(128) +int(0) \ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getParentClass.phpt b/ext/reflection/tests/reflectionClass_getParentClass.phpt new file mode 100644 index 0000000000..46884ca2ba --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getParentClass.phpt @@ -0,0 +1,21 @@ +--TEST-- +ReflectionClass::getParentClass() +--CREDITS-- +Michelangelo van Dam +#testfest roosendaal on 2008-05-10 +--FILE-- +getParentClass()); +?> + +--EXPECTF-- +object(ReflectionClass)#%d (1) { + ["name"]=> + string(3) "Foo" +} diff --git a/ext/reflection/tests/reflectionClass_hasConstant_basic.phpt b/ext/reflection/tests/reflectionClass_hasConstant_basic.phpt new file mode 100644 index 0000000000..49570150c7 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_hasConstant_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionClass::hasConstant() +--CREDIT-- +Marc Veldman +#testfest roosendaal on 2008-05-10 +--FILE-- +hasConstant('foo')); + +//C should not have constant bar +var_dump($rc->hasConstant('bar')); + +Class C { + const foo=1; +} +?> +--EXPECTF-- +bool(true) +bool(false) diff --git a/ext/reflection/tests/reflectionClass_hasMethod_basic.phpt b/ext/reflection/tests/reflectionClass_hasMethod_basic.phpt new file mode 100644 index 0000000000..3ef5ac9202 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_hasMethod_basic.phpt @@ -0,0 +1,57 @@ +--TEST-- +ReflectionClass::hasMethod() +--CREDIT-- +Marc Veldman +#testfest roosendaal on 2008-05-10 +--FILE-- +hasMethod('publicFoo')); + +//Check if C has protected method protectedFoo +var_dump($rc->hasMethod('protectedFoo')); + +//Check if C has private method privateFoo +var_dump($rc->hasMethod('privateFoo')); + +//Check if C has static method staticFoo +var_dump($rc->hasMethod('staticFoo')); + +//C should not have method bar +var_dump($rc->hasMethod('bar')); + +//Method names are case insensitive +var_dump($rc->hasMethod('PUBLICfOO')); + +Class C { + public function publicFoo() + { + return true; + } + + protected function protectedFoo() + { + return true; + } + + private function privateFoo() + { + return true; + } + + static function staticFoo() + { + return true; + } +} +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_hasProperty_basic.phpt b/ext/reflection/tests/reflectionClass_hasProperty_basic.phpt new file mode 100644 index 0000000000..b3264e01ed --- /dev/null +++ b/ext/reflection/tests/reflectionClass_hasProperty_basic.phpt @@ -0,0 +1,38 @@ +--TEST-- +ReflectionClass::hasProperty() +--CREDIT-- +Marc Veldman +#testfest roosendaal on 2008-05-10 +--FILE-- +hasProperty('publicFoo')); + +//Check if C has protected property protectedFoo +var_dump($rc->hasProperty('protectedFoo')); + +//Check if C has private property privateFoo +var_dump($rc->hasProperty('privateFoo')); + +//Check if C has static property staticFoo +var_dump($rc->hasProperty('staticFoo')); + +//C should not have property bar +var_dump($rc->hasProperty('bar')); + +Class C { + public $publicFoo; + protected $protectedFoo; + private $privateFoo; + public static $staticFoo; +} +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) diff --git a/ext/reflection/tests/reflectionClass_isAbstract_basic.phpt b/ext/reflection/tests/reflectionClass_isAbstract_basic.phpt new file mode 100644 index 0000000000..7a3d577ef6 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isAbstract_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionClass::isAbstract() method +--SKIPIF-- + +--CREDITS-- +Felix De Vliegher +#testfest roosendaal on 2008-05-10 +--FILE-- +isAbstract()); +var_dump($abstractClass->isAbstract()); + +?> +--EXPECT-- +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_isFinal_basic.phpt b/ext/reflection/tests/reflectionClass_isFinal_basic.phpt new file mode 100644 index 0000000000..efa131724e --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isFinal_basic.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionClass::isFinal() method +--SKIPIF-- + +--CREDITS-- +Felix De Vliegher +#testfest roosendaal on 2008-05-10 +--FILE-- +isFinal()); +var_dump($finalClass->isFinal()); + +?> +--EXPECT-- +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_isInterface_basic.phpt b/ext/reflection/tests/reflectionClass_isInterface_basic.phpt new file mode 100644 index 0000000000..2870725e83 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInterface_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +ReflectionClass::isInterface() method +--SKIPIF-- + +--CREDITS-- +Felix De Vliegher +#testfest roosendaal on 2008-05-10 +--FILE-- +isInterface()); +var_dump($reflectionClass2->isInterface()); +var_dump($reflectionClass3->isInterface()); + +?> +--EXPECT-- +bool(true) +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_isIterateable_basic.phpt b/ext/reflection/tests/reflectionClass_isIterateable_basic.phpt new file mode 100644 index 0000000000..3e1228af25 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isIterateable_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionClass::isIterateable() basic +--SKIPIF-- + +--CREDITS-- +Felix De Vliegher , Marc Veldman +--FILE-- +isIterateable()); +} + +$classes = array("ArrayObject", "IteratorClass", "DerivedClass", "NonIterator"); +foreach ($classes as $class) { + echo "Is $class iterateable? "; + dump_iterateable($class); +} +?> +--EXPECT-- +Is ArrayObject iterateable? bool(true) +Is IteratorClass iterateable? bool(true) +Is DerivedClass iterateable? bool(true) +Is NonIterator iterateable? bool(false) diff --git a/ext/reflection/tests/reflectionClass_isIterateable_variation1.phpt b/ext/reflection/tests/reflectionClass_isIterateable_variation1.phpt new file mode 100644 index 0000000000..6d737bb893 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isIterateable_variation1.phpt @@ -0,0 +1,27 @@ +--TEST-- +ReflectionClass::isIterateable() variations +--SKIPIF-- + +--CREDITS-- +Felix De Vliegher +--FILE-- +isIterateable()); +} + +$basicClass = new BasicClass(); +$stdClass = new StdClass(); + +dump_iterateable($basicClass); +dump_iterateable($stdClass); + +?> +--EXPECT-- +bool(false) +bool(false) diff --git a/ext/reflection/tests/reflectionObject___toString_basic1.phpt b/ext/reflection/tests/reflectionObject___toString_basic1.phpt new file mode 100644 index 0000000000..fefa220c9e --- /dev/null +++ b/ext/reflection/tests/reflectionObject___toString_basic1.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionObject::__toString() : very basic test with no dynamic properties +--FILE-- + +--EXPECTF-- +Object of class [ class Foo ] { + @@ %s 3-5 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ public $bar ] + } + + - Dynamic properties [0] { + } + + - Methods [0] { + } +} \ No newline at end of file diff --git a/ext/reflection/tests/reflectionObject___toString_basic2.phpt b/ext/reflection/tests/reflectionObject___toString_basic2.phpt new file mode 100644 index 0000000000..332386afd3 --- /dev/null +++ b/ext/reflection/tests/reflectionObject___toString_basic2.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionObject::__toString() : very basic test with dynamic properties +--FILE-- +dynProp = 'hello'; +$f->dynProp2 = 'hello again'; +echo new ReflectionObject($f); + +?> +--EXPECTF-- +Object of class [ class Foo ] { + @@ %s 3-5 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ public $bar ] + } + + - Dynamic properties [2] { + Property [ public $dynProp ] + Property [ public $dynProp2 ] + } + + - Methods [0] { + } +} \ No newline at end of file diff --git a/ext/reflection/tests/reflectionObject_export_basic1.phpt b/ext/reflection/tests/reflectionObject_export_basic1.phpt new file mode 100644 index 0000000000..f7dfef8670 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_export_basic1.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionObject::export() : very basic test with no dynamic properties +--FILE-- + +--EXPECTF-- +Object of class [ class Foo ] { + @@ %s 3-5 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ public $bar ] + } + + - Dynamic properties [0] { + } + + - Methods [0] { + } +} \ No newline at end of file diff --git a/ext/reflection/tests/reflectionObject_export_basic2.phpt b/ext/reflection/tests/reflectionObject_export_basic2.phpt new file mode 100644 index 0000000000..277f06eaf5 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_export_basic2.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionObject::export() : very basic test with dynamic properties +--FILE-- +dynProp = 'hello'; +$f->dynProp2 = 'hello again'; +ReflectionObject::export($f); + +?> +--EXPECTF-- +Object of class [ class Foo ] { + @@ %s 3-5 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ public $bar ] + } + + - Dynamic properties [2] { + Property [ public $dynProp ] + Property [ public $dynProp2 ] + } + + - Methods [0] { + } +} \ No newline at end of file diff --git a/ext/reflection/tests/reflectionObject_export_basic3.phpt b/ext/reflection/tests/reflectionObject_export_basic3.phpt new file mode 100644 index 0000000000..7c1da34c93 --- /dev/null +++ b/ext/reflection/tests/reflectionObject_export_basic3.phpt @@ -0,0 +1,38 @@ +--TEST-- +ReflectionObject::export() - ensure dynamic property with same name as inherited private property is shown. +--FILE-- +p = 'value'; +ReflectionObject::export($Obj) +?> +--EXPECTF-- +Object of class [ class D extends C ] { + @@ %s 6-7 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Dynamic properties [0] { + } + + - Methods [0] { + } +} + diff --git a/ext/reflection/tests/reflectionProperty_constructor_variation1.phpt b/ext/reflection/tests/reflectionProperty_constructor_variation1.phpt new file mode 100644 index 0000000000..d61480377c --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_constructor_variation1.phpt @@ -0,0 +1,58 @@ +--TEST-- +ReflectionProperty::__construct(): ensure inherited private props can't be accessed through ReflectionProperty. +--FILE-- +getMessage(); + } + } +} + +class D extends C{ + static function testFromD() { + try { + $rp = new ReflectionProperty("D", "p"); + var_dump($rp); + } catch (Exception $e) { + echo $e->getMessage(); + } + } +} + +echo "--> Reflect inherited private from global scope:\n"; +try { + $rp = new ReflectionProperty("D", "p"); + var_dump($rp); +} catch (Exception $e) { + echo $e->getMessage(); +} + +echo "\n\n--> Reflect inherited private from declaring scope:\n"; +C::testFromC(); + +echo "\n\n--> Reflect inherited private from declaring scope via subclass:\n"; +D::testFromC(); + +echo "\n\n--> Reflect inherited private from subclass:\n"; +D::testFromD(); +?> +--EXPECTF-- +--> Reflect inherited private from global scope: +Property D::$p does not exist + +--> Reflect inherited private from declaring scope: +Property D::$p does not exist + +--> Reflect inherited private from declaring scope via subclass: +Property D::$p does not exist + +--> Reflect inherited private from subclass: +Property D::$p does not exist \ No newline at end of file -- 2.40.0