From fb148e495320f874166b765e1ed303c9f5f7aa3d Mon Sep 17 00:00:00 2001 From: Zoe Slattery Date: Wed, 11 Jul 2007 20:16:43 +0000 Subject: [PATCH] More reflectionClass tests --- .../tests/reflectionClass_getName_basic.phpt | 29 +++ .../tests/reflectionClass_getName_error.phpt | 23 +++ .../tests/reflectionClass_getName_error1.phpt | 10 + .../reflectionClass_isInstance_basic.phpt | 72 +++++++ .../reflectionClass_isInstance_error.phpt | 60 ++++++ .../reflectionClass_isInstantiable_basic.phpt | 46 +++++ .../reflectionClass_isInstantiable_error.phpt | 25 +++ ...lectionClass_isInstantiable_variation.phpt | 58 ++++++ .../reflectionClass_isInternal_basic.phpt | 28 +++ .../reflectionClass_isInternal_error.phpt | 20 ++ .../reflectionClass_isSubclassOf_basic.phpt | 179 ++++++++++++++++++ .../reflectionClass_isSubclassOf_error.phpt | 23 +++ .../reflectionClass_isSubclassOf_error1.phpt | 22 +++ .../reflectionClass_isUserDefined_basic.phpt | 28 +++ .../reflectionClass_isUserDefined_error.phpt | 20 ++ 15 files changed, 643 insertions(+) create mode 100644 ext/reflection/tests/reflectionClass_getName_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_getName_error.phpt create mode 100644 ext/reflection/tests/reflectionClass_getName_error1.phpt create mode 100644 ext/reflection/tests/reflectionClass_isInstance_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isInstance_error.phpt create mode 100644 ext/reflection/tests/reflectionClass_isInstantiable_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isInstantiable_error.phpt create mode 100644 ext/reflection/tests/reflectionClass_isInstantiable_variation.phpt create mode 100644 ext/reflection/tests/reflectionClass_isInternal_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isInternal_error.phpt create mode 100644 ext/reflection/tests/reflectionClass_isSubclassOf_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isSubclassOf_error.phpt create mode 100644 ext/reflection/tests/reflectionClass_isSubclassOf_error1.phpt create mode 100644 ext/reflection/tests/reflectionClass_isUserDefined_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_isUserDefined_error.phpt diff --git a/ext/reflection/tests/reflectionClass_getName_basic.phpt b/ext/reflection/tests/reflectionClass_getName_basic.phpt new file mode 100644 index 0000000000..2e6d78f458 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getName_basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +ReflectionClass::getName() +--FILE-- +getName(), $r2->getName(), $r3->getName()); + +?> +--EXPECTF-- +string(8) "stdClass" +string(8) "stdClass" +string(10) "TrickClass" +--UEXPECTF-- +unicode(8) "stdClass" +unicode(8) "stdClass" +unicode(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..4dcf8f5532 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getName_error.phpt @@ -0,0 +1,23 @@ +--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 +--UEXPECTF-- +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..de1f4aec24 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getName_error1.phpt @@ -0,0 +1,10 @@ +--TEST-- +ReflectionClass::getName - forbid static invocation +--FILE-- + +--EXPECTF-- +Fatal error: Non-static method ReflectionClass::getName() cannot be called statically in %s on line 2 +--UEXPECTF-- +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..07ec0cea79 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstance_basic.phpt @@ -0,0 +1,72 @@ +--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) +--UEXPECTF-- +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..1b0a605235 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstance_error.phpt @@ -0,0 +1,60 @@ +--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 +--UEXPECTF-- +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, Unicode 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..69d814c8af --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstantiable_basic.phpt @@ -0,0 +1,46 @@ +--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) +--UEXPECTF-- +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..5e7896785e --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstantiable_error.phpt @@ -0,0 +1,25 @@ +--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 +--UEXPECTF-- +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..50c5e58b50 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInstantiable_variation.phpt @@ -0,0 +1,58 @@ +--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) +--UEXPECTF-- +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..3b7ba4fd7b --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInternal_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +ReflectionClass::isInternal() +--FILE-- +isInternal(), $r2->isInternal(), $r3->isInternal(), + $r4->isInternal(), $r5->isInternal()); +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +--UEXPECTF-- +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..b8ab16f13f --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isInternal_error.phpt @@ -0,0 +1,20 @@ +--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 +--UEXPECTF-- +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..b50aab71d1 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isSubclassOf_basic.phpt @@ -0,0 +1,179 @@ +--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) +--UEXPECTF-- +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..732a34413b --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isSubclassOf_error.phpt @@ -0,0 +1,23 @@ +--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 +--UEXPECTF-- +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..71c3d700cf --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isSubclassOf_error1.phpt @@ -0,0 +1,22 @@ +--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 +--UEXPECTF-- +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..56d427f39c --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isUserDefined_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +ReflectionClass::isUserDefined() +--FILE-- +isUserDefined(), $r2->isUserDefined(), $r3->isUserDefined(), + $r4->isUserDefined(), $r5->isUserDefined()); +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +--UEXPECTF-- +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..d4aa1774af --- /dev/null +++ b/ext/reflection/tests/reflectionClass_isUserDefined_error.phpt @@ -0,0 +1,20 @@ +--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 +--UEXPECTF-- +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 -- 2.50.1