From: Robin Fernandes Date: Fri, 5 Dec 2008 22:12:07 +0000 (+0000) Subject: Add some class related tests, fix hard-coded object ID in serialize_001.phpt. X-Git-Tag: php-5.3.0beta1~504 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2057a9a3f955419bb7dfc739dbaa308cdfb9a302;p=php Add some class related tests, fix hard-coded object ID in serialize_001.phpt. --- diff --git a/tests/classes/__call_006.phpt b/tests/classes/__call_006.phpt new file mode 100644 index 0000000000..a65fafb823 --- /dev/null +++ b/tests/classes/__call_006.phpt @@ -0,0 +1,77 @@ +--TEST-- +Ensure exceptions are handled properly when thrown in __call. +--FILE-- + Invoke __call via simple method call.\n"; +try { + $a->unknown(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via scope resolution operator within instance.\n"; +try { + $a->test(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via scope resolution operator within child instance.\n"; +$b = new B(); +try { + $b->test(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via callback.\n"; +try { + call_user_func(array($b, 'unknownCallback'), 1,2,3); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} +?> +==DONE== +--EXPECTF-- +---> Invoke __call via simple method call. +object(A)#%d (0) { +} +Exception caught OK; continuing. + + +---> Invoke __call via scope resolution operator within instance. +object(A)#%d (0) { +} +Exception caught OK; continuing. + + +---> Invoke __call via scope resolution operator within child instance. +object(B)#%d (0) { +} +Exception caught OK; continuing. + + +---> Invoke __call via callback. +object(B)#%d (0) { +} +Exception caught OK; continuing. +==DONE== \ No newline at end of file diff --git a/tests/classes/__call_007.phpt b/tests/classes/__call_007.phpt new file mode 100644 index 0000000000..de225547db --- /dev/null +++ b/tests/classes/__call_007.phpt @@ -0,0 +1,74 @@ +--TEST-- +Ensure exceptions are handled properly when thrown in a statically declared __call. +--FILE-- + Invoke __call via simple method call.\n"; +try { + $a->unknown(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via scope resolution operator within instance.\n"; +try { + $a->test(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via scope resolution operator within child instance.\n"; +$b = new B(); +try { + $b->test(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via callback.\n"; +try { + call_user_func(array($b, 'unknownCallback'), 1,2,3); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} +?> +==DONE== +--EXPECTF-- +Warning: The magic method __call() must have public visibility and can not be static in %s on line 3 +---> Invoke __call via simple method call. +NULL +Exception caught OK; continuing. + + +---> Invoke __call via scope resolution operator within instance. +NULL +Exception caught OK; continuing. + + +---> Invoke __call via scope resolution operator within child instance. +NULL +Exception caught OK; continuing. + + +---> Invoke __call via callback. +NULL +Exception caught OK; continuing. +==DONE== \ No newline at end of file diff --git a/tests/classes/implicit_instantiation_001.phpt b/tests/classes/implicit_instantiation_001.phpt new file mode 100644 index 0000000000..460cdc97f2 --- /dev/null +++ b/tests/classes/implicit_instantiation_001.phpt @@ -0,0 +1,146 @@ +--TEST-- +Implicit object instantiation when accessing properties of non-object. +--FILE-- + $value) { + echo "\n\n---( \$c->$name )---"; + echo "\n --> Attempting implicit conversion to object using increment...\n"; + $c->$name->prop++; + $c->$name = $value; // reset value in case implicit conversion was successful + + echo "\n --> Attempting implicit conversion to object using assignment...\n"; + $c->$name->prop = "Implicit instantiation!"; + $c->$name = $value; // reset value in case implicit conversion was successful + + echo "\n --> Attempting implicit conversion to object using combined assignment...\n"; + $c->$name->prop .= " Implicit instantiation!"; +} + +echo "\n\n\n --> Resulting object:"; +var_dump($c); + +?> +--EXPECTF-- + + +---( $c->boolFalse )--- + --> Attempting implicit conversion to object using increment... + +Strict Standards: Creating default object from empty value in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Strict Standards: Creating default object from empty value in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Strict Standards: Creating default object from empty value in %s on line 26 + + +---( $c->emptyString )--- + --> Attempting implicit conversion to object using increment... + +Strict Standards: Creating default object from empty value in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Strict Standards: Creating default object from empty value in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Strict Standards: Creating default object from empty value in %s on line 26 + + +---( $c->null )--- + --> Attempting implicit conversion to object using increment... + +Strict Standards: Creating default object from empty value in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Strict Standards: Creating default object from empty value in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Strict Standards: Creating default object from empty value in %s on line 26 + + +---( $c->boolTrue )--- + --> Attempting implicit conversion to object using increment... + +Warning: Attempt to %s property of non-object in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Warning: Attempt to assign property of non-object in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Warning: Attempt to assign property of non-object in %s on line 26 + + +---( $c->nonEmptyString )--- + --> Attempting implicit conversion to object using increment... + +Warning: Attempt to %s property of non-object in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Warning: Attempt to assign property of non-object in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Warning: Attempt to assign property of non-object in %s on line 26 + + +---( $c->intZero )--- + --> Attempting implicit conversion to object using increment... + +Warning: Attempt to %s property of non-object in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Warning: Attempt to assign property of non-object in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Warning: Attempt to assign property of non-object in %s on line 26 + + + + --> Resulting object:object(C)#%d (6) { + [%u|b%"boolFalse"]=> + object(stdClass)#%d (1) { + [%u|b%"prop"]=> + %unicode|string%(24) " Implicit instantiation!" + } + [%u|b%"emptyString"]=> + object(stdClass)#%d (1) { + [%u|b%"prop"]=> + %unicode|string%(24) " Implicit instantiation!" + } + [%u|b%"null"]=> + object(stdClass)#%d (1) { + [%u|b%"prop"]=> + %unicode|string%(24) " Implicit instantiation!" + } + [%u|b%"boolTrue"]=> + bool(true) + [%u|b%"nonEmptyString"]=> + %unicode|string%(5) "hello" + [%u|b%"intZero"]=> + int(0) +} \ No newline at end of file diff --git a/tests/classes/inheritance_006.phpt b/tests/classes/inheritance_006.phpt new file mode 100644 index 0000000000..d51dafeede --- /dev/null +++ b/tests/classes/inheritance_006.phpt @@ -0,0 +1,24 @@ +--TEST-- +Private property inheritance check +--FILE-- + +--EXPECTF-- +object(C)#%d (2) { + [%u|b%"c":%u|b%"B":private]=> + NULL + [%u|b%"c":%u|b%"A":private]=> + NULL +} \ No newline at end of file diff --git a/tests/classes/inheritance_007.phpt b/tests/classes/inheritance_007.phpt new file mode 100644 index 0000000000..df6b96a550 --- /dev/null +++ b/tests/classes/inheritance_007.phpt @@ -0,0 +1,39 @@ +--TEST-- +Ensure inherited old-style constructor doesn't block other methods. +--FILE-- +getMethods()); + + +$b = new B(); +$b->a(); +$b->b(); + +?> +--EXPECTF-- +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + [%u|b%"name"]=> + %string|unicode%(1) "B" + [%u|b%"class"]=> + %string|unicode%(1) "B" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + [%u|b%"name"]=> + %string|unicode%(1) "A" + [%u|b%"class"]=> + %string|unicode%(1) "B" + } +} +In A::A +In A::A +In A::B \ No newline at end of file diff --git a/tests/classes/property_recreate_private.phpt b/tests/classes/property_recreate_private.phpt new file mode 100644 index 0000000000..8bcf485355 --- /dev/null +++ b/tests/classes/property_recreate_private.phpt @@ -0,0 +1,81 @@ +--TEST-- +Unsetting and recreating private properties. +--FILE-- +p); + } + function setPrivate() { + $this->p = 'changed'; + } +} + +class D extends C { + function setP() { + $this->p = 'changed in D'; + } +} + +echo "Unset and recreate a superclass's private property:\n"; +$d = new D; +$d->unsetPrivate(); +$d->setPrivate(); +var_dump($d); + +echo "\nUnset superclass's private property, and recreate it as public in subclass:\n"; +$d = new D; +$d->unsetPrivate(); +$d->setP(); +var_dump($d); + +echo "\nUnset superclass's private property, and recreate it as public at global scope:\n"; +$d = new D; +$d->unsetPrivate(); +$d->p = 'this will create a public property'; +var_dump($d); + + +echo "\n\nUnset and recreate a private property:\n"; +$c = new C; +$c->unsetPrivate(); +$c->setPrivate(); +var_dump($c); + +echo "\nUnset a private property, and attempt to recreate at global scope (expecting failure):\n"; +$c = new C; +$c->unsetPrivate(); +$c->p = 'this will fail'; +var_dump($c); +?> +==Done== +--EXPECTF-- +Unset and recreate a superclass's private property: +object(D)#%d (1) { + [%u|b%"p":%u|b%"C":private]=> + %unicode|string%(7) "changed" +} + +Unset superclass's private property, and recreate it as public in subclass: +object(D)#%d (1) { + [%u|b%"p"]=> + %unicode|string%(12) "changed in D" +} + +Unset superclass's private property, and recreate it as public at global scope: +object(D)#%d (1) { + [%u|b%"p"]=> + %unicode|string%(34) "this will create a public property" +} + + +Unset and recreate a private property: +object(C)#%d (1) { + [%u|b%"p":%u|b%"C":private]=> + %unicode|string%(7) "changed" +} + +Unset a private property, and attempt to recreate at global scope (expecting failure): + +Fatal error: Cannot access private property C::$p in %s on line 46 \ No newline at end of file diff --git a/tests/classes/property_recreate_protected.phpt b/tests/classes/property_recreate_protected.phpt new file mode 100644 index 0000000000..4da4de87ad --- /dev/null +++ b/tests/classes/property_recreate_protected.phpt @@ -0,0 +1,53 @@ +--TEST-- +Unsetting and recreating protected properties. +--FILE-- +p); + } + function setProtected() { + $this->p = 'changed'; + } +} + +class D extends C { + function setP() { + $this->p = 'changed in D'; + } +} + +$d = new D; +echo "Unset and recreate a protected property from property's declaring class scope:\n"; +$d->unsetProtected(); +$d->setProtected(); +var_dump($d); + +echo "\nUnset and recreate a protected property from subclass:\n"; +$d = new D; +$d->unsetProtected(); +$d->setP(); +var_dump($d); + +echo "\nUnset a protected property, and attempt to recreate it outside of scope (expected failure):\n"; +$d->unsetProtected(); +$d->p = 'this will fail'; +var_dump($d); +?> +--EXPECTF-- +Unset and recreate a protected property from property's declaring class scope: +object(D)#%d (1) { + [%u|b%"p":protected]=> + %unicode|string%(7) "changed" +} + +Unset and recreate a protected property from subclass: +object(D)#%d (1) { + [%u|b%"p":protected]=> + %unicode|string%(12) "changed in D" +} + +Unset a protected property, and attempt to recreate it outside of scope (expected failure): + +Fatal error: Cannot access protected property %s::$p in %s on line 32 \ No newline at end of file diff --git a/tests/classes/serialize_001.phpt b/tests/classes/serialize_001.phpt index 16c79d415e..142fc50fcd 100755 --- a/tests/classes/serialize_001.phpt +++ b/tests/classes/serialize_001.phpt @@ -47,19 +47,19 @@ foreach($tests as $data) ?> ===DONE=== ---EXPECT-- +--EXPECTF-- ========== -string(6) "String" +%unicode|string%(6) "String" Test::__construct(String) Test::serialize(String) Test::unserialize(String) -object(Test)#1 (1) { - ["data"]=> - string(6) "String" +object(Test)#%d (1) { + [%u|b%"data"]=> + %unicode|string%(6) "String" } -object(Test)#1 (1) { - ["data"]=> - string(6) "String" +object(Test)#%d (1) { + [%u|b%"data"]=> + %unicode|string%(6) "String" } ========== NULL diff --git a/tests/classes/static_properties_003.phpt b/tests/classes/static_properties_003.phpt new file mode 100644 index 0000000000..2441e41578 --- /dev/null +++ b/tests/classes/static_properties_003.phpt @@ -0,0 +1,49 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- + Access visible static prop like instance prop:\n"; +var_dump(isset($c->x)); +unset($c->x); +echo $c->x; +$c->x = 1; +$ref = 'ref'; +$c->x =& $ref; +var_dump($c->x, C::$x); + +echo "\n--> Access non-visible static prop like instance prop:\n"; +var_dump(isset($c->y)); +//unset($c->y); // Fatal error, tested in static_properties_003_error1.phpt +//echo $c->y; // Fatal error, tested in static_properties_003_error2.phpt +//$c->y = 1; // Fatal error, tested in static_properties_003_error3.phpt +//$c->y =& $ref; // Fatal error, tested in static_properties_003_error4.phpt +?> +==Done== +--EXPECTF-- +--> Access visible static prop like instance prop: +bool(false) + +Strict Standards: Accessing static property C::$x as non static in %s on line 11 + +Strict Standards: Accessing static property C::$x as non static in %s on line 12 + +Notice: Undefined property: C::$x in %s on line 12 + +Strict Standards: Accessing static property C::$x as non static in %s on line 13 + +Strict Standards: Accessing static property C::$x as non static in %s on line 15 + +Strict Standards: Accessing static property C::$x as non static in %s on line 16 +%unicode|string%(3) "ref" +%unicode|string%(5) "C::$x" + +--> Access non-visible static prop like instance prop: +bool(false) +==Done== \ No newline at end of file diff --git a/tests/classes/static_properties_003_error1.phpt b/tests/classes/static_properties_003_error1.phpt new file mode 100644 index 0000000000..7a5e3d931a --- /dev/null +++ b/tests/classes/static_properties_003_error1.phpt @@ -0,0 +1,18 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- + Access non-visible static prop like instance prop:\n"; +unset($c->y); +?> +==Done== +--EXPECTF-- + +--> Access non-visible static prop like instance prop: + +Fatal error: Cannot access protected property C::$y in %s on line 8 diff --git a/tests/classes/static_properties_003_error2.phpt b/tests/classes/static_properties_003_error2.phpt new file mode 100644 index 0000000000..589cc6909e --- /dev/null +++ b/tests/classes/static_properties_003_error2.phpt @@ -0,0 +1,18 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- + Access non-visible static prop like instance prop:\n"; +echo $c->y; +?> +==Done== +--EXPECTF-- + +--> Access non-visible static prop like instance prop: + +Fatal error: Cannot access protected property C::$y in %s on line 8 diff --git a/tests/classes/static_properties_003_error3.phpt b/tests/classes/static_properties_003_error3.phpt new file mode 100644 index 0000000000..3e01e0e42b --- /dev/null +++ b/tests/classes/static_properties_003_error3.phpt @@ -0,0 +1,18 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- + Access non-visible static prop like instance prop:\n"; +$c->y = 1; +?> +==Done== +--EXPECTF-- + +--> Access non-visible static prop like instance prop: + +Fatal error: Cannot access protected property C::$y in %s on line 8 diff --git a/tests/classes/static_properties_003_error4.phpt b/tests/classes/static_properties_003_error4.phpt new file mode 100644 index 0000000000..fd69a9ffb8 --- /dev/null +++ b/tests/classes/static_properties_003_error4.phpt @@ -0,0 +1,18 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- + Access non-visible static prop like instance prop:\n"; +$c->y =& $ref; +?> +==Done== +--EXPECTF-- + +--> Access non-visible static prop like instance prop: + +Fatal error: Cannot access protected property C::$y in %s on line 8 diff --git a/tests/classes/static_properties_004.phpt b/tests/classes/static_properties_004.phpt new file mode 100644 index 0000000000..ce1d19dcc1 --- /dev/null +++ b/tests/classes/static_properties_004.phpt @@ -0,0 +1,37 @@ +--TEST-- +Inherited static properties can be separated from their reference set. +--FILE-- + +==Done== +--EXPECTF-- +Inherited static properties refer to the same value accross classes: +%unicode|string%(8) "original" +%unicode|string%(8) "original" +%unicode|string%(8) "original" + +Changing one changes all the others: +%unicode|string%(11) "changed.all" +%unicode|string%(11) "changed.all" +%unicode|string%(11) "changed.all" + +But because this is implemented using PHP references, the reference set can easily be split: +%unicode|string%(11) "changed.all" +%unicode|string%(11) "changed.one" +%unicode|string%(11) "changed.all" +==Done== \ No newline at end of file diff --git a/tests/classes/type_hinting_005a.phpt b/tests/classes/type_hinting_005a.phpt new file mode 100644 index 0000000000..d487a44611 --- /dev/null +++ b/tests/classes/type_hinting_005a.phpt @@ -0,0 +1,18 @@ +--TEST-- +Check type hint compatibility in overrides with array hints. +--FILE-- + +==DONE== +--EXPECTF-- +Strict Standards: Declaration of D2::f() should be compatible with that of C::f() in %s on line 8 +Compatible hint. +Class hint, should be array. +==DONE== \ No newline at end of file diff --git a/tests/classes/type_hinting_005b.phpt b/tests/classes/type_hinting_005b.phpt new file mode 100644 index 0000000000..bc0d7686b5 --- /dev/null +++ b/tests/classes/type_hinting_005b.phpt @@ -0,0 +1,14 @@ +--TEST-- +Check type hint compatibility in overrides with array hints. +--FILE-- + +==DONE== +--EXPECTF-- +Strict Standards: Declaration of D::f() should be compatible with that of C::f() in %s on line 5 +No hint, should be array. +==DONE== \ No newline at end of file diff --git a/tests/classes/type_hinting_005c.phpt b/tests/classes/type_hinting_005c.phpt new file mode 100644 index 0000000000..d3b72412cd --- /dev/null +++ b/tests/classes/type_hinting_005c.phpt @@ -0,0 +1,14 @@ +--TEST-- +Check type hint compatibility in overrides with array hints. +--FILE-- + +==DONE== +--EXPECTF-- +Strict Standards: Declaration of D::f() should be compatible with that of C::f() in %s on line 5 +Array hint, should be class. +==DONE== \ No newline at end of file diff --git a/tests/classes/type_hinting_005d.phpt b/tests/classes/type_hinting_005d.phpt new file mode 100644 index 0000000000..60dda0ff24 --- /dev/null +++ b/tests/classes/type_hinting_005d.phpt @@ -0,0 +1,14 @@ +--TEST-- +Check type hint compatibility in overrides with array hints. +--FILE-- + +==DONE== +--EXPECTF-- +Strict Standards: Declaration of D::f() should be compatible with that of C::f() in %s on line 5 +Array hint, should be nothing. +==DONE== \ No newline at end of file