From a8b455aa5bb48435c99dd10a5da0118a59bdce84 Mon Sep 17 00:00:00 2001 From: Zoe Slattery Date: Tue, 10 Jul 2007 16:21:26 +0000 Subject: [PATCH] Tests for reflectionClass --- .../tests/reflectionClass_FileInfo_basic.phpt | 40 ++++++++ .../tests/reflectionClass_FileInfo_error.phpt | 59 +++++++++++ .../reflectionClass_getConstant_basic.phpt | 57 +++++++++++ .../reflectionClass_getConstant_error.phpt | 55 +++++++++++ .../reflectionClass_getConstants_basic.phpt | 72 ++++++++++++++ .../reflectionClass_getConstants_error.phpt | 32 ++++++ .../reflectionClass_getConstructor_basic.phpt | 99 +++++++++++++++++++ .../reflectionClass_getConstructor_error.phpt | 24 +++++ 8 files changed, 438 insertions(+) create mode 100644 ext/reflection/tests/reflectionClass_FileInfo_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_FileInfo_error.phpt create mode 100644 ext/reflection/tests/reflectionClass_getConstant_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_getConstant_error.phpt create mode 100644 ext/reflection/tests/reflectionClass_getConstants_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_getConstants_error.phpt create mode 100644 ext/reflection/tests/reflectionClass_getConstructor_basic.phpt create mode 100644 ext/reflection/tests/reflectionClass_getConstructor_error.phpt diff --git a/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt b/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt new file mode 100644 index 0000000000..b987da664b --- /dev/null +++ b/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt @@ -0,0 +1,40 @@ +--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) +--UEXPECTF-- +unicode(%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..693af5d7c6 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_FileInfo_error.phpt @@ -0,0 +1,59 @@ +--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 +--UEXPECTF-- +unicode(%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 diff --git a/ext/reflection/tests/reflectionClass_getConstant_basic.phpt b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt new file mode 100644 index 0000000000..f1301fbb95 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstant_basic.phpt @@ -0,0 +1,57 @@ +--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) +--UEXPECTF-- +Reflecting on class C: +unicode(12) "hello from C" +bool(false) +Reflecting on class D: +unicode(12) "hello from C" +bool(false) +Reflecting on class E: +unicode(12) "hello from C" +bool(false) +Reflecting on class F: +unicode(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..f8a6deed6f --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstant_error.phpt @@ -0,0 +1,55 @@ +--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 (Unicode or binary), array given in %s on line 14 +NULL + +Warning: ReflectionClass::getConstant() expects parameter 1 to be string (Unicode or binary), object given in %s on line 15 +NULL +--UEXPECTF-- +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 (Unicode or binary), array given in %s on line 14 +NULL + +Warning: ReflectionClass::getConstant() expects parameter 1 to be string (Unicode or binary), object given in %s on line 15 +NULL diff --git a/ext/reflection/tests/reflectionClass_getConstants_basic.phpt b/ext/reflection/tests/reflectionClass_getConstants_basic.phpt new file mode 100644 index 0000000000..e01c1800af --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstants_basic.phpt @@ -0,0 +1,72 @@ +--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) { +} +--UEXPECTF-- +Constants from class C: +array(1) { + [u"a"]=> + unicode(12) "hello from C" +} +Constants from class D: +array(1) { + [u"a"]=> + unicode(12) "hello from C" +} +Constants from class E: +array(1) { + [u"a"]=> + unicode(12) "hello from C" +} +Constants from class F: +array(1) { + [u"a"]=> + unicode(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..5d724197fb --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstants_error.phpt @@ -0,0 +1,32 @@ +--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 +--UEXPECTF-- +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..1b5b2984f8 --- /dev/null +++ b/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt @@ -0,0 +1,99 @@ +--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 +--UEXPECTF-- + +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 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 -- 2.50.1