summaryrefslogtreecommitdiff
path: root/ext/reflection
diff options
context:
space:
mode:
authorRobin Fernandes <robinf@php.net>2008-05-22 21:53:59 +0000
committerRobin Fernandes <robinf@php.net>2008-05-22 21:53:59 +0000
commit066a3308774954c021a26a0bac87b1856596c853 (patch)
tree4bce6f1d36cf57429f6f98255f17770fa901f16a /ext/reflection
parent4b035dae5f66354928183c593facb08f98358be8 (diff)
downloadphp-git-066a3308774954c021a26a0bac87b1856596c853.tar.gz
Basic ReflectionClass tests (from Dutch TestFest)
Diffstat (limited to 'ext/reflection')
-rw-r--r--ext/reflection/tests/reflectionClass_getModifiers_basic.phpt39
-rw-r--r--ext/reflection/tests/reflectionClass_getParentClass.phpt21
-rw-r--r--ext/reflection/tests/reflectionClass_hasConstant_basic.phpt23
-rw-r--r--ext/reflection/tests/reflectionClass_hasMethod_basic.phpt57
-rw-r--r--ext/reflection/tests/reflectionClass_hasProperty_basic.phpt38
-rw-r--r--ext/reflection/tests/reflectionClass_isInterface_basic.phpt27
-rw-r--r--ext/reflection/tests/reflectionClass_isIterateable_basic.phpt36
-rw-r--r--ext/reflection/tests/reflectionClass_isIterateable_variation1.phpt27
8 files changed, 268 insertions, 0 deletions
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--
+<?php extension_loaded('reflection') or die('skip'); ?>
+--CREDITS--
+Felix De Vliegher <felix.devliegher@gmail.com>
+--FILE--
+<?php
+
+class a {}
+abstract class b {}
+final class c {}
+interface d {}
+class e implements d {}
+interface f extends d {}
+class g extends b {}
+
+function dump_modifiers($class) {
+ $obj = new ReflectionClass($class);
+ var_dump($obj->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..46884ca2ba
--- /dev/null
+++ b/ext/reflection/tests/reflectionClass_getParentClass.phpt
@@ -0,0 +1,21 @@
+--TEST--
+ReflectionClass::getParentClass()
+--CREDITS--
+Michelangelo van Dam <dragonbe@gmail.com>
+#testfest roosendaal on 2008-05-10
+--FILE--
+<?php
+
+class Foo {}
+
+class Bar extends Foo {}
+
+$rc1 = new ReflectionClass("Bar");
+var_dump($rc1->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 <marc@ibuildings.nl>
+#testfest roosendaal on 2008-05-10
+--FILE--
+<?php
+//New instance of class C - defined below
+$rc = new ReflectionClass("C");
+
+//Check if C has constant foo
+var_dump($rc->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 <marc@ibuildings.nl>
+#testfest roosendaal on 2008-05-10
+--FILE--
+<?php
+//New instance of class C - defined below
+$rc = new ReflectionClass("C");
+
+//Check if C has public method publicFoo
+var_dump($rc->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 <marc@ibuildings.nl>
+#testfest roosendaal on 2008-05-10
+--FILE--
+<?php
+//New instance of class C - defined below
+$rc = new ReflectionClass("C");
+
+//Check if C has public property publicFoo
+var_dump($rc->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--
+<?php extension_loaded('reflection') or die('skip'); ?>
+--CREDITS--
+Felix De Vliegher <felix.devliegher@gmail.com>
+#testfest roosendaal on 2008-05-10
+--FILE--
+<?php
+
+interface TestInterface {}
+class TestClass {}
+interface DerivedInterface extends TestInterface {}
+
+$reflectionClass = new ReflectionClass('TestInterface');
+$reflectionClass2 = new ReflectionClass('TestClass');
+$reflectionClass3 = new ReflectionClass('DerivedInterface');
+
+var_dump($reflectionClass->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--
+<?php extension_loaded('reflection') or die('skip'); ?>
+--CREDITS--
+Felix De Vliegher <felix.devliegher@gmail.com>, Marc Veldman <marc@ibuildings.nl>
+--FILE--
+<?php
+
+class IteratorClass implements Iterator {
+ public function __construct() { }
+ public function key() {}
+ public function current() {}
+ function next() {}
+ function valid() {}
+ function rewind() {}
+}
+class DerivedClass extends IteratorClass {}
+class NonIterator {}
+
+function dump_iterateable($class) {
+ $reflection = new ReflectionClass($class);
+ var_dump($reflection->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--
+<?php extension_loaded('reflection') or die('skip'); ?>
+--CREDITS--
+Felix De Vliegher <felix.devliegher@gmail.com>
+--FILE--
+<?php
+
+class BasicClass {}
+
+function dump_iterateable($obj)
+{
+ $reflection = new ReflectionClass($obj);
+ var_dump($reflection->isIterateable());
+}
+
+$basicClass = new BasicClass();
+$stdClass = new StdClass();
+
+dump_iterateable($basicClass);
+dump_iterateable($stdClass);
+
+?>
+--EXPECT--
+bool(false)
+bool(false)