From: Ant Phillips Date: Tue, 18 Nov 2008 15:36:48 +0000 (+0000) Subject: Reflection tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64... X-Git-Tag: php-5.3.0alpha2~140 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4126370491cc42427e96ada7883fa924f0bdef34;p=php Reflection tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows, Linux and Linux 64 bit). --- diff --git a/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt b/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt new file mode 100644 index 0000000000..3bf8f77ec6 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getDefaultProperties_001.phpt @@ -0,0 +1,198 @@ +--TEST-- +ReflectionClass::getDefaultProperties(), ReflectionClass::getStaticProperties() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getStaticProperties()); + echo "\n\n---- Default properties in $class ----\n"; + print_r($rc->getDefaultProperties()); +} + +?> +--EXPECTF-- +---- Static properties in A ---- +Array +( + [statPubC] => stat pubC in A + [statProtC] => stat protC in A + [statPrivC] => stat privC in A + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [statPrivA] => stat privA in A +) + + +---- Default properties in A ---- +Array +( + [statPubC] => stat pubC in A + [statProtC] => stat protC in A + [statPrivC] => stat privC in A + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [statPrivA] => stat privA in A + [pubC] => pubC in A + [protC] => protC in A + [privC] => privC in A + [pubA] => pubA in A + [protA] => protA in A + [privA] => privA in A +) + + +---- Static properties in B ---- +Array +( + [statPubC] => stat pubC in B + [statProtC] => stat protC in B + [statPrivC] => stat privC in A + [statPubB] => stat pubB in B + [statProtB] => stat protB in B + [statPrivB] => stat privB in B + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [statPrivA] => stat privA in A +) + + +---- Default properties in B ---- +Array +( + [statPubC] => stat pubC in B + [statProtC] => stat protC in B + [statPrivC] => stat privC in B + [statPubB] => stat pubB in B + [statProtB] => stat protB in B + [statPrivB] => stat privB in B + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [pubC] => pubC in B + [protC] => protC in B + [privC] => privC in B + [pubB] => pubB in B + [protB] => protB in B + [privB] => privB in B + [pubA] => pubA in A + [protA] => protA in A +) + + +---- Static properties in C ---- +Array +( + [statPubC] => stat pubC in C + [statProtC] => stat protC in C + [statPrivC] => stat privC in A + [statPubB] => stat pubB in B + [statProtB] => stat protB in B + [statPrivB] => stat privB in B + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [statPrivA] => stat privA in A +) + + +---- Default properties in C ---- +Array +( + [statPubC] => stat pubC in C + [statProtC] => stat protC in C + [statPrivC] => stat privC in C + [statPubB] => stat pubB in B + [statProtB] => stat protB in B + [statPubA] => stat pubA in A + [statProtA] => stat protA in A + [pubC] => pubC in C + [protC] => protC in C + [privC] => privC in C + [pubB] => pubB in B + [protB] => protB in B + [pubA] => pubA in A + [protA] => protA in A +) + + +---- Static properties in X ---- +Array +( + [statPubC] => stat pubC in X + [statProtC] => stat protC in X + [statPrivC] => stat privC in X +) + + +---- Default properties in X ---- +Array +( + [statPubC] => stat pubC in X + [statProtC] => stat protC in X + [statPrivC] => stat privC in X + [pubC] => pubC in X + [protC] => protC in X + [privC] => privC in X +) + diff --git a/ext/reflection/tests/ReflectionClass_getDefaultProperties_002.phpt b/ext/reflection/tests/ReflectionClass_getDefaultProperties_002.phpt new file mode 100644 index 0000000000..6012f08551 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getDefaultProperties_002.phpt @@ -0,0 +1,45 @@ +--TEST-- +ReflectionClass::getDefaultProperties(), ReflectionClass::getStaticProperties() - wrong param count +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getDefaultProperties(null)); +var_dump($rc->getDefaultProperties('X')); +var_dump($rc->getDefaultProperties(true)); +var_dump($rc->getDefaultProperties(array(1,2,3))); +var_dump($rc->getStaticProperties(null)); +var_dump($rc->getStaticProperties('X')); +var_dump($rc->getStaticProperties(true)); +var_dump($rc->getStaticProperties(array(1,2,3))); + +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 7 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDefaultProperties() in %s on line 8 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 9 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 10 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 11 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStaticProperties() in %s on line 12 +NULL \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt b/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt new file mode 100644 index 0000000000..5feb560ae1 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt @@ -0,0 +1,98 @@ +--TEST-- +ReflectionClass::getDocComment() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- + Doc comment for class $class:\n"; + $rc = new ReflectionClass($class); + var_dump($rc->getDocComment()); +} + + +?> +--EXPECTF-- + + +---> Doc comment for class A: +string(%d) "/** + + + My +Doc + * Comment +for A + +* */" + + +---> Doc comment for class B: +string(26) "/** My DocComment for B */" + + +---> Doc comment for class C: +bool(false) + + +---> Doc comment for class D: +bool(false) + + +---> Doc comment for class E: +bool(false) + + +---> Doc comment for class F: +bool(false) + + +---> Doc comment for class G: +string(27) "/** ** Doc comment for G */" + + +---> Doc comment for class I: +string(%d) "/** + * Interface doc comment + */" \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getDocComment_002.phpt b/ext/reflection/tests/ReflectionClass_getDocComment_002.phpt new file mode 100644 index 0000000000..6668a8b656 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getDocComment_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +ReflectionClass::getDocComment() - bad params +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getDocComment(null)); +var_dump($rc->getDocComment('X')); +var_dump($rc->getDocComment(true)); +var_dump($rc->getDocComment(array(1,2,3))); +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 4 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getDocComment() in %s on line 7 +NULL diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_001.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_001.phpt new file mode 100644 index 0000000000..42136003e7 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_001.phpt @@ -0,0 +1,311 @@ +--TEST-- +ReflectionClass::getInterfaces() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getInterfaces(); + // Sort interfaces so that tests do not fail because of wrong order. + ksort($interfaces); + print_r($interfaces); +} + +?> +--EXPECTF-- +---( Interfaces implemented by A0 )--- + Array +( +) +---( Interfaces implemented by A1 )--- + Array +( +) +---( Interfaces implemented by B0 )--- + Array +( +) +---( Interfaces implemented by B1 )--- + Array +( +) +---( Interfaces implemented by I0 )--- + Array +( +) +---( Interfaces implemented by I1 )--- + Array +( +) +---( Interfaces implemented by I2 )--- + Array +( +) +---( Interfaces implemented by I3 )--- + Array +( +) +---( Interfaces implemented by I4 )--- + Array +( + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by I5 )--- + Array +( + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + +) +---( Interfaces implemented by I6 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + +) +---( Interfaces implemented by I7 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + + [I6] => ReflectionClass Object + ( + [name] => I6 + ) + +) +---( Interfaces implemented by C0 )--- + Array +( + [I0] => ReflectionClass Object + ( + [name] => I0 + ) + +) +---( Interfaces implemented by C1 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by C2 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by C3 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by C4 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + +) +---( Interfaces implemented by C5 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + + [I6] => ReflectionClass Object + ( + [name] => I6 + ) + + [I7] => ReflectionClass Object + ( + [name] => I7 + ) + +) +---( Interfaces implemented by C6 )--- + Array +( + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + + [I6] => ReflectionClass Object + ( + [name] => I6 + ) + + [I7] => ReflectionClass Object + ( + [name] => I7 + ) + +) diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt new file mode 100644 index 0000000000..328a7c3e69 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt @@ -0,0 +1,53 @@ +--TEST-- +ReflectionClass::getInterfaces() - interface ordering. +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getInterfaces(); +print_r($interfaces); +?> +--EXPECTF-- +Array +( + [I6] => ReflectionClass Object + ( + [name] => I6 + ) + + [I2] => ReflectionClass Object + ( + [name] => I2 + ) + + [I1] => ReflectionClass Object + ( + [name] => I1 + ) + + [I4] => ReflectionClass Object + ( + [name] => I4 + ) + + [I3] => ReflectionClass Object + ( + [name] => I3 + ) + + [I5] => ReflectionClass Object + ( + [name] => I5 + ) + +) \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt new file mode 100644 index 0000000000..74044f7531 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt @@ -0,0 +1,69 @@ +--TEST-- +ReflectionClass::getInterfaces() - odd ampersand behaviour. +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +x = 1; +var_dump($a); + + +echo "\n\nObtain the array of interfaces implemented by C.\n"; +interface I {} +class C implements I {} +$rc = new ReflectionClass('C'); +$a = $rc->getInterfaces(); +echo "The result is an array in which each element is an object (an instance of ReflectionClass)\n"; +echo "Var_dumping this array shows that the elements are referenced. By what?\n"; +var_dump($a); + +echo "Modify the object, and it is apparently no longer referenced.\n"; +$a['I']->x = 1; +var_dump($a); + +?> +--EXPECTF-- +An object is in an array and is referenced. As expected, var_dumping the array shows '&': +array(1) { + [0]=> + &object(stdClass)#%d (0) { + } +} +Naturally, this remains true if we modify the object: +array(1) { + [0]=> + &object(stdClass)#%d (1) { + ["x"]=> + int(1) + } +} + + +Obtain the array of interfaces implemented by C. +The result is an array in which each element is an object (an instance of ReflectionClass) +Var_dumping this array shows that the elements are referenced. By what? +array(1) { + ["I"]=> + &object(ReflectionClass)#%d (1) { + ["name"]=> + string(1) "I" + } +} +Modify the object, and it is apparently no longer referenced. +array(1) { + ["I"]=> + object(ReflectionClass)#%d (2) { + ["name"]=> + string(1) "I" + ["x"]=> + int(1) + } +} \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_004.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_004.phpt new file mode 100644 index 0000000000..5f42e4736d --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_004.phpt @@ -0,0 +1,28 @@ +--TEST-- +ReflectionClass::getInterfaces() - wrong param count +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getInterfaces(null)); +var_dump($rc->getInterfaces('X')); +var_dump($rc->getInterfaces(true)); +var_dump($rc->getInterfaces(array(1,2,3))); +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 7 +NULL + +Warning: Wrong parameter count for ReflectionClass::getInterfaces() in %s on line 8 +NULL diff --git a/ext/reflection/tests/ReflectionClass_getMethod_001.phpt b/ext/reflection/tests/ReflectionClass_getMethod_001.phpt new file mode 100644 index 0000000000..5821ebad0c --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethod_001.phpt @@ -0,0 +1,168 @@ +--TEST-- +ReflectionClass::getMethod() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- + Check for f(): "; + var_dump($rc->getMethod("f")); + echo " --> Check for s(): "; + var_dump($rc->getMethod("s")); + echo " --> Check for F(): "; + var_dump($rc->getMethod("F")); + echo " --> Check for doesntExist(): "; + try { + var_dump($rc->getMethod("doesntExist")); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } +} +?> +--EXPECTF-- +Reflecting on class pubf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(4) "pubf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(4) "pubf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(4) "pubf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class subpubf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(7) "subpubf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(7) "subpubf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(7) "subpubf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class protf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "protf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "protf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "protf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class subprotf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprotf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprotf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprotf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class privf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "privf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "privf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "privf" +} + --> Check for doesntExist(): Method doesntExist does not exist +Reflecting on class subprivf: + --> Check for f(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprivf" +} + --> Check for s(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprivf" +} + --> Check for F(): object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprivf" +} + --> Check for doesntExist(): Method doesntExist does not exist \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getMethod_002.phpt b/ext/reflection/tests/ReflectionClass_getMethod_002.phpt new file mode 100644 index 0000000000..2baabdedad --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethod_002.phpt @@ -0,0 +1,74 @@ +--TEST-- +ReflectionClass::getMethod() - error cases +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getMethod()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod("f", "f")); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(1)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(1.5)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(true)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(array(1,2,3))); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getMethod(new C)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + + +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::getMethod() expects exactly 1 parameter, 0 given in %s on line 9 +NULL + +Warning: ReflectionClass::getMethod() expects exactly 1 parameter, 2 given in %s on line 14 +NULL +Method does not exist +Method 1 does not exist +Method 1.5 does not exist +Method 1 does not exist + +Warning: ReflectionClass::getMethod() expects parameter 1 to be string, array given in %s on line 39 +NULL + +Warning: ReflectionClass::getMethod() expects parameter 1 to be string, object given in %s on line 44 +NULL \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getMethods_001.phpt b/ext/reflection/tests/ReflectionClass_getMethods_001.phpt new file mode 100644 index 0000000000..867d669adf --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethods_001.phpt @@ -0,0 +1,140 @@ +--TEST-- +ReflectionClass::getMethods() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getMethods()); +} + +?> +--EXPECTF-- +Reflecting on class pubf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(4) "pubf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(4) "pubf" + } +} +Reflecting on class subpubf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(7) "subpubf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(7) "subpubf" + } +} +Reflecting on class protf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "protf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "protf" + } +} +Reflecting on class subprotf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprotf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprotf" + } +} +Reflecting on class privf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(5) "privf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "privf" + } +} +Reflecting on class subprivf: +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "f" + ["class"]=> + string(8) "subprivf" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprivf" + } +} \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getMethods_002.phpt b/ext/reflection/tests/ReflectionClass_getMethods_002.phpt new file mode 100644 index 0000000000..b25222563b --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethods_002.phpt @@ -0,0 +1,18 @@ +--TEST-- +ReflectionClass::getMethods() - invalid arguments +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getMethods('X'); +$rc->getMethods('X', true); + +?> +--EXPECTF-- +Test invalid arguments: +Warning: ReflectionClass::getMethods() expects parameter 1 to be long, string given in %s on line 4 + +Warning: ReflectionClass::getMethods() expects at most 1 parameter, 2 given in %s on line 5 diff --git a/ext/reflection/tests/ReflectionClass_getMethods_003.phpt b/ext/reflection/tests/ReflectionClass_getMethods_003.phpt new file mode 100644 index 0000000000..435f5d2d8d --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getMethods_003.phpt @@ -0,0 +1,191 @@ +--TEST-- +ReflectionClass::getMethods() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getMethods(0)); + +echo "Public methods:"; +var_dump($rc->getMethods($pubFlag)); + +echo "Private methods:"; +var_dump($rc->getMethods($privFlag)); + +echo "Public or static methods:"; +var_dump($rc->getMethods($StaticFlag | $pubFlag)); + +echo "Private or static methods:"; +var_dump($rc->getMethods($StaticFlag | $privFlag)); + + +?> +--EXPECTF-- +No methods:array(0) { +} +Public methods:array(4) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(5) "pubf1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(5) "pubf2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf2" + ["class"]=> + string(1) "C" + } +} +Private methods:array(4) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "privf1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "privf2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf2" + ["class"]=> + string(1) "C" + } +} +Public or static methods:array(6) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(5) "pubf1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(5) "pubf2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf2" + ["class"]=> + string(1) "C" + } + [4]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf1" + ["class"]=> + string(1) "C" + } + [5]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf2" + ["class"]=> + string(1) "C" + } +} +Private or static methods:array(6) { + [0]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "privf1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "privf2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(6) "pubsf2" + ["class"]=> + string(1) "C" + } + [4]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf1" + ["class"]=> + string(1) "C" + } + [5]=> + &object(ReflectionMethod)#%d (2) { + ["name"]=> + string(7) "privsf2" + ["class"]=> + string(1) "C" + } +} diff --git a/ext/reflection/tests/ReflectionClass_getParentClass_001.phpt b/ext/reflection/tests/ReflectionClass_getParentClass_001.phpt new file mode 100644 index 0000000000..e26595a87b --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getParentClass_001.phpt @@ -0,0 +1,38 @@ +--TEST-- +ReflectionClass::getParentClass() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getParentClass(); +$grandParent = $parent->getParentClass(); +var_dump($parent, $grandParent); + +echo "\nTest bad params:\n"; +var_dump($rc->getParentClass(null)); +var_dump($rc->getParentClass('x')); +var_dump($rc->getParentClass('x', 123)); + +?> +--EXPECTF-- +object(ReflectionClass)#%d (1) { + ["name"]=> + string(1) "A" +} +bool(false) + +Test bad params: + +Warning: Wrong parameter count for ReflectionClass::getParentClass() in %s on line 11 +NULL + +Warning: Wrong parameter count for ReflectionClass::getParentClass() in %s on line 12 +NULL + +Warning: Wrong parameter count for ReflectionClass::getParentClass() in %s on line 13 +NULL \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperties_001.phpt b/ext/reflection/tests/ReflectionClass_getProperties_001.phpt new file mode 100644 index 0000000000..5eecc5dee4 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperties_001.phpt @@ -0,0 +1,126 @@ +--TEST-- +ReflectionClass::getProperties() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getProperties()); +} + +?> +--EXPECTF-- +Reflecting on class pubf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(4) "pubf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(4) "pubf" + } +} +Reflecting on class subpubf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(7) "subpubf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(7) "subpubf" + } +} +Reflecting on class protf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(5) "protf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "protf" + } +} +Reflecting on class subprotf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(8) "subprotf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprotf" + } +} +Reflecting on class privf: +array(2) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(5) "privf" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "privf" + } +} +Reflecting on class subprivf: +array(0) { +} \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperties_002.phpt b/ext/reflection/tests/ReflectionClass_getProperties_002.phpt new file mode 100644 index 0000000000..c21cff24f5 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperties_002.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionClass::getProperties() - invalid arguments +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getProperties('X'); +$rc->getProperties('X', true); +?> +--EXPECTF-- +Test invalid arguments: +Warning: ReflectionClass::getProperties() expects parameter 1 to be long, string given in %s on line 4 + +Warning: ReflectionClass::getProperties() expects at most 1 parameter, 2 given in %s on line 5 diff --git a/ext/reflection/tests/ReflectionClass_getProperties_003.phpt b/ext/reflection/tests/ReflectionClass_getProperties_003.phpt new file mode 100644 index 0000000000..b4f9a774db --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperties_003.phpt @@ -0,0 +1,189 @@ +--TEST-- +ReflectionClass::getProperties() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getProperties(0)); + +echo "Public properties:"; +var_dump($rc->getProperties($pubFlag)); + +echo "Private properties:"; +var_dump($rc->getProperties($privFlag)); + +echo "Public or static properties:"; +var_dump($rc->getProperties($StaticFlag | $pubFlag)); + +echo "Private or static properties:"; +var_dump($rc->getProperties($StaticFlag | $privFlag)); +?> +--EXPECTF-- +No properties:array(0) { +} +Public properties:array(4) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pub1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pub2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubs" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "pubs2" + ["class"]=> + string(1) "C" + } +} +Private properties:array(4) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "priv1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "priv2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs1" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs2" + ["class"]=> + string(1) "C" + } +} +Public or static properties:array(6) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pub1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pub2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubs" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "pubs2" + ["class"]=> + string(1) "C" + } + [4]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs1" + ["class"]=> + string(1) "C" + } + [5]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs2" + ["class"]=> + string(1) "C" + } +} +Private or static properties:array(6) { + [0]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "priv1" + ["class"]=> + string(1) "C" + } + [1]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "priv2" + ["class"]=> + string(1) "C" + } + [2]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubs" + ["class"]=> + string(1) "C" + } + [3]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "pubs2" + ["class"]=> + string(1) "C" + } + [4]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs1" + ["class"]=> + string(1) "C" + } + [5]=> + &object(ReflectionProperty)#%d (2) { + ["name"]=> + string(6) "privs2" + ["class"]=> + string(1) "C" + } +} \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperty_001.phpt b/ext/reflection/tests/ReflectionClass_getProperty_001.phpt new file mode 100644 index 0000000000..fa5deaa670 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperty_001.phpt @@ -0,0 +1,146 @@ +--TEST-- +ReflectionClass::getProperty() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- + Check for s: "; + var_dump($rc->getProperty("s")); + } catch (exception $e) { + echo $e->getMessage() . "\n"; + } + try { + echo " --> Check for a: "; + var_dump($rc->getProperty("a")); + } catch (exception $e) { + echo $e->getMessage() . "\n"; + } + try { + echo " --> Check for A: "; + var_dump($rc->getProperty("A")); + } catch (exception $e) { + echo $e->getMessage() . "\n"; + } + try { + echo " --> Check for doesntExist: "; + var_dump($rc->getProperty("doesntExist")); + } catch (exception $e) { + echo $e->getMessage() . "\n"; + } + +} +?> +--EXPECTF-- +Reflecting on class pubf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(4) "pubf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(4) "pubf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class subpubf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(7) "subpubf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(7) "subpubf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class protf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "protf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(5) "protf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class subprotf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprotf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(8) "subprotf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class privf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(5) "privf" +} + --> Check for a: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(5) "privf" +} + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist +Reflecting on class subprivf: + --> Check for s: object(ReflectionProperty)#%d (2) { + ["name"]=> + string(1) "s" + ["class"]=> + string(8) "subprivf" +} + --> Check for a: Property a does not exist + --> Check for A: Property A does not exist + --> Check for doesntExist: Property doesntExist does not exist \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperty_002.phpt b/ext/reflection/tests/ReflectionClass_getProperty_002.phpt new file mode 100644 index 0000000000..be7bb53bc8 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperty_002.phpt @@ -0,0 +1,72 @@ +--TEST-- +ReflectionClass::getProperty() - error cases +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getProperty()); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty("a", "a")); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(null)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(1)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(1.5)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(true)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(array(1,2,3))); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getProperty(new C)); +} catch (exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::getProperty() expects exactly 1 parameter, 0 given in %s on line 9 +NULL + +Warning: ReflectionClass::getProperty() expects exactly 1 parameter, 2 given in %s on line 14 +NULL +Property does not exist +Property 1 does not exist +Property 1.5 does not exist +Property 1 does not exist + +Warning: ReflectionClass::getProperty() expects parameter 1 to be string, array given in %s on line 39 +NULL + +Warning: ReflectionClass::getProperty() expects parameter 1 to be string, object given in %s on line 44 +NULL \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperty_003.phpt b/ext/reflection/tests/ReflectionClass_getProperty_003.phpt new file mode 100644 index 0000000000..dddd2260fe --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperty_003.phpt @@ -0,0 +1,251 @@ +--TEST-- +ReflectionClass::getProperty() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getProperty($name); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + return; + } + try { + var_dump($rp); + var_dump($rp->getValue($myC)); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + return; + } +} + + +showInfo("pubA"); +showInfo("protA"); +showInfo("privA"); + +showInfo("pubB"); +showInfo("protB"); +showInfo("privB"); + +showInfo("pubC"); +showInfo("protC"); +showInfo("privC"); +showInfo("doesntExist"); + +showInfo("A::pubC"); +showInfo("A::protC"); +showInfo("A::privC"); + +showInfo("B::pubC"); +showInfo("B::protC"); +showInfo("B::privC"); + +showInfo("c::pubC"); +showInfo("c::PUBC"); +showInfo("C::pubC"); +showInfo("C::protC"); +showInfo("C::privC"); + +showInfo("X::pubC"); +showInfo("X::protC"); +showInfo("X::privC"); +showInfo("X::doesntExist"); + +showInfo("doesntexist::doesntExist"); + +?> +--EXPECTF-- +--- (Reflecting on pubA) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubA" + ["class"]=> + string(1) "C" +} +string(9) "pubA in A" +--- (Reflecting on protA) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protA" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protA +--- (Reflecting on privA) --- +Property privA does not exist +--- (Reflecting on pubB) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubB" + ["class"]=> + string(1) "C" +} +string(9) "pubB in B" +--- (Reflecting on protB) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protB" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protB +--- (Reflecting on privB) --- +Property privB does not exist +--- (Reflecting on pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protC +--- (Reflecting on privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::privC +--- (Reflecting on doesntExist) --- +Property doesntExist does not exist +--- (Reflecting on A::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "A" +} +string(9) "pubC in A" +--- (Reflecting on A::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "A" +} +Cannot access non-public member A::protC +--- (Reflecting on A::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "A" +} +Cannot access non-public member A::privC +--- (Reflecting on B::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "B" +} +string(9) "pubC in B" +--- (Reflecting on B::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "B" +} +Cannot access non-public member B::protC +--- (Reflecting on B::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "B" +} +Cannot access non-public member B::privC +--- (Reflecting on c::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on c::PUBC) --- +Property PUBC does not exist +--- (Reflecting on C::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on C::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protC +--- (Reflecting on C::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::privC +--- (Reflecting on X::pubC) --- +Fully qualified property name X::pubC does not specify a base class of C +--- (Reflecting on X::protC) --- +Fully qualified property name X::protC does not specify a base class of C +--- (Reflecting on X::privC) --- +Fully qualified property name X::privC does not specify a base class of C +--- (Reflecting on X::doesntExist) --- +Fully qualified property name X::doesntExist does not specify a base class of C +--- (Reflecting on doesntexist::doesntExist) --- +Class doesntexist does not exist \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getProperty_004.phpt b/ext/reflection/tests/ReflectionClass_getProperty_004.phpt new file mode 100644 index 0000000000..791f5e1fa9 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getProperty_004.phpt @@ -0,0 +1,251 @@ +--TEST-- +ReflectionClass::getProperty() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getProperty($name); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + return; + } + try { + var_dump($rp); + var_dump($rp->getValue($myC)); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + return; + } +} + + +showInfo("pubA"); +showInfo("protA"); +showInfo("privA"); + +showInfo("pubB"); +showInfo("protB"); +showInfo("privB"); + +showInfo("pubC"); +showInfo("protC"); +showInfo("privC"); +showInfo("doesntExist"); + +showInfo("A::pubC"); +showInfo("A::protC"); +showInfo("A::privC"); + +showInfo("B::pubC"); +showInfo("B::protC"); +showInfo("B::privC"); + +showInfo("c::pubC"); +showInfo("c::PUBC"); +showInfo("C::pubC"); +showInfo("C::protC"); +showInfo("C::privC"); + +showInfo("X::pubC"); +showInfo("X::protC"); +showInfo("X::privC"); +showInfo("X::doesntExist"); + +showInfo("doesntexist::doesntExist"); + +?> +--EXPECTF-- +--- (Reflecting on pubA) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubA" + ["class"]=> + string(1) "C" +} +string(9) "pubA in A" +--- (Reflecting on protA) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protA" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protA +--- (Reflecting on privA) --- +Property privA does not exist +--- (Reflecting on pubB) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubB" + ["class"]=> + string(1) "C" +} +string(9) "pubB in B" +--- (Reflecting on protB) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protB" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protB +--- (Reflecting on privB) --- +Property privB does not exist +--- (Reflecting on pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protC +--- (Reflecting on privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::privC +--- (Reflecting on doesntExist) --- +Property doesntExist does not exist +--- (Reflecting on A::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "A" +} +string(9) "pubC in C" +--- (Reflecting on A::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "A" +} +Cannot access non-public member A::protC +--- (Reflecting on A::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "A" +} +Cannot access non-public member A::privC +--- (Reflecting on B::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "B" +} +string(9) "pubC in C" +--- (Reflecting on B::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "B" +} +Cannot access non-public member B::protC +--- (Reflecting on B::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "B" +} +Cannot access non-public member B::privC +--- (Reflecting on c::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on c::PUBC) --- +Property PUBC does not exist +--- (Reflecting on C::pubC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(4) "pubC" + ["class"]=> + string(1) "C" +} +string(9) "pubC in C" +--- (Reflecting on C::protC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "protC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::protC +--- (Reflecting on C::privC) --- +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(5) "privC" + ["class"]=> + string(1) "C" +} +Cannot access non-public member C::privC +--- (Reflecting on X::pubC) --- +Fully qualified property name X::pubC does not specify a base class of C +--- (Reflecting on X::protC) --- +Fully qualified property name X::protC does not specify a base class of C +--- (Reflecting on X::privC) --- +Fully qualified property name X::privC does not specify a base class of C +--- (Reflecting on X::doesntExist) --- +Fully qualified property name X::doesntExist does not specify a base class of C +--- (Reflecting on doesntexist::doesntExist) --- +Class doesntexist does not exist \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001.phpt b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001.phpt new file mode 100644 index 0000000000..733c4c7e4d --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001.phpt @@ -0,0 +1,67 @@ +--TEST-- +ReflectionClass::getStaticPropertyValue() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getStaticPropertyValue("privateOverridden", "default value")); +var_dump($rcA->getStaticPropertyValue("\0A\0privateOverridden")); +var_dump($rcA->getStaticPropertyValue("protectedOverridden", "default value")); +var_dump($rcA->getStaticPropertyValue("\0*\0protectedOverridden")); +var_dump($rcA->getStaticPropertyValue("publicOverridden")); + +echo "\nRetrieving static values from B:\n"; +$rcB = new ReflectionClass('B'); +var_dump($rcB->getStaticPropertyValue("\0A\0privateOverridden")); +var_dump($rcB->getStaticPropertyValue("\0B\0privateOverridden")); +var_dump($rcB->getStaticPropertyValue("\0*\0protectedOverridden")); +var_dump($rcB->getStaticPropertyValue("publicOverridden")); + +echo "\nRetrieving non-existent values from A with no default value:\n"; +try { + var_dump($rcA->getStaticPropertyValue("protectedOverridden")); + echo "you should not see this"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump($rcA->getStaticPropertyValue("privateOverridden")); + echo "you should not see this"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECTF-- +Retrieving static values from A: +string(13) "default value" +string(16) "original private" +string(13) "default value" +string(18) "original protected" +string(15) "original public" + +Retrieving static values from B: +string(16) "original private" +string(15) "changed private" +string(17) "changed protected" +string(14) "changed public" + +Retrieving non-existent values from A with no default value: +Class A does not have a property named protectedOverridden +Class A does not have a property named privateOverridden diff --git a/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_002.phpt b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_002.phpt new file mode 100644 index 0000000000..36b4744d8c --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_002.phpt @@ -0,0 +1,52 @@ +--TEST-- +ReflectionClass::getStaticPropertyValue() - bad params +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getStaticPropertyValue("x", "default value", 'blah')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getStaticPropertyValue()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getStaticPropertyValue(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getStaticPropertyValue(1.5, 'def')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->getStaticPropertyValue(array(1,2,3))); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + + +?> +--EXPECTF-- + +Warning: ReflectionClass::getStaticPropertyValue() expects at most 2 parameters, 3 given in %s on line 8 +NULL + +Warning: ReflectionClass::getStaticPropertyValue() expects at least 1 parameter, 0 given in %s on line 13 +NULL +Class C does not have a property named +string(3) "def" + +Warning: ReflectionClass::getStaticPropertyValue() expects parameter 1 to be string, array given in %s on line 28 +NULL \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_hasConstant_001.phpt b/ext/reflection/tests/ReflectionClass_hasConstant_001.phpt new file mode 100644 index 0000000000..6e6d4341c8 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasConstant_001.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionClass::hasConstant() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +hasConstant("myConst")); +echo "Check existing constant, different case: "; +var_dump($rc->hasConstant("MyCoNsT")); +echo "Check absent constant: "; +var_dump($rc->hasConstant("doesntExist")); + + +$rd = new ReflectionClass("D"); +echo "Check inherited constant: "; +var_dump($rd->hasConstant("myConst")); +echo "Check absent constant: "; +var_dump($rd->hasConstant("doesntExist")); +?> +--EXPECTF-- +Check existing constant: bool(true) +Check existing constant, different case: bool(false) +Check absent constant: bool(false) +Check inherited constant: bool(true) +Check absent constant: bool(false) \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_hasConstant_002.phpt b/ext/reflection/tests/ReflectionClass_hasConstant_002.phpt new file mode 100644 index 0000000000..a0a76f024a --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasConstant_002.phpt @@ -0,0 +1,40 @@ +--TEST-- +ReflectionClass::hasConstant() - error cases +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +hasConstant()); +var_dump($rc->hasConstant("myConst", "myConst")); +var_dump($rc->hasConstant(null)); +var_dump($rc->hasConstant(1)); +var_dump($rc->hasConstant(1.5)); +var_dump($rc->hasConstant(true)); +var_dump($rc->hasConstant(array(1,2,3))); +var_dump($rc->hasConstant(new C)); +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::hasConstant() expects exactly 1 parameter, 0 given in %s on line 8 +NULL + +Warning: ReflectionClass::hasConstant() expects exactly 1 parameter, 2 given in %s on line 9 +NULL +bool(false) +bool(false) +bool(false) +bool(false) + +Warning: ReflectionClass::hasConstant() expects parameter 1 to be string, array given in %s on line 14 +NULL + +Warning: ReflectionClass::hasConstant() 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_hasMethod_001.phpt b/ext/reflection/tests/ReflectionClass_hasMethod_001.phpt new file mode 100644 index 0000000000..81614bd9f8 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasMethod_001.phpt @@ -0,0 +1,75 @@ +--TEST-- +ReflectionClass::hasMethod() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- + Check for f(): "; + var_dump($rc->hasMethod("f")); + echo " --> Check for s(): "; + var_dump($rc->hasMethod("s")); + echo " --> Check for F(): "; + var_dump($rc->hasMethod("F")); + echo " --> Check for doesntExist(): "; + var_dump($rc->hasMethod("doesntExist")); +} +?> +--EXPECTF-- +Reflecting on class pubf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class subpubf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class protf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class subprotf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class privf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) +Reflecting on class subprivf: + --> Check for f(): bool(true) + --> Check for s(): bool(true) + --> Check for F(): bool(true) + --> Check for doesntExist(): bool(false) + \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_hasMethod_002.phpt b/ext/reflection/tests/ReflectionClass_hasMethod_002.phpt new file mode 100644 index 0000000000..63fe8791fc --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasMethod_002.phpt @@ -0,0 +1,40 @@ +--TEST-- +ReflectionClass::hasMethod() - error cases +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +hasMethod()); +var_dump($rc->hasMethod("f", "f")); +var_dump($rc->hasMethod(null)); +var_dump($rc->hasMethod(1)); +var_dump($rc->hasMethod(1.5)); +var_dump($rc->hasMethod(true)); +var_dump($rc->hasMethod(array(1,2,3))); +var_dump($rc->hasMethod(new C)); +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::hasMethod() expects exactly 1 parameter, 0 given in %s on line 8 +NULL + +Warning: ReflectionClass::hasMethod() expects exactly 1 parameter, 2 given in %s on line 9 +NULL +bool(false) +bool(false) +bool(false) +bool(false) + +Warning: ReflectionClass::hasMethod() expects parameter 1 to be string, array given in %s on line 14 +NULL + +Warning: ReflectionClass::hasMethod() expects parameter 1 to be string, object given in %s on line 15 +NULL diff --git a/ext/reflection/tests/ReflectionClass_hasProperty_001.phpt b/ext/reflection/tests/ReflectionClass_hasProperty_001.phpt new file mode 100644 index 0000000000..94f739c33c --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasProperty_001.phpt @@ -0,0 +1,75 @@ +--TEST-- +ReflectionClass::hasProperty() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- + Check for s: "; + var_dump($rc->hasProperty("s")); + echo " --> Check for a: "; + var_dump($rc->hasProperty("a")); + echo " --> Check for A: "; + var_dump($rc->hasProperty("A")); + echo " --> Check for doesntExist: "; + var_dump($rc->hasProperty("doesntExist")); +} +?> +--EXPECTF-- +Reflecting on class pubf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class subpubf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class protf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class subprotf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class privf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) +Reflecting on class subprivf: + --> Check for s: bool(true) + --> Check for a: bool(true) + --> Check for A: bool(false) + --> Check for doesntExist: bool(false) + diff --git a/ext/reflection/tests/ReflectionClass_hasProperty_002.phpt b/ext/reflection/tests/ReflectionClass_hasProperty_002.phpt new file mode 100644 index 0000000000..753890394f --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_hasProperty_002.phpt @@ -0,0 +1,40 @@ +--TEST-- +ReflectionClass::hasProperty() - error cases +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +hasProperty()); +var_dump($rc->hasProperty("a", "a")); +var_dump($rc->hasProperty(null)); +var_dump($rc->hasProperty(1)); +var_dump($rc->hasProperty(1.5)); +var_dump($rc->hasProperty(true)); +var_dump($rc->hasProperty(array(1,2,3))); +var_dump($rc->hasProperty(new C)); +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::hasProperty() expects exactly 1 parameter, 0 given in %s on line 8 +NULL + +Warning: ReflectionClass::hasProperty() expects exactly 1 parameter, 2 given in %s on line 9 +NULL +bool(false) +bool(false) +bool(false) +bool(false) + +Warning: ReflectionClass::hasProperty() expects parameter 1 to be string, array given in %s on line 14 +NULL + +Warning: ReflectionClass::hasProperty() expects parameter 1 to be string, object given in %s on line 15 +NULL diff --git a/ext/reflection/tests/ReflectionClass_implementsInterface_001.phpt b/ext/reflection/tests/ReflectionClass_implementsInterface_001.phpt new file mode 100644 index 0000000000..9c2fdedddb --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_implementsInterface_001.phpt @@ -0,0 +1,155 @@ +--TEST-- +ReflectionClass::implementsInterface() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- + $child) { + foreach ($rcs as $parentName => $parent) { + echo "Does " . $childName . " implement " . $parentName . "? \n"; + echo " - Using object argument: "; + try { + var_dump($child->implementsInterface($parent)); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + echo " - Using string argument: "; + try { + var_dump($child->implementsInterface($parentName)); + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } + } +} + + + +echo "\n\nTest bad arguments:\n"; +try { + var_dump($rcs['A']->implementsInterface()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rcs['A']->implementsInterface('C', 'C')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rcs['A']->implementsInterface(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rcs['A']->implementsInterface('ThisClassDoesNotExist')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rcs['A']->implementsInterface(2)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +Does A implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does A implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does A implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does A implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does A implement I2? + - Using object argument: bool(false) + - Using string argument: bool(false) +Does B implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does B implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does B implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does B implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does B implement I2? + - Using object argument: bool(false) + - Using string argument: bool(false) +Does C implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does C implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does C implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does C implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does C implement I2? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does I1 implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does I1 implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does I1 implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does I1 implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does I1 implement I2? + - Using object argument: bool(false) + - Using string argument: bool(false) +Does I2 implement A? + - Using object argument: Interface A is a Class + - Using string argument: Interface A is a Class +Does I2 implement B? + - Using object argument: Interface B is a Class + - Using string argument: Interface B is a Class +Does I2 implement C? + - Using object argument: Interface C is a Class + - Using string argument: Interface C is a Class +Does I2 implement I1? + - Using object argument: bool(true) + - Using string argument: bool(true) +Does I2 implement I2? + - Using object argument: bool(true) + - Using string argument: bool(true) + + +Test bad arguments: + +Warning: ReflectionClass::implementsInterface() expects exactly 1 parameter, 0 given in %s on line 37 +NULL + +Warning: ReflectionClass::implementsInterface() expects exactly 1 parameter, 2 given in %s on line 42 +NULL +Parameter one must either be a string or a ReflectionClass object +Interface ThisClassDoesNotExist does not exist +Parameter one must either be a string or a ReflectionClass object diff --git a/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt b/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt new file mode 100644 index 0000000000..3ece915427 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt @@ -0,0 +1,75 @@ +--TEST-- +ReflectionClass::isIterateable() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +isIterateable()); +} + +echo "\nTest invalid params:\n"; +$rc = new ReflectionClass('IteratorImpl'); +var_dump($rc->isIterateable(null)); +var_dump($rc->isIterateable(null, null)); +var_dump($rc->isIterateable(1)); +var_dump($rc->isIterateable(1.5)); +var_dump($rc->isIterateable(true)); +var_dump($rc->isIterateable('X')); +var_dump($rc->isIterateable(null)); + +echo "\nTest static invocation:\n"; +ReflectionClass::isIterateable(); + +?> +--EXPECTF-- +Is Traversable iterable? bool(false) +Is Iterator iterable? bool(false) +Is IteratorAggregate iterable? bool(false) +Is ExtendsIterator iterable? bool(false) +Is ExtendsIteratorAggregate iterable? bool(false) +Is IteratorImpl iterable? bool(true) +Is IterarorAggregateImpl iterable? bool(true) +Is ExtendsIteratorImpl iterable? bool(true) +Is ExtendsIteratorAggregateImpl iterable? bool(true) +Is A iterable? bool(false) + +Test invalid params: +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Test static invocation: + +Fatal error: Non-static method ReflectionClass::isIterateable() cannot be called statically in %s on line 43 \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_isSubclassOf_002.phpt b/ext/reflection/tests/ReflectionClass_isSubclassOf_002.phpt new file mode 100644 index 0000000000..083b277131 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_isSubclassOf_002.phpt @@ -0,0 +1,49 @@ +--TEST-- +ReflectionObject::isSubclassOf() - bad arguments +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +isSubclassOf()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->isSubclassOf('C', 'C')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->isSubclassOf(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->isSubclassOf('ThisClassDoesNotExist')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->isSubclassOf(2)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- + +Test bad arguments: + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 7 +NULL + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 12 +NULL +Parameter one must either be a string or a ReflectionClass object +Class ThisClassDoesNotExist does not exist +Parameter one must either be a string or a ReflectionClass object \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_modifiers_001.phpt b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt new file mode 100644 index 0000000000..941bfe5f2b --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt @@ -0,0 +1,44 @@ +--TEST-- +Modifiers +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +isFinal()); + var_dump($rc->isInterface()); + var_dump($rc->isAbstract()); + var_dump($rc->getModifiers()); +} +?> +--EXPECTF-- +bool(false) +bool(false) +bool(true) +int(32) +bool(false) +bool(false) +bool(false) +int(0) +bool(false) +bool(false) +bool(false) +int(0) +bool(true) +bool(false) +bool(false) +int(64) +bool(false) +bool(true) +bool(false) +int(128) \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_modifiers_002.phpt b/ext/reflection/tests/ReflectionClass_modifiers_002.phpt new file mode 100644 index 0000000000..3fa247454f --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_modifiers_002.phpt @@ -0,0 +1,28 @@ +--TEST-- +Modifiers - wrong param count +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +isFinal('X')); +var_dump($rc->isInterface(null)); +var_dump($rc->isAbstract(true)); +var_dump($rc->getModifiers(array(1,2,3))); + +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::isFinal() in %s on line 4 +NULL + +Warning: Wrong parameter count for ReflectionClass::isInterface() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::isAbstract() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getModifiers() in %s on line 7 +NULL diff --git a/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt b/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt new file mode 100644 index 0000000000..981d67519a --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt @@ -0,0 +1,98 @@ +--TEST-- +ReflectionClass::newInstanceArgs +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +newInstanceArgs(); +$a2 = $rcA->newInstanceArgs(array('x')); +var_dump($a1, $a2); + +$b1 = $rcB->newInstanceArgs(); +$b2 = $rcB->newInstanceArgs(array('x', 123)); +var_dump($b1, $b2); + +try { + $rcC->newInstanceArgs(); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +try { + $rcD->newInstanceArgs(); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +$e1 = $rcE->newInstanceArgs(); +var_dump($e1); + +try { + $e2 = $rcE->newInstanceArgs(array('x')); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +In constructor of class A +In constructor of class A +object(A)#%d (0) { +} +object(A)#%d (0) { +} + +Warning: Missing argument 1 for B::__construct() in %s on line 9 + +Warning: Missing argument 2 for B::__construct() in %s on line 9 + +Notice: Undefined variable: a in %s on line 10 + +Notice: Undefined variable: b in %s on line 10 +In constructor of class B with args , +In constructor of class B with args x, 123 +object(B)#%d (0) { +} +object(B)#%d (0) { +} +Access to non-public constructor of class C +Access to non-public constructor of class D +object(E)#%d (0) { +} +Class E does not have a constructor, so you cannot pass any constructor arguments \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt b/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt new file mode 100644 index 0000000000..af5aeff2df --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt @@ -0,0 +1,20 @@ +--TEST-- +ReflectionClass::newInstanceArgs() - wrong arg type +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +newInstanceArgs('x'); +var_dump($a); + +?> +--EXPECTF-- + +Catchable fatal error: Argument 1 passed to ReflectionClass::newInstanceArgs() must be an array, string given in %s on line 8 diff --git a/ext/reflection/tests/ReflectionClass_newInstance_001.phpt b/ext/reflection/tests/ReflectionClass_newInstance_001.phpt new file mode 100644 index 0000000000..3cdb5d76b7 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_newInstance_001.phpt @@ -0,0 +1,98 @@ +--TEST-- +ReflectionClass::newInstance() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +newInstance(); +$a2 = $rcA->newInstance('x'); +var_dump($a1, $a2); + +$b1 = $rcB->newInstance(); +$b2 = $rcB->newInstance('x', 123); +var_dump($b1, $b2); + +try { + $rcC->newInstance(); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +try { + $rcD->newInstance(); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +$e1 = $rcE->newInstance(); +var_dump($e1); + +try { + $e2 = $rcE->newInstance('x'); + echo "you should not see this\n"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +In constructor of class A +In constructor of class A +object(A)#%d (0) { +} +object(A)#%d (0) { +} + +Warning: Missing argument 1 for B::__construct() in %s on line 9 + +Warning: Missing argument 2 for B::__construct() in %s on line 9 + +Notice: Undefined variable: a in %s on line 10 + +Notice: Undefined variable: b in %s on line 10 +In constructor of class B with args , +In constructor of class B with args x, 123 +object(B)#%d (0) { +} +object(B)#%d (0) { +} +Access to non-public constructor of class C +Access to non-public constructor of class D +object(E)#%d (0) { +} +Class E does not have a constructor, so you cannot pass any constructor arguments \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt new file mode 100644 index 0000000000..70a3bab9c2 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001.phpt @@ -0,0 +1,77 @@ +--TEST-- +ReflectionClass::setStaticPropertyValue() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +setStaticPropertyValue("\0A\0privateOverridden", "new value 1"); +$rcA->setStaticPropertyValue("\0*\0protectedOverridden", "new value 2"); +$rcA->setStaticPropertyValue("publicOverridden", "new value 3"); +print_r($rcA->getStaticProperties()); + +echo "\nSet static values in B:\n"; +$rcB = new ReflectionClass('B'); +$rcB->setStaticPropertyValue("\0A\0privateOverridden", "new value 4"); +$rcB->setStaticPropertyValue("\0B\0privateOverridden", "new value 5"); +$rcB->setStaticPropertyValue("\0*\0protectedOverridden", "new value 6"); +$rcB->setStaticPropertyValue("publicOverridden", "new value 7"); +print_r($rcA->getStaticProperties()); +print_r($rcB->getStaticProperties()); + +echo "\nSet non-existent values from A with no default value:\n"; +try { + var_dump($rcA->setStaticPropertyValue("protectedOverridden", "new value 8")); + echo "you should not see this"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +try { + var_dump($rcA->setStaticPropertyValue("privateOverridden", "new value 9")); + echo "you should not see this"; +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + +?> +--EXPECTF-- +Set static values in A: +Array +( + [privateOverridden] => new value 1 + [protectedOverridden] => new value 2 + [publicOverridden] => new value 3 +) + +Set static values in B: +Array +( + [privateOverridden] => new value 4 + [protectedOverridden] => new value 2 + [publicOverridden] => new value 3 +) +Array +( + [privateOverridden] => new value 4 + [protectedOverridden] => new value 6 + [publicOverridden] => new value 7 +) + +Set non-existent values from A with no default value: +Class A does not have a property named protectedOverridden +Class A does not have a property named privateOverridden \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt new file mode 100644 index 0000000000..3244ec30b9 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt @@ -0,0 +1,60 @@ +--TEST-- +ReflectionClass::getStaticPropertyValue() - bad params +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +setStaticPropertyValue("x", "default value", 'blah')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue(null,null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue(1.5, 'def')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($rc->setStaticPropertyValue(array(1,2,3), 'blah')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} + + +?> +--EXPECTF-- + +Warning: ReflectionClass::setStaticPropertyValue() expects exactly 2 parameters, 3 given in %s on line 8 +NULL + +Warning: ReflectionClass::setStaticPropertyValue() expects exactly 2 parameters, 0 given in %s on line 13 +NULL + +Warning: ReflectionClass::setStaticPropertyValue() expects exactly 2 parameters, 1 given in %s on line 18 +NULL +Class C does not have a property named +Class C does not have a property named 1.5 + +Warning: ReflectionClass::setStaticPropertyValue() expects parameter 1 to be string, array given in %s on line 33 +NULL \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt new file mode 100644 index 0000000000..bf2221c78d --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -0,0 +1,233 @@ +--TEST-- +ReflectionClass::__toString() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- + +--EXPECTF-- +Class [ class ReflectionClass implements Reflector ] { + + - Constants [3] { + Constant [ integer IS_IMPLICIT_ABSTRACT ] { 16 } + Constant [ integer IS_EXPLICIT_ABSTRACT ] { 32 } + Constant [ integer IS_FINAL ] { 64 } + } + + - Static properties [0] { + } + + - Static methods [1] { + Method [ static public method export ] { + + - Parameters [2] { + Parameter #0 [ $argument ] + Parameter #1 [ $return ] + } + } + } + + - Properties [1] { + Property [ public $name ] + } + + - Methods [43] { + Method [ final private method __clone ] { + } + + Method [ public method __construct ] { + + - Parameters [1] { + Parameter #0 [ $argument ] + } + } + + Method [ public method __toString ] { + } + + Method [ public method getName ] { + } + + Method [ public method isInternal ] { + } + + Method [ public method isUserDefined ] { + } + + Method [ public method isInstantiable ] { + } + + Method [ public method getFileName ] { + } + + Method [ public method getStartLine ] { + } + + Method [ public method getEndLine ] { + } + + Method [ public method getDocComment ] { + } + + Method [ public method getConstructor ] { + } + + Method [ public method hasMethod ] { + + - Parameters [1] { + Parameter #0 [ $name ] + } + } + + Method [ public method getMethod ] { + + - Parameters [1] { + Parameter #0 [ $name ] + } + } + + Method [ public method getMethods ] { + + - Parameters [1] { + Parameter #0 [ $filter ] + } + } + + Method [ public method hasProperty ] { + + - Parameters [1] { + Parameter #0 [ $name ] + } + } + + Method [ public method getProperty ] { + + - Parameters [1] { + Parameter #0 [ $name ] + } + } + + Method [ public method getProperties ] { + + - Parameters [1] { + Parameter #0 [ $filter ] + } + } + + Method [ public method hasConstant ] { + + - Parameters [1] { + Parameter #0 [ $name ] + } + } + + Method [ public method getConstants ] { + } + + Method [ public method getConstant ] { + + - Parameters [1] { + Parameter #0 [ $name ] + } + } + + Method [ public method getInterfaces ] { + } + + Method [ public method getInterfaceNames ] { + } + + Method [ public method isInterface ] { + } + + Method [ public method isAbstract ] { + } + + Method [ public method isFinal ] { + } + + Method [ public method getModifiers ] { + } + + Method [ public method isInstance ] { + + - Parameters [1] { + Parameter #0 [ $object ] + } + } + + Method [ public method newInstance ] { + + - Parameters [1] { + Parameter #0 [ $args ] + } + } + + Method [ public method newInstanceArgs ] { + + - Parameters [1] { + Parameter #0 [ array $args ] + } + } + + Method [ public method getParentClass ] { + } + + Method [ public method isSubclassOf ] { + + - Parameters [1] { + Parameter #0 [ $class ] + } + } + + Method [ public method getStaticProperties ] { + } + + Method [ public method getStaticPropertyValue ] { + + - Parameters [2] { + Parameter #0 [ $name ] + Parameter #1 [ $default ] + } + } + + Method [ public method setStaticPropertyValue ] { + + - Parameters [2] { + Parameter #0 [ $name ] + Parameter #1 [ $value ] + } + } + + Method [ public method getDefaultProperties ] { + } + + Method [ public method isIterateable ] { + } + + Method [ public method implementsInterface ] { + + - Parameters [1] { + Parameter #0 [ $interface ] + } + } + + Method [ public method getExtension ] { + } + + Method [ public method getExtensionName ] { + } + + Method [ public method inNamespace ] { + } + + Method [ public method getNamespaceName ] { + } + + Method [ public method getShortName ] { + } + } +} diff --git a/ext/reflection/tests/ReflectionClass_toString_002.phpt b/ext/reflection/tests/ReflectionClass_toString_002.phpt new file mode 100644 index 0000000000..e9aaa502c6 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_toString_002.phpt @@ -0,0 +1,123 @@ +--TEST-- +ReflectionClass::__toString() - verify 'inherits', 'overwrites' and 'prototype' parts of method representation +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- + +--EXPECTF-- + + +----( Reflection class A: )---- +Class [ class A ] { + @@ %s 2-4 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ public method f ] { + @@ %s 3 - 3 + } + } +} + + +----( Reflection class B: )---- +Class [ class B extends A ] { + @@ %s 5-7 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ public method f ] { + @@ %s 6 - 6 + } + } +} + + +----( Reflection class C: )---- +Class [ class C extends B ] { + @@ %s 8-10 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ public method f ] { + @@ %s 6 - 6 + } + } +} + + +----( Reflection class D: )---- +Class [ class D extends C ] { + @@ %s 11-13 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ public method f ] { + @@ %s 12 - 12 + } + } +} \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_toString_003.phpt b/ext/reflection/tests/ReflectionClass_toString_003.phpt new file mode 100644 index 0000000000..ce5afb09ed --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_toString_003.phpt @@ -0,0 +1,120 @@ +--TEST-- +ReflectionClass::__toString() - verify 'inherits', 'overwrites' and 'prototype' parts of method representation with private methods +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- + +--EXPECTF-- + + +----( Reflection class A: )---- +Class [ class A ] { + @@ %s 2-4 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ private method f ] { + @@ %s 3 - 3 + } + } +} + + +----( Reflection class B: )---- +Class [ class B extends A ] { + @@ %s 5-7 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ private method f ] { + @@ %s 6 - 6 + } + } +} + + +----( Reflection class C: )---- +Class [ class C extends B ] { + @@ %s 8-10 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [0] { + } +} + + +----( Reflection class D: )---- +Class [ class D extends C ] { + @@ %s 11-13 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ private method f ] { + @@ %s 12 - 12 + } + } +} diff --git a/ext/reflection/tests/ReflectionFunction_001.phpt b/ext/reflection/tests/ReflectionFunction_001.phpt new file mode 100644 index 0000000000..7c592dc612 --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_001.phpt @@ -0,0 +1,67 @@ +--TEST-- +ReflectionFunction methods +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getName()); + var_dump($funcInfo->isInternal()); + var_dump($funcInfo->isUserDefined()); + var_dump($funcInfo->getStartLine()); + var_dump($funcInfo->getEndLine()); + var_dump($funcInfo->getStaticVariables()); +} + +dumpFuncInfo('foo'); +dumpFuncInfo('bar'); +dumpFuncInfo('extract'); + +?> +--EXPECT-- +string(3) "foo" +bool(false) +bool(true) +int(6) +int(11) +array(3) { + ["c"]=> + NULL + ["a"]=> + int(1) + ["b"]=> + string(5) "hello" +} +string(3) "bar" +bool(false) +bool(true) +int(16) +int(16) +array(0) { +} +string(7) "extract" +bool(true) +bool(false) +bool(false) +bool(false) +array(0) { +} \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionFunction_construct.001.phpt b/ext/reflection/tests/ReflectionFunction_construct.001.phpt new file mode 100644 index 0000000000..c8e0a17a9d --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_construct.001.phpt @@ -0,0 +1,23 @@ +--TEST-- +ReflectionFunction constructor errors +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getMessage(); +} +$a = new ReflectionFunction(); +$a = new ReflectionFunction(1, 2); +?> +--EXPECTF-- +Warning: ReflectionFunction::__construct() expects parameter 1 to be string, array given in %s on line %d +Function nonExistentFunction() does not exist +Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 0 given in %s on line %d + +Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 2 given in %s on line %d diff --git a/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt b/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt new file mode 100644 index 0000000000..38c278d8a3 --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt @@ -0,0 +1,41 @@ +--TEST-- +ReflectionFunction::getDocComment() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getDocComment()); +} + +dumpFuncInfo('foo'); +dumpFuncInfo('bar'); +dumpFuncInfo('extract'); + +?> +--EXPECTF-- +string(%d) "/** + * my doc comment + */" +bool(false) +bool(false) + diff --git a/ext/reflection/tests/ReflectionFunction_getFileName.001.phpt b/ext/reflection/tests/ReflectionFunction_getFileName.001.phpt new file mode 100644 index 0000000000..5dbe7b54b7 --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getFileName.001.phpt @@ -0,0 +1,18 @@ +--TEST-- +ReflectionFunction::getFileName() with function in an included file +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getFileName()); + +?> +--EXPECTF-- +%sincluded4.inc +%d +string(%d) "%sincluded4.inc" \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionFunction_getFileName.002.phpt b/ext/reflection/tests/ReflectionFunction_getFileName.002.phpt new file mode 100644 index 0000000000..455935e380 --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_getFileName.002.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionFunction::getFileName() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getFileName()); +} + +dumpFuncInfo('foo'); +dumpFuncInfo('bar'); +dumpFuncInfo('extract'); + +?> +--EXPECTF-- +string(%d) "%sReflectionFunction_getFileName.002.php" +string(%d) "%sReflectionFunction_getFileName.002.php" +bool(false) + diff --git a/ext/reflection/tests/ReflectionMethod_006.phpt b/ext/reflection/tests/ReflectionMethod_006.phpt new file mode 100644 index 0000000000..4a8192b9ed --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_006.phpt @@ -0,0 +1,100 @@ +--TEST-- +ReflectionMethod methods - wrong num args +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +isFinal(1)); +var_dump($rm->isAbstract(1)); +var_dump($rm->isPrivate(1)); +var_dump($rm->isProtected(1)); +var_dump($rm->isPublic(1)); +var_dump($rm->isStatic(1)); +var_dump($rm->isConstructor(1)); +var_dump($rm->isDestructor(1)); +var_dump($rm->getModifiers(1)); +var_dump($rm->isInternal(1)); +var_dump($rm->isUserDefined(1)); +var_dump($rm->getFileName(1)); +var_dump($rm->getStartLine(1)); +var_dump($rm->getEndLine(1)); +var_dump($rm->getStaticVariables(1)); +var_dump($rm->getName(1)); + + +?> +--EXPECTF-- +Warning: ReflectionMethod::__construct() expects %s on line 3 +object(ReflectionMethod)#%d (2) { + ["name"]=> + string(0) "" + ["class"]=> + string(0) "" +} + +Warning: ReflectionMethod::__construct() expects %s on line 4 +object(ReflectionMethod)#%d (2) { + ["name"]=> + string(0) "" + ["class"]=> + string(0) "" +} + +Warning: Wrong parameter count for ReflectionMethod::isFinal() in %s on line 12 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isAbstract() in %s on line 13 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isPrivate() in %s on line 14 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isProtected() in %s on line 15 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isPublic() in %s on line 16 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isStatic() in %s on line 17 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isConstructor() in %s on line 18 +NULL + +Warning: Wrong parameter count for ReflectionMethod::isDestructor() in %s on line 19 +NULL + +Warning: Wrong parameter count for ReflectionMethod::getModifiers() in %s on line 20 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::isInternal() in %s on line 21 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::isUserDefined() in %s on line 22 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getFileName() in %s on line 23 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getStartLine() in %s on line 24 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getEndLine() in %s on line 25 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getStaticVariables() in %s on line 26 +NULL + +Warning: Wrong parameter count for ReflectionFunctionAbstract::getName() in %s on line 27 +NULL \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt new file mode 100644 index 0000000000..70528255e7 --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt @@ -0,0 +1,103 @@ +--TEST-- +ReflectionMethod constructor errors +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +__toString(); +} +try { + echo "\nWrong type of argument (int):\n"; + $methodInfo = new ReflectionMethod(3); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nWrong type of argument (bool, string):\n"; + $methodInfo = new ReflectionMethod(true, "foo"); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nWrong type of argument (string, bool):\n"; + $methodInfo = new ReflectionMethod('TestClass', true); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nNo method given:\n"; + $methodInfo = new ReflectionMethod("TestClass"); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nClass and Method in same string, bad method name:\n"; + $methodInfo = new ReflectionMethod("TestClass::foop::dedoop"); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nClass and Method in same string, bad class name:\n"; + $methodInfo = new ReflectionMethod("TestCla::foo"); +} catch (Exception $e) { + print $e->__toString(); +} +try { + echo "\nClass and Method in same string (ok):\n"; + $methodInfo = new ReflectionMethod("TestClass::foo"); +} catch (Exception $e) { + print $e->__toString(); +} + +?> +--EXPECTF-- +Wrong type of argument (bool): +exception 'ReflectionException' with message 'Invalid method name 1' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('1') +#1 {main} +Wrong type of argument (int): +exception 'ReflectionException' with message 'Invalid method name 3' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('3') +#1 {main} +Wrong type of argument (bool, string): +exception 'ReflectionException' with message 'The parameter class is expected to be either a string or an object' in %s +Stack trace: +#0 %s ReflectionMethod->__construct(true, 'foo') +#1 {main} +Wrong type of argument (string, bool): +exception 'ReflectionException' with message 'Method TestClass::1() does not exist' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('TestClass', '1') +#1 {main} +No method given: +exception 'ReflectionException' with message 'Invalid method name TestClass' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('TestClass') +#1 {main} +Class and Method in same string, bad method name: +exception 'ReflectionException' with message 'Method TestClass::foop::dedoop() does not exist' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('TestClass::foop...') +#1 {main} +Class and Method in same string, bad class name: +exception 'ReflectionException' with message 'Class TestCla does not exist' in %s +Stack trace: +#0 %s ReflectionMethod->__construct('TestCla::foo') +#1 {main} +Class and Method in same string (ok): + diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt new file mode 100644 index 0000000000..1c2d3a138f --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt @@ -0,0 +1,37 @@ +--TEST-- +ReflectionMethod constructor errors +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +__toString(); +} +try { + echo "\nToo many arguments:\n"; + $methodInfo = new ReflectionMethod("TestClass", "foo", true); +} catch (Exception $e) { + print $e->__toString(); +} + +?> +--EXPECTF-- +Too few arguments: + +Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line 12 + +Too many arguments: + +Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line 18 diff --git a/ext/reflection/tests/ReflectionObject_isSubclassOf.002.phpt b/ext/reflection/tests/ReflectionObject_isSubclassOf.002.phpt new file mode 100644 index 0000000000..2fb8cb0870 --- /dev/null +++ b/ext/reflection/tests/ReflectionObject_isSubclassOf.002.phpt @@ -0,0 +1,48 @@ +--TEST-- +ReflectionObject::isSubclassOf() - bad arguments +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +isSubclassOf()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($ro->isSubclassOf('C', 'C')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($ro->isSubclassOf(null)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($ro->isSubclassOf('ThisClassDoesNotExist')); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +try { + var_dump($ro->isSubclassOf(2)); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +--EXPECTF-- +Test bad arguments: + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 7 +NULL + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 12 +NULL +Parameter one must either be a string or a ReflectionClass object +Class ThisClassDoesNotExist does not exist +Parameter one must either be a string or a ReflectionClass object \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionParameter_001.phpt b/ext/reflection/tests/ReflectionParameter_001.phpt new file mode 100644 index 0000000000..dae3ac7235 --- /dev/null +++ b/ext/reflection/tests/ReflectionParameter_001.phpt @@ -0,0 +1,80 @@ +--TEST-- +ReflectionParameter class - getNames() method. +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getParameters(); +echo "Parameters from twoArgMethod:\n\n"; +foreach($parameters as $parameter) { + var_dump($parameter); + $name = $parameter->getName(); + echo "\n"; +} + +$method = new ReflectionMethod('ReflectTestClass', 'oneArgNonStatic'); +$parameters = $method->getParameters(); +echo "Parameters from oneArgNonStatic:\n\n"; +foreach($parameters as $parameter) { + var_dump($parameter); + $name = $parameter->getName(); + echo "\n"; +} + + +$method = new ReflectionMethod('ReflectTestClass', 'noArgs'); +$parameters = $method->getParameters(); +echo "Parameters from noArgs:\n\n"; +var_dump($parameters); +foreach($parameters as $parameter) { + var_dump($parameter); + $name = $parameter->getName(); + echo "\n"; +} + +echo "done\n"; + +?> +--EXPECTF-- +Parameters from twoArgMethod: + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(12) "theIncrement" +} + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(12) "anotherParam" +} + +Parameters from oneArgNonStatic: + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(8) "theParam" +} + +Parameters from noArgs: + +array(0) { +} +done \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionParameter_002.phpt b/ext/reflection/tests/ReflectionParameter_002.phpt new file mode 100644 index 0000000000..3b7df6f95b --- /dev/null +++ b/ext/reflection/tests/ReflectionParameter_002.phpt @@ -0,0 +1,80 @@ +--TEST-- +ReflectionParameter class - isPassedByReferenceMethod() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getParameters(); +echo "Parameters from staticMethod:\n\n"; +foreach($parameters as $parameter) { + var_dump($parameter); + if($parameter->isPassedByReference()) { + echo "This param is passed by reference\n"; + } else { + echo "This param is not passed by reference\n"; + } + echo "\n"; +} + +// Create an instance of the Reflection_Method class +$method = new ReflectionMethod('ReflectTestClass', 'instanceMethod'); +// Get the parameters +$parameters = $method->getParameters(); +echo "Parameters from instanceMethod:\n\n"; +foreach($parameters as $parameter) { + var_dump($parameter); + if($parameter->isPassedByReference()) { + echo "This param is passed by reference\n"; + } else { + echo "This param is not passed by reference\n"; + } + echo "\n"; +} + +echo "done\n"; + +?> +--EXPECTF-- +Parameters from staticMethod: + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(8) "paramOne" +} +This param is passed by reference + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(12) "anotherParam" +} +This param is not passed by reference + +Parameters from instanceMethod: + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(10) "firstParam" +} +This param is not passed by reference + +object(ReflectionParameter)#%i (1) { + ["name"]=> + string(11) "secondParam" +} +This param is passed by reference + +done \ No newline at end of file diff --git a/ext/reflection/tests/ReflectionParameter_003.phpt b/ext/reflection/tests/ReflectionParameter_003.phpt new file mode 100644 index 0000000000..f7ced9ad00 --- /dev/null +++ b/ext/reflection/tests/ReflectionParameter_003.phpt @@ -0,0 +1,88 @@ +--TEST-- +ReflectionParameter class - isOptional, isDefaultValueAvailable and getDefaultValue methods. +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getParameters(); + +echo "parameter names from staticMethod method:\n\n"; +foreach($refParameters as $parameter) { + var_dump($parameter); + if($parameter->isOptional()) { + echo "this parameter is optional\n"; + } else { + echo "this parameter is not optional\n"; + } + + if($parameter->isDefaultValueAvailable()) { + echo "this parameter has a default value\n"; + } else { + echo "this parameter has no default value\n"; + } + + /* + $val = 0; + try { + $val = $parameter->getDefaultValue(); + var_dump($val); + } catch (ReflectionException $e) { + print $e->getMessage(); + echo "\n"; + } + */ + + echo "\n"; +} + +?> +--EXPECTF-- +hello from test +third is jack + +Notice: Undefined variable: theIncrement in %s on line 8 +parameter names from staticMethod method: + +object(ReflectionParameter)#%d (1) { + ["name"]=> + string(8) "paramOne" +} +this parameter is not optional +this parameter has no default value + +object(ReflectionParameter)#%d (1) { + ["name"]=> + string(12) "anotherParam" +} +this parameter is optional +this parameter has a default value + +object(ReflectionParameter)#%d (1) { + ["name"]=> + string(10) "thirdParam" +} +this parameter is optional +this parameter has a default value + +object(ReflectionParameter)#%d (1) { + ["name"]=> + string(10) "arrayParam" +} +this parameter is optional +this parameter has a default value diff --git a/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt b/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt new file mode 100644 index 0000000000..fe888a83bc --- /dev/null +++ b/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt @@ -0,0 +1,66 @@ +--TEST-- +ReflectionProperty::getModifiers() +--CREDITS-- +Robin Fernandes +Steve Seear +--FILE-- +getModifiers()); + + echo "\n**********************************\n"; +} + +class TestClass +{ + public $pub; + static public $stat = "static property"; + /** + * This property has a comment. + */ + protected $prot = 4; + private $priv = "keepOut"; +} + +reflectProperty("TestClass", "pub"); +reflectProperty("TestClass", "stat"); +reflectProperty("TestClass", "prot"); +reflectProperty("TestClass", "priv"); + +?> +--EXPECT-- +********************************** +Reflecting on property TestClass::pub + +getModifiers(): +int(256) + +********************************** +********************************** +Reflecting on property TestClass::stat + +getModifiers(): +int(257) + +********************************** +********************************** +Reflecting on property TestClass::prot + +getModifiers(): +int(512) + +********************************** +********************************** +Reflecting on property TestClass::priv + +getModifiers(): +int(1024) + +********************************** diff --git a/ext/reflection/tests/included4.inc b/ext/reflection/tests/included4.inc new file mode 100644 index 0000000000..88947251cd --- /dev/null +++ b/ext/reflection/tests/included4.inc @@ -0,0 +1,9 @@ + \ No newline at end of file