Annotation of embedaddon/php/ext/reflection/tests/ReflectionProperty_setValue_error.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test ReflectionProperty::setValue() error cases.
! 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->setValue());
! 23: var_dump($propInfo->setValue($instance));
! 24:
! 25: echo "\nToo many args:\n";
! 26: var_dump($propInfo->setValue($instance, "NewValue", true));
! 27:
! 28: echo "\nWrong type of arg:\n";
! 29: var_dump($propInfo->setValue(true, "NewValue"));
! 30: $propInfo = new ReflectionProperty('TestClass', 'stat');
! 31:
! 32: echo "\nStatic property / too many args:\n";
! 33: var_dump($propInfo->setValue($instance, "NewValue", true));
! 34:
! 35: echo "\nStatic property / too few args:\n";
! 36: var_dump($propInfo->setValue("A new value"));
! 37: var_dump(TestClass::$stat);
! 38: var_dump($propInfo->setValue());
! 39: var_dump(TestClass::$stat);
! 40:
! 41: echo "\nStatic property / wrong type of arg:\n";
! 42: var_dump($propInfo->setValue(true, "Another new value"));
! 43: var_dump(TestClass::$stat);
! 44:
! 45: echo "\nProtected property:\n";
! 46: try {
! 47: $propInfo = new ReflectionProperty('TestClass', 'prot');
! 48: var_dump($propInfo->setValue($instance, "NewValue"));
! 49: }
! 50: catch(Exception $exc) {
! 51: echo $exc->getMessage();
! 52: }
! 53:
! 54: echo "\n\nInstance without property:\n";
! 55: $propInfo = new ReflectionProperty('TestClass', 'pub2');
! 56: var_dump($propInfo->setValue($instanceWithNoProperties, "NewValue"));
! 57: var_dump($instanceWithNoProperties->pub2);
! 58: ?>
! 59: --EXPECTF--
! 60: Too few args:
! 61:
! 62: Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 0 given in %s on line %d
! 63: NULL
! 64:
! 65: Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 1 given in %s on line %d
! 66: NULL
! 67:
! 68: Too many args:
! 69:
! 70: Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 3 given in %s on line %d
! 71: NULL
! 72:
! 73: Wrong type of arg:
! 74:
! 75: Warning: ReflectionProperty::setValue() expects parameter 1 to be object, boolean given in %s on line %d
! 76: NULL
! 77:
! 78: Static property / too many args:
! 79:
! 80: Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 3 given in %s on line %d
! 81: NULL
! 82:
! 83: Static property / too few args:
! 84: NULL
! 85: string(11) "A new value"
! 86:
! 87: Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 0 given in %s on line %d
! 88: NULL
! 89: string(11) "A new value"
! 90:
! 91: Static property / wrong type of arg:
! 92: NULL
! 93: string(17) "Another new value"
! 94:
! 95: Protected property:
! 96: Cannot access non-public member TestClass::prot
! 97:
! 98: Instance without property:
! 99: NULL
! 100: string(8) "NewValue"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>