summaryrefslogtreecommitdiff
path: root/ext/reflection
diff options
context:
space:
mode:
authorZoe Slattery <zoe@php.net>2007-07-10 16:25:15 +0000
committerZoe Slattery <zoe@php.net>2007-07-10 16:25:15 +0000
commit90fd8fd7e859bcf513e14ba1bbaa2dde3cd32239 (patch)
treefe509feae572a1ffb4da62d7f6f9c1901492b7a2 /ext/reflection
parentca854215dbf3a8c0576460969477d12ba4b90ce4 (diff)
downloadphp-git-90fd8fd7e859bcf513e14ba1bbaa2dde3cd32239.tar.gz
tests for reflectionClass
Diffstat (limited to 'ext/reflection')
-rw-r--r--ext/reflection/tests/reflectionClass_FileInfo_basic.phpt33
-rw-r--r--ext/reflection/tests/reflectionClass_FileInfo_error.phpt37
-rw-r--r--ext/reflection/tests/reflectionClass_getConstant_basic.phpt41
-rw-r--r--ext/reflection/tests/reflectionClass_getConstant_error.phpt37
-rw-r--r--ext/reflection/tests/reflectionClass_getConstants_basic.phpt48
-rw-r--r--ext/reflection/tests/reflectionClass_getConstants_error.phpt24
-rw-r--r--ext/reflection/tests/reflectionClass_getConstructor_basic.phpt82
-rw-r--r--ext/reflection/tests/reflectionClass_getConstructor_error.phpt24
8 files changed, 326 insertions, 0 deletions
diff --git a/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt b/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt
new file mode 100644
index 0000000000..27b4bc24a1
--- /dev/null
+++ b/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt
@@ -0,0 +1,33 @@
+--TEST--
+ReflectionClass::getFileName(), ReflectionClass::getStartLine(), ReflectionClass::getEndLine()
+--FILE--
+<?php
+//New instance of class C - defined below
+$rc = new ReflectionClass("C");
+
+//Get the file name of the PHP script in which C is defined
+var_dump($rc->getFileName());
+
+//Get the line number at the start of the definition of class C
+var_dump($rc->getStartLine());
+
+//Get the line number at the end of the definition of class C
+var_dump($rc->getEndLine());
+
+//Same tests as above but stdclass is internal - so all results should be false.
+$rc = new ReflectionClass("stdClass");
+var_dump($rc->getFileName());
+var_dump($rc->getStartLine());
+var_dump($rc->getEndLine());
+
+Class C {
+
+}
+?>
+--EXPECTF--
+string(%d) "%sreflectionClass_FileInfo_basic.php"
+int(20)
+int(22)
+bool(false)
+bool(false)
+bool(false)
diff --git a/ext/reflection/tests/reflectionClass_FileInfo_error.phpt b/ext/reflection/tests/reflectionClass_FileInfo_error.phpt
new file mode 100644
index 0000000000..766cdf3b71
--- /dev/null
+++ b/ext/reflection/tests/reflectionClass_FileInfo_error.phpt
@@ -0,0 +1,37 @@
+--TEST--
+ReflectionClass::getFileName(), ReflectionClass::getStartLine(), ReflectionClass::getEndLine() - bad params
+--FILE--
+<?php
+Class C { }
+
+$rc = new ReflectionClass("C");
+$methods = array("getFileName", "getStartLine", "getEndLine");
+
+foreach ($methods as $method) {
+ var_dump($rc->$method());
+ var_dump($rc->$method(null));
+ var_dump($rc->$method('X', 0));
+}
+?>
+--EXPECTF--
+string(%d) "%s"
+
+Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 10
+NULL
+int(2)
+
+Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 10
+NULL
+int(2)
+
+Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 9
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 10
+NULL \ No newline at end of file
diff --git a/ext/reflection/tests/reflectionClass_getConstant_basic.phpt b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt
new file mode 100644
index 0000000000..6e051113d5
--- /dev/null
+++ b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt
@@ -0,0 +1,41 @@
+--TEST--
+ReflectionClass::getConstants()
+--FILE--
+<?php
+class C {
+ const a = 'hello from C';
+}
+class D extends C {
+}
+class E extends D {
+}
+class F extends E {
+ const a = 'hello from F';
+}
+class X {
+}
+
+$classes = array("C", "D", "E", "F", "X");
+foreach($classes as $class) {
+ echo "Reflecting on class $class: \n";
+ $rc = new ReflectionClass($class);
+ var_dump($rc->getConstant('a'));
+ var_dump($rc->getConstant('doesntexist'));
+}
+?>
+--EXPECTF--
+Reflecting on class C:
+string(12) "hello from C"
+bool(false)
+Reflecting on class D:
+string(12) "hello from C"
+bool(false)
+Reflecting on class E:
+string(12) "hello from C"
+bool(false)
+Reflecting on class F:
+string(12) "hello from F"
+bool(false)
+Reflecting on class X:
+bool(false)
+bool(false)
diff --git a/ext/reflection/tests/reflectionClass_getConstant_error.phpt b/ext/reflection/tests/reflectionClass_getConstant_error.phpt
new file mode 100644
index 0000000000..907d6d8b7a
--- /dev/null
+++ b/ext/reflection/tests/reflectionClass_getConstant_error.phpt
@@ -0,0 +1,37 @@
+--TEST--
+ReflectionClass::getConstant() - bad params
+--FILE--
+<?php
+class C {
+ const myConst = 1;
+}
+
+$rc = new ReflectionClass("C");
+echo "Check invalid params:\n";
+var_dump($rc->getConstant());
+var_dump($rc->getConstant("myConst", "myConst"));
+var_dump($rc->getConstant(null));
+var_dump($rc->getConstant(1));
+var_dump($rc->getConstant(1.5));
+var_dump($rc->getConstant(true));
+var_dump($rc->getConstant(array(1,2,3)));
+var_dump($rc->getConstant(new C));
+?>
+--EXPECTF--
+Check invalid params:
+
+Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 0 given in %s on line 8
+NULL
+
+Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 2 given in %s on line 9
+NULL
+bool(false)
+bool(false)
+bool(false)
+bool(false)
+
+Warning: ReflectionClass::getConstant() expects parameter 1 to be string, array given in %s on line 14
+NULL
+
+Warning: ReflectionClass::getConstant() expects parameter 1 to be string, object given in %s on line 15
+NULL \ No newline at end of file
diff --git a/ext/reflection/tests/reflectionClass_getConstants_basic.phpt b/ext/reflection/tests/reflectionClass_getConstants_basic.phpt
new file mode 100644
index 0000000000..9abdcc801a
--- /dev/null
+++ b/ext/reflection/tests/reflectionClass_getConstants_basic.phpt
@@ -0,0 +1,48 @@
+--TEST--
+ReflectionClass::getConstants()
+--FILE--
+<?php
+class C {
+ const a = 'hello from C';
+}
+class D extends C {
+}
+class E extends D {
+}
+class F extends E {
+ const a = 'hello from F';
+}
+class X {
+}
+
+$classes = array('C', 'D', 'E', 'F', 'X');
+foreach($classes as $class) {
+ echo "Constants from class $class: \n";
+ $rc = new ReflectionClass($class);
+ var_dump($rc->getConstants());
+}
+?>
+--EXPECTF--
+Constants from class C:
+array(1) {
+ ["a"]=>
+ string(12) "hello from C"
+}
+Constants from class D:
+array(1) {
+ ["a"]=>
+ string(12) "hello from C"
+}
+Constants from class E:
+array(1) {
+ ["a"]=>
+ string(12) "hello from C"
+}
+Constants from class F:
+array(1) {
+ ["a"]=>
+ string(12) "hello from F"
+}
+Constants from class X:
+array(0) {
+}
diff --git a/ext/reflection/tests/reflectionClass_getConstants_error.phpt b/ext/reflection/tests/reflectionClass_getConstants_error.phpt
new file mode 100644
index 0000000000..73c407d656
--- /dev/null
+++ b/ext/reflection/tests/reflectionClass_getConstants_error.phpt
@@ -0,0 +1,24 @@
+--TEST--
+ReflectionClass::getConstants()
+--FILE--
+<?php
+class X {
+}
+
+$rc = new reflectionClass('X');
+
+//Test invalid arguments
+$rc->getConstants('X');
+$rc->getConstants(true);
+$rc->getConstants(null);
+$rc->getConstants('A', 'B');
+
+?>
+--EXPECTF--
+Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 8
+
+Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 9
+
+Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 10
+
+Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 11
diff --git a/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt b/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt
new file mode 100644
index 0000000000..f3881c56db
--- /dev/null
+++ b/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt
@@ -0,0 +1,82 @@
+--TEST--
+ReflectionClass::getConstructor()
+--FILE--
+<?php
+class NewCtor {
+ function __construct() {}
+}
+
+class ExtendsNewCtor extends NewCtor {
+}
+
+class OldCtor {
+ function OldCtor() {}
+}
+
+class ExtendsOldCtor extends OldCtor {
+}
+
+
+class X {
+ function Y() {}
+}
+
+class Y extends X {
+}
+
+class OldAndNewCtor {
+ function OldAndNewCtor() {}
+ function __construct() {}
+}
+
+class NewAndOldCtor {
+ function __construct() {}
+ function NewAndOldCtor() {}
+}
+class B {
+ function B() {}
+}
+
+class C extends B {
+ function C() {}
+}
+
+class D1 extends C {
+ function __construct() {}
+}
+
+class D2 extends C {
+}
+
+$classes = array('NewCtor', 'ExtendsNewCtor', 'OldCtor', 'ExtendsOldCtor',
+ 'OldAndNewCtor', 'NewAndOldCtor', 'B', 'C', 'D1', 'D2', 'X', 'Y');
+
+foreach ($classes as $class) {
+ $rc = new ReflectionClass($class);
+ $rm = $rc->getConstructor();
+ if ($rm != null) {
+ echo "Constructor of $class: " . $rm->getName() . "\n";
+ } else {
+ echo "No constructor for $class\n";
+ }
+
+}
+
+?>
+--EXPECTF--
+
+Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line 26
+
+Strict Standards: %s for class NewAndOldCtor in %s on line 31
+Constructor of NewCtor: __construct
+Constructor of ExtendsNewCtor: __construct
+Constructor of OldCtor: OldCtor
+Constructor of ExtendsOldCtor: OldCtor
+Constructor of OldAndNewCtor: __construct
+Constructor of NewAndOldCtor: __construct
+Constructor of B: B
+Constructor of C: C
+Constructor of D1: __construct
+Constructor of D2: C
+No constructor for X
+No constructor for Y \ No newline at end of file
diff --git a/ext/reflection/tests/reflectionClass_getConstructor_error.phpt b/ext/reflection/tests/reflectionClass_getConstructor_error.phpt
new file mode 100644
index 0000000000..8892b1d6b0
--- /dev/null
+++ b/ext/reflection/tests/reflectionClass_getConstructor_error.phpt
@@ -0,0 +1,24 @@
+--TEST--
+ReflectionClass::getConstructor() - bad params
+--FILE--
+<?php
+class C {}
+$rc = new ReflectionClass('C');
+var_dump($rc->getConstructor(null));
+var_dump($rc->getConstructor('X'));
+var_dump($rc->getConstructor(true));
+var_dump($rc->getConstructor(array(1,2,3)));
+?>
+--EXPECTF--
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 4
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 5
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 6
+NULL
+
+Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 7
+NULL