From 50cd9a03829b7903b620fab7af7973485eeb6733 Mon Sep 17 00:00:00 2001 From: Robin Fernandes Date: Thu, 22 May 2008 21:54:01 +0000 Subject: [PATCH] Basic ReflectionClass tests (from Dutch TestFest) --- .../reflectionClass_getModifiers_basic.phpt | 39 +++++++++++++ .../tests/reflectionClass_getParentClass.phpt | 24 ++++++++ .../reflectionClass_hasConstant_basic.phpt | 23 ++++++++ .../reflectionClass_hasMethod_basic.phpt | 57 +++++++++++++++++++ .../reflectionClass_hasProperty_basic.phpt | 38 +++++++++++++ .../reflectionClass_isInterface_basic.phpt | 27 +++++++++ .../reflectionClass_isIterateable_basic.phpt | 36 ++++++++++++ ...lectionClass_isIterateable_variation1.phpt | 27 +++++++++ 8 files changed, 271 insertions(+) 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_isInterface_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isIterateable_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isIterateable_variation1.phpt diff --git a/ext/reflection/tests/reflectionClass_getModifiers_basic.phpt b/ext/reflection/tests/reflectionClass_getModifiers_basic.phpt new file mode 100644 index 0000000000..5d2592d17e --- /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(524288) +int(524416) +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..32c01aeafd --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getParentClass.phpt @@ -0,0 +1,24 @@ +--TEST-- +ReflectionClass::getParentClass() +--CREDITS-- +Michelangelo van Dam +#testfest roosendaal on 2008-05-10 +--FILE-- +getParentClass()); +?> +--EXPECTF-- +object(ReflectionClass)#%d (1) { + ["name"]=> + string(3) "Foo" +} +--UEXPECTF-- +object(ReflectionClass)#%d (1) { + [u"name"]=> + unicode(3) "Foo" +} \ No newline at end of file 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_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) -- 2.40.0