Annotation of embedaddon/php/ext/reflection/tests/ReflectionProperty_getValue_error.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test ReflectionProperty::getValue() errors.
                      3: --FILE--
                      4: <?php
                      5: 
                      6: class TestClass {
                      7:     public $pub;
                      8:     public $pub2 = 5;
                      9:     static public $stat = "static property";
                     10:     protected $prot = 4;
                     11:     private $priv = "keepOut";
                     12: }
                     13: 
                     14: class AnotherClass {
                     15: }
                     16: 
                     17: $instance = new TestClass();
                     18: $instanceWithNoProperties = new AnotherClass();
                     19: $propInfo = new ReflectionProperty('TestClass', 'pub2');
                     20: 
                     21: echo "Too few args:\n";
                     22: var_dump($propInfo->getValue());
                     23: 
                     24: echo "\nToo many args:\n";
                     25: var_dump($propInfo->getValue($instance, true));
                     26: 
                     27: echo "\nWrong type of arg:\n";
                     28: var_dump($propInfo->getValue(true));
                     29: 
                     30: echo "\nInstance without property:\n";
                     31: $propInfo = new ReflectionProperty('TestClass', 'stat');
                     32: 
                     33: echo "\nStatic property / too many args:\n";
                     34: var_dump($propInfo->getValue($instance, true));
                     35: 
                     36: echo "\nStatic property / wrong type of arg:\n";
                     37: var_dump($propInfo->getValue(true));
                     38: 
                     39: echo "\nProtected property:\n";
                     40: try {
                     41:     $propInfo = new ReflectionProperty('TestClass', 'prot');
                     42:     var_dump($propInfo->getValue($instance));
                     43: }
                     44: catch(Exception $exc) {
                     45:     echo $exc->getMessage();
                     46: }
                     47: 
                     48: echo "\n\nInstance without property:\n";
                     49: $propInfo = new ReflectionProperty('TestClass', 'pub2');
                     50: var_dump($propInfo->getValue($instanceWithNoProperties));
                     51: 
                     52: ?>
                     53: --EXPECTF--
                     54: Too few args:
                     55: 
                     56: Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 0 given in %s on line %d
                     57: NULL
                     58: 
                     59: Too many args:
                     60: 
                     61: Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 2 given in %s on line %d
                     62: NULL
                     63: 
                     64: Wrong type of arg:
                     65: 
                     66: Warning: ReflectionProperty::getValue() expects parameter 1 to be object, boolean given in %s on line %d
                     67: NULL
                     68: 
                     69: Instance without property:
                     70: 
                     71: Static property / too many args:
                     72: string(15) "static property"
                     73: 
                     74: Static property / wrong type of arg:
                     75: string(15) "static property"
                     76: 
                     77: Protected property:
                     78: Cannot access non-public member TestClass::prot
                     79: 
                     80: Instance without property:
                     81: NULL

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>