From: Zoe Slattery Date: Tue, 10 Jul 2007 16:25:15 +0000 (+0000) Subject: tests for reflectionClass X-Git-Tag: php-5.2.4RC1~197 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90fd8fd7e859bcf513e14ba1bbaa2dde3cd32239;p=php tests for reflectionClass --- diff --git a/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt b/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt new file mode 100644 index 0000000000..27b4bc24a1 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt @@ -0,0 +1,33 @@ +--TEST-- +ReflectionClass::getFileName(), ReflectionClass::getStartLine(), ReflectionClass::getEndLine() +--FILE-- +getFileName()); + +//Get the line number at the start of the definition of class C +var_dump($rc->getStartLine()); + +//Get the line number at the end of the definition of class C +var_dump($rc->getEndLine()); + +//Same tests as above but stdclass is internal - so all results should be false. +$rc = new ReflectionClass("stdClass"); +var_dump($rc->getFileName()); +var_dump($rc->getStartLine()); +var_dump($rc->getEndLine()); + +Class C { + +} +?> +--EXPECTF-- +string(%d) "%sreflectionClass_FileInfo_basic.php" +int(20) +int(22) +bool(false) +bool(false) +bool(false) diff --git a/ext/reflection/tests/reflectionClass_FileInfo_error.phpt b/ext/reflection/tests/reflectionClass_FileInfo_error.phpt new file mode 100644 index 0000000000..766cdf3b71 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_FileInfo_error.phpt @@ -0,0 +1,37 @@ +--TEST-- +ReflectionClass::getFileName(), ReflectionClass::getStartLine(), ReflectionClass::getEndLine() - bad params +--FILE-- +$method()); + var_dump($rc->$method(null)); + var_dump($rc->$method('X', 0)); +} +?> +--EXPECTF-- +string(%d) "%s" + +Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 9 +NULL + +Warning: Wrong parameter count for ReflectionClass::getFileName() in %s on line 10 +NULL +int(2) + +Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 9 +NULL + +Warning: Wrong parameter count for ReflectionClass::getStartLine() in %s on line 10 +NULL +int(2) + +Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 9 +NULL + +Warning: Wrong parameter count for ReflectionClass::getEndLine() in %s on line 10 +NULL \ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getConstant_basic.phpt b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt new file mode 100644 index 0000000000..6e051113d5 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +ReflectionClass::getConstants() +--FILE-- +getConstant('a')); + var_dump($rc->getConstant('doesntexist')); +} +?> +--EXPECTF-- +Reflecting on class C: +string(12) "hello from C" +bool(false) +Reflecting on class D: +string(12) "hello from C" +bool(false) +Reflecting on class E: +string(12) "hello from C" +bool(false) +Reflecting on class F: +string(12) "hello from F" +bool(false) +Reflecting on class X: +bool(false) +bool(false) diff --git a/ext/reflection/tests/reflectionClass_getConstant_error.phpt b/ext/reflection/tests/reflectionClass_getConstant_error.phpt new file mode 100644 index 0000000000..907d6d8b7a --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstant_error.phpt @@ -0,0 +1,37 @@ +--TEST-- +ReflectionClass::getConstant() - bad params +--FILE-- +getConstant()); +var_dump($rc->getConstant("myConst", "myConst")); +var_dump($rc->getConstant(null)); +var_dump($rc->getConstant(1)); +var_dump($rc->getConstant(1.5)); +var_dump($rc->getConstant(true)); +var_dump($rc->getConstant(array(1,2,3))); +var_dump($rc->getConstant(new C)); +?> +--EXPECTF-- +Check invalid params: + +Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 0 given in %s on line 8 +NULL + +Warning: ReflectionClass::getConstant() expects exactly 1 parameter, 2 given in %s on line 9 +NULL +bool(false) +bool(false) +bool(false) +bool(false) + +Warning: ReflectionClass::getConstant() expects parameter 1 to be string, array given in %s on line 14 +NULL + +Warning: ReflectionClass::getConstant() expects parameter 1 to be string, object given in %s on line 15 +NULL \ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getConstants_basic.phpt b/ext/reflection/tests/reflectionClass_getConstants_basic.phpt new file mode 100644 index 0000000000..9abdcc801a --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstants_basic.phpt @@ -0,0 +1,48 @@ +--TEST-- +ReflectionClass::getConstants() +--FILE-- +getConstants()); +} +?> +--EXPECTF-- +Constants from class C: +array(1) { + ["a"]=> + string(12) "hello from C" +} +Constants from class D: +array(1) { + ["a"]=> + string(12) "hello from C" +} +Constants from class E: +array(1) { + ["a"]=> + string(12) "hello from C" +} +Constants from class F: +array(1) { + ["a"]=> + string(12) "hello from F" +} +Constants from class X: +array(0) { +} diff --git a/ext/reflection/tests/reflectionClass_getConstants_error.phpt b/ext/reflection/tests/reflectionClass_getConstants_error.phpt new file mode 100644 index 0000000000..73c407d656 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstants_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +ReflectionClass::getConstants() +--FILE-- +getConstants('X'); +$rc->getConstants(true); +$rc->getConstants(null); +$rc->getConstants('A', 'B'); + +?> +--EXPECTF-- +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 8 + +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 9 + +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 10 + +Warning: Wrong parameter count for ReflectionClass::getConstants() in %s on line 11 diff --git a/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt b/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt new file mode 100644 index 0000000000..f3881c56db --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt @@ -0,0 +1,82 @@ +--TEST-- +ReflectionClass::getConstructor() +--FILE-- +getConstructor(); + if ($rm != null) { + echo "Constructor of $class: " . $rm->getName() . "\n"; + } else { + echo "No constructor for $class\n"; + } + +} + +?> +--EXPECTF-- + +Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line 26 + +Strict Standards: %s for class NewAndOldCtor in %s on line 31 +Constructor of NewCtor: __construct +Constructor of ExtendsNewCtor: __construct +Constructor of OldCtor: OldCtor +Constructor of ExtendsOldCtor: OldCtor +Constructor of OldAndNewCtor: __construct +Constructor of NewAndOldCtor: __construct +Constructor of B: B +Constructor of C: C +Constructor of D1: __construct +Constructor of D2: C +No constructor for X +No constructor for Y \ No newline at end of file diff --git a/ext/reflection/tests/reflectionClass_getConstructor_error.phpt b/ext/reflection/tests/reflectionClass_getConstructor_error.phpt new file mode 100644 index 0000000000..8892b1d6b0 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstructor_error.phpt @@ -0,0 +1,24 @@ +--TEST-- +ReflectionClass::getConstructor() - bad params +--FILE-- +getConstructor(null)); +var_dump($rc->getConstructor('X')); +var_dump($rc->getConstructor(true)); +var_dump($rc->getConstructor(array(1,2,3))); +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 4 +NULL + +Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 5 +NULL + +Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 6 +NULL + +Warning: Wrong parameter count for ReflectionClass::getConstructor() in %s on line 7 +NULL