From: Zoe Slattery Date: Wed, 11 Jul 2007 20:11:34 +0000 (+0000) Subject: More reflectionClass tests X-Git-Tag: php-5.2.4RC1~178 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=addad7104838838e73ad1213cc57a1b7e6e5fbb3;p=php More reflectionClass tests --- diff --git a/ext/reflection/tests/reflectionClass_getName_basic.phpt b/ext/reflection/tests/reflectionClass_getName_basic.phpt new file mode 100644 index 0000000000..158413f158 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getName_basic.phpt @@ -0,0 +1,25 @@ +--TEST-- +ReflectionClass::getName() +--FILE-- +getName(), $r2->getName(), $r3->getName()); + +?> +--EXPECTF-- +string(8) "stdClass" +string(8) "stdClass" +string(10) "TrickClass" diff --git a/ext/reflection/tests/reflectionClass_getName_error.phpt b/ext/reflection/tests/reflectionClass_getName_error.phpt new file mode 100644 index 0000000000..6f5699c931 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getName_error.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionClass::getName() - invalid params +--FILE-- +getName('X')); +var_dump($r1->getName('X', true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getName() in %s on line 6 +NULL + diff --git a/ext/reflection/tests/reflectionClass_getName_error1.phpt b/ext/reflection/tests/reflectionClass_getName_error1.phpt new file mode 100644 index 0000000000..5590137f89 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getName_error1.phpt @@ -0,0 +1,8 @@ +--TEST-- +ReflectionClass::getName - forbid static invocation +--FILE-- + +--EXPECTF-- +Fatal error: Non-static method ReflectionClass::getName() cannot be called statically in %s on line 2 diff --git a/ext/reflection/tests/reflectionClass_isInstance_basic.phpt b/ext/reflection/tests/reflectionClass_isInstance_basic.phpt new file mode 100644 index 0000000000..e8b1e9d801 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstance_basic.phpt @@ -0,0 +1,51 @@ +--TEST-- +ReflectionClass::isInstance() +--FILE-- + new A, + "myB" => new B, + "myC" => new C, + "myX" => new X ); + +foreach ($classes as $class) { + $rc = new ReflectionClass($class); + + foreach ($instances as $name => $instance) { + echo "is $name a $class? "; + var_dump($rc->isInstance($instance)); + } + +} + +?> +--EXPECTF-- +is myA a A? bool(true) +is myB a A? bool(false) +is myC a A? bool(false) +is myX a A? bool(false) +is myA a B? bool(false) +is myB a B? bool(true) +is myC a B? bool(false) +is myX a B? bool(false) +is myA a C? bool(false) +is myB a C? bool(false) +is myC a C? bool(true) +is myX a C? bool(false) +is myA a I? bool(false) +is myB a I? bool(false) +is myC a I? bool(false) +is myX a I? bool(false) +is myA a X? bool(false) +is myB a X? bool(false) +is myC a X? bool(false) +is myX a X? bool(true) diff --git a/ext/reflection/tests/reflectionClass_isInstance_error.phpt b/ext/reflection/tests/reflectionClass_isInstance_error.phpt new file mode 100644 index 0000000000..2c4f49b7d0 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstance_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionClass::isInstance() - invalid params +--FILE-- +isInstance()); +var_dump($rc->isInstance($instance, $instance)); +var_dump($rc->isInstance(1)); +var_dump($rc->isInstance(1.5)); +var_dump($rc->isInstance(true)); +var_dump($rc->isInstance('X')); +var_dump($rc->isInstance(null)); + +?> +--EXPECTF-- +Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 0 given in %s on line 7 +NULL + +Warning: ReflectionClass::isInstance() expects exactly 1 parameter, 2 given in %s on line 8 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, %s given in %s on line 9 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, double given in %s on line 10 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, boolean given in %s on line 11 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, string given in %s on line 12 +NULL + +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, null given in %s on line 13 +NULL diff --git a/ext/reflection/tests/reflectionClass_isInstantiable_basic.phpt b/ext/reflection/tests/reflectionClass_isInstantiable_basic.phpt new file mode 100644 index 0000000000..6ebcfa99a9 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstantiable_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +ReflectionClass::IsInstantiable() +--FILE-- +IsInstantiable()); + +} + +?> +--EXPECTF-- +Is C instantiable? bool(true) +Is iface instantiable? bool(false) +Is ifaceImpl instantiable? bool(true) +Is abstractClass instantiable? bool(false) +Is D instantiable? bool(true) diff --git a/ext/reflection/tests/reflectionClass_isInstantiable_error.phpt b/ext/reflection/tests/reflectionClass_isInstantiable_error.phpt new file mode 100644 index 0000000000..cc31a2f42c --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstantiable_error.phpt @@ -0,0 +1,19 @@ +--TEST-- +ReflectionClass::IsInstantiable() +--FILE-- +IsInstantiable('X')); +var_dump($reflectionClass->IsInstantiable(0, null)); + +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 7 +NULL + +Warning: Wrong parameter count for ReflectionClass::isInstantiable() in %s on line 8 +NULL diff --git a/ext/reflection/tests/reflectionClass_isInstantiable_variation.phpt b/ext/reflection/tests/reflectionClass_isInstantiable_variation.phpt new file mode 100644 index 0000000000..1cf3e613e8 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstantiable_variation.phpt @@ -0,0 +1,50 @@ +--TEST-- +ReflectionClass::IsInstantiable() +--FILE-- +IsInstantiable()); +} + +?> +--EXPECTF-- +Is noCtor instantiable? bool(true) +Is publicCtorNew instantiable? bool(true) +Is protectedCtorNew instantiable? bool(false) +Is privateCtorNew instantiable? bool(false) +Is publicCtorOld instantiable? bool(true) +Is protectedCtorOld instantiable? bool(false) +Is privateCtorOld instantiable? bool(false) diff --git a/ext/reflection/tests/reflectionClass_isInternal_basic.phpt b/ext/reflection/tests/reflectionClass_isInternal_basic.phpt new file mode 100644 index 0000000000..2eaacb67f8 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInternal_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +ReflectionClass::isInternal() +--FILE-- +isInternal(), $r2->isInternal(), $r3->isInternal(), + $r4->isInternal(), $r5->isInternal()); +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) diff --git a/ext/reflection/tests/reflectionClass_isInternal_error.phpt b/ext/reflection/tests/reflectionClass_isInternal_error.phpt new file mode 100644 index 0000000000..b1117e8304 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInternal_error.phpt @@ -0,0 +1,14 @@ +--TEST-- +ReflectionClass::isInternal() - invalid params +--FILE-- +isInternal('X')); +var_dump($r1->isInternal('X', true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 3 +NULL + +Warning: Wrong parameter count for ReflectionClass::isInternal() in %s on line 4 +NULL diff --git a/ext/reflection/tests/reflectionClass_isSubclassOf_basic.phpt b/ext/reflection/tests/reflectionClass_isSubclassOf_basic.phpt new file mode 100644 index 0000000000..94fcf00ece --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isSubclassOf_basic.phpt @@ -0,0 +1,103 @@ +--TEST-- +ReflectionClass::isSubclassOf() +--FILE-- + $child) { + foreach ($rcs as $parentName => $parent) { + echo "Is " . $childName . " a subclass of " . $parentName . "? \n"; + echo " - Using object argument: "; + var_dump($child->isSubclassOf($parent)); + echo " - Using string argument: "; + var_dump($child->isSubclassOf($parentName)); + } +} +?> +--EXPECTF-- +Is A a subclass of A? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of B? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of I? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is A a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of A? + - Using object argument: bool(true) + - Using string argument: bool(true) +Is B a subclass of B? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of I? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is B a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is C a subclass of A? + - Using object argument: bool(true) + - Using string argument: bool(true) +Is C a subclass of B? + - Using object argument: bool(true) + - Using string argument: bool(true) +Is C a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is C a subclass of I? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is C a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of A? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of B? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of I? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is I a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of A? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of B? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of C? + - Using object argument: bool(false) + - Using string argument: bool(false) +Is X a subclass of I? + - Using object argument: bool(true) + - Using string argument: bool(true) +Is X a subclass of X? + - Using object argument: bool(false) + - Using string argument: bool(false) diff --git a/ext/reflection/tests/reflectionClass_isSubclassOf_error.phpt b/ext/reflection/tests/reflectionClass_isSubclassOf_error.phpt new file mode 100644 index 0000000000..7d929fafd7 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isSubclassOf_error.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionClass::isSubclassOf() - invalid number of parameters +--FILE-- +isSubclassOf()); +var_dump($rc->isSubclassOf('A',5)); + +?> +--EXPECTF-- +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 0 given in %s on line 5 +NULL + +Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 6 +NULL diff --git a/ext/reflection/tests/reflectionClass_isSubclassOf_error1.phpt b/ext/reflection/tests/reflectionClass_isSubclassOf_error1.phpt new file mode 100644 index 0000000000..2fabd023e6 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isSubclassOf_error1.phpt @@ -0,0 +1,16 @@ +--TEST-- +ReflectionClass::isSubclassOf() - non-existent class error +--FILE-- +isSubclassOf('X')); + +?> +--EXPECTF-- +Fatal error: Uncaught exception 'ReflectionException' with message 'Class X does not exist' in %s:5 +Stack trace: +#0 %s(5): ReflectionClass->isSubclassOf('X') +#1 {main} + thrown in %s on line 5 diff --git a/ext/reflection/tests/reflectionClass_isUserDefined_basic.phpt b/ext/reflection/tests/reflectionClass_isUserDefined_basic.phpt new file mode 100644 index 0000000000..af43fcefa4 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isUserDefined_basic.phpt @@ -0,0 +1,22 @@ +--TEST-- +ReflectionClass::isUserDefined() +--FILE-- +isUserDefined(), $r2->isUserDefined(), $r3->isUserDefined(), + $r4->isUserDefined(), $r5->isUserDefined()); +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) diff --git a/ext/reflection/tests/reflectionClass_isUserDefined_error.phpt b/ext/reflection/tests/reflectionClass_isUserDefined_error.phpt new file mode 100644 index 0000000000..077e4d6a6d --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isUserDefined_error.phpt @@ -0,0 +1,14 @@ +--TEST-- +ReflectionClass::isUserDefined() - invalid params. +--FILE-- +isUserDefined('X')); +var_dump($r1->isUserDefined('X', true)); +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 3 +NULL + +Warning: Wrong parameter count for ReflectionClass::isUserDefined() in %s on line 4 +NULL