zoe Tue Jul 10 16:21:26 2007 UTC Added files: /php-src/ext/reflection/tests reflectionClass_getConstants_basic.phpt reflectionClass_FileInfo_basic.phpt reflectionClass_getConstant_error.phpt reflectionClass_getConstructor_error.phpt reflectionClass_getConstant_basic.phpt reflectionClass_getConstants_error.phpt reflectionClass_getConstructor_basic.phpt reflectionClass_FileInfo_error.phpt Log: Tests for reflectionClass
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionClass_getConstants_basic.phpt?view=markup&rev=1.1 Index: php-src/ext/reflection/tests/reflectionClass_getConstants_basic.phpt +++ php-src/ext/reflection/tests/reflectionClass_getConstants_basic.phpt --TEST-- ReflectionClass::getConstants() --FILE-- <?php class C { const a = 'hello from C'; } class D extends C { } class E extends D { } class F extends E { const a = 'hello from F'; } class X { }
$classes = array('C', 'D', 'E', 'F', 'X'); foreach($classes as $class) { echo "Constants from class $class: \n"; $rc = new ReflectionClass($class); var_dump($rc->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) { } http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt?view=markup&rev=1.1 Index: php-src/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt +++ php-src/ext/reflection/tests/reflectionClass_FileInfo_basic.phpt --TEST-- ReflectionClass::getFileName(), ReflectionClass::getStartLine(), ReflectionClass::getEndLine() --FILE-- <?php //New instance of class C - defined below $rc = new ReflectionClass("C"); //Get the file name of the PHP script in which C is defined var_dump($rc->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) http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionClass_getConstant_error.phpt?view=markup&rev=1.1 Index: php-src/ext/reflection/tests/reflectionClass_getConstant_error.phpt +++ php-src/ext/reflection/tests/reflectionClass_getConstant_error.phpt --TEST-- ReflectionClass::getConstant() - bad params --FILE-- <?php class C { const myConst = 1; } $rc = new ReflectionClass("C"); echo "Check invalid params:\n"; var_dump($rc->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 http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionClass_getConstructor_error.phpt?view=markup&rev=1.1 Index: php-src/ext/reflection/tests/reflectionClass_getConstructor_error.phpt +++ php-src/ext/reflection/tests/reflectionClass_getConstructor_error.phpt --TEST-- ReflectionClass::getConstructor() - bad params --FILE-- <?php class C {} $rc = new ReflectionClass('C'); var_dump($rc->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 http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionClass_getConstant_basic.phpt?view=markup&rev=1.1 Index: php-src/ext/reflection/tests/reflectionClass_getConstant_basic.phpt +++ php-src/ext/reflection/tests/reflectionClass_getConstant_basic.phpt --TEST-- ReflectionClass::getConstants() --FILE-- <?php class C { const a = 'hello from C'; } class D extends C { } class E extends D { } class F extends E { const a = 'hello from F'; } class X { } $classes = array("C", "D", "E", "F", "X"); foreach($classes as $class) { echo "Reflecting on class $class: \n"; $rc = new ReflectionClass($class); var_dump($rc->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) http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionClass_getConstants_error.phpt?view=markup&rev=1.1 Index: php-src/ext/reflection/tests/reflectionClass_getConstants_error.phpt +++ php-src/ext/reflection/tests/reflectionClass_getConstants_error.phpt --TEST-- ReflectionClass::getConstants() --FILE-- <?php class X { } $rc = new reflectionClass('X'); //Test invalid arguments $rc->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 http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt?view=markup&rev=1.1 Index: php-src/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt +++ php-src/ext/reflection/tests/reflectionClass_getConstructor_basic.phpt --TEST-- ReflectionClass::getConstructor() --FILE-- <?php class NewCtor { function __construct() {} } class ExtendsNewCtor extends NewCtor { } class OldCtor { function OldCtor() {} } class ExtendsOldCtor extends OldCtor { } class X { function Y() {} } class Y extends X { } class OldAndNewCtor { function OldAndNewCtor() {} function __construct() {} } class NewAndOldCtor { function __construct() {} function NewAndOldCtor() {} } class B { function B() {} } class C extends B { function C() {} } class D1 extends C { function __construct() {} } class D2 extends C { } $classes = array('NewCtor', 'ExtendsNewCtor', 'OldCtor', 'ExtendsOldCtor', 'OldAndNewCtor', 'NewAndOldCtor', 'B', 'C', 'D1', 'D2', 'X', 'Y'); foreach ($classes as $class) { $rc = new ReflectionClass($class); $rm = $rc->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 http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/reflectionClass_FileInfo_error.phpt?view=markup&rev=1.1 Index: php-src/ext/reflection/tests/reflectionClass_FileInfo_error.phpt +++ php-src/ext/reflection/tests/reflectionClass_FileInfo_error.phpt --TEST-- ReflectionClass::getFileName(), ReflectionClass::getStartLine(), ReflectionClass::getEndLine() - bad params --FILE-- <?php Class C { } $rc = new ReflectionClass("C"); $methods = array("getFileName", "getStartLine", "getEndLine"); foreach ($methods as $method) { var_dump($rc->$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
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php