robinf          Fri Dec  5 22:12:08 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/tests/classes      inheritance_007.phpt inheritance_006.phpt 
                                implicit_instantiation_001.phpt 
                                property_recreate_private.phpt 
                                static_properties_004.phpt 
                                type_hinting_005d.phpt 
                                static_properties_003.phpt 
                                type_hinting_005c.phpt 
                                type_hinting_005b.phpt 
                                type_hinting_005a.phpt __call_007.phpt 
                                __call_006.phpt 
                                static_properties_003_error4.phpt 
                                static_properties_003_error3.phpt 
                                static_properties_003_error2.phpt 
                                property_recreate_protected.phpt 
                                static_properties_003_error1.phpt 

  Modified files:              
    /php-src/tests/classes      serialize_001.phpt 
  Log:
  Add some class related tests, fix hard-coded object ID in serialize_001.phpt.
  
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/serialize_001.phpt?r1=1.2.6.1&r2=1.2.6.2&diff_format=u
Index: php-src/tests/classes/serialize_001.phpt
diff -u php-src/tests/classes/serialize_001.phpt:1.2.6.1 
php-src/tests/classes/serialize_001.phpt:1.2.6.2
--- php-src/tests/classes/serialize_001.phpt:1.2.6.1    Sat May 24 15:22:21 2008
+++ php-src/tests/classes/serialize_001.phpt    Fri Dec  5 22:12:07 2008
@@ -47,19 +47,19 @@
 ?>
 ===DONE===
 <?php exit(0); ?>
---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

http://cvs.php.net/viewvc.cgi/php-src/tests/classes/inheritance_007.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/inheritance_007.phpt
+++ php-src/tests/classes/inheritance_007.phpt
--TEST--
Ensure inherited old-style constructor doesn't block other methods.
--FILE--
<?php
class A {
  public function B () { echo "In " . __METHOD__ . "\n"; }
  public function A () { echo "In " . __METHOD__ . "\n"; }
}
class B extends A { }

$rc = new ReflectionClass('B');
var_dump($rc->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
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/inheritance_006.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/inheritance_006.phpt
+++ php-src/tests/classes/inheritance_006.phpt
--TEST--
Private property inheritance check
--FILE--
<?php
Class A {
        private $c;
}

Class B extends A {
        private $c;
}

Class C extends B {
}

var_dump(new C);
?>
--EXPECTF--
object(C)#%d (2) {
  [%u|b%"c":%u|b%"B":private]=>
  NULL
  [%u|b%"c":%u|b%"A":private]=>
  NULL
}
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/implicit_instantiation_001.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/implicit_instantiation_001.phpt
+++ php-src/tests/classes/implicit_instantiation_001.phpt
--TEST--
Implicit object instantiation when accessing properties of non-object.
--FILE--
<?php
class C {
        // These values get implicitly converted to objects
        public $boolFalse = false;
        public $emptyString = '';
        public $null = null;

        // These values do not get implicitly converted to objects
        public $boolTrue = true;
        public $nonEmptyString = 'hello';
        public $intZero = 0;
}

$c = new C;
foreach($c as $name => $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)
}
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/property_recreate_private.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/property_recreate_private.phpt
+++ php-src/tests/classes/property_recreate_private.phpt
--TEST--
Unsetting and recreating private properties.
--FILE--
<?php
class C {
        private $p = 'test';
        function unsetPrivate() {
                unset($this->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
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/static_properties_004.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/static_properties_004.phpt
+++ php-src/tests/classes/static_properties_004.phpt
--TEST--
Inherited static properties can be separated from their reference set. 
--FILE--
<?php
class C { public static $p = 'original'; }
class D extends C {     }
class E extends D {     }

echo "\nInherited static properties refer to the same value accross classes:\n";
var_dump(C::$p, D::$p, E::$p);

echo "\nChanging one changes all the others:\n";
D::$p = 'changed.all';
var_dump(C::$p, D::$p, E::$p);

echo "\nBut because this is implemented using PHP references, the reference set 
can easily be split:\n";
$ref = 'changed.one';
D::$p =& $ref;
var_dump(C::$p, D::$p, E::$p);
?>
==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==
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/type_hinting_005d.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/type_hinting_005d.phpt
+++ php-src/tests/classes/type_hinting_005d.phpt
--TEST--
Check type hint compatibility in overrides with array hints.
--FILE--
<?php
Class C { function f($a) {} }

echo "Array hint, should be nothing.\n";
Class D extends C { function f(array $a) {} }
?>
==DONE==
--EXPECTF--
Fatal error: Declaration of D::f() must be compatible with that of C::f() in %s 
on line 5
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/static_properties_003.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/static_properties_003.phpt
+++ php-src/tests/classes/static_properties_003.phpt
--TEST--
Attempting to access static properties using instance property syntax 
--FILE--
<?php
class C {
    public static $x = 'C::$x';
    protected static $y = 'C::$y';
}

$c = new C;

echo "\n--> 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==
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/type_hinting_005c.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/type_hinting_005c.phpt
+++ php-src/tests/classes/type_hinting_005c.phpt
--TEST--
Check type hint compatibility in overrides with array hints.
--FILE--
<?php
Class C { function f(SomeClass $a) {} }

echo "Array hint, should be class.\n";
Class D extends C { function f(array $a) {} }
?>
==DONE==
--EXPECTF--
Fatal error: Declaration of D::f() must be compatible with that of C::f() in %s 
on line 5
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/type_hinting_005b.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/type_hinting_005b.phpt
+++ php-src/tests/classes/type_hinting_005b.phpt
--TEST--
Check type hint compatibility in overrides with array hints.
--FILE--
<?php
Class C { function f(array $a) {} }

echo "No hint, should be array.\n";
Class D extends C { function f($a) {} }
?>
==DONE==
--EXPECTF--
Fatal error: Declaration of D::f() must be compatible with that of C::f() in %s 
on line 5
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/type_hinting_005a.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/type_hinting_005a.phpt
+++ php-src/tests/classes/type_hinting_005a.phpt
--TEST--
Check type hint compatibility in overrides with array hints.
--FILE--
<?php
Class C { function f(array $a) {} }

echo "Compatible hint.\n";
Class D1 extends C { function f(array $a) {} }

echo "Class hint, should be array.\n";
Class D2 extends C { function f(SomeClass $a) {} }
?>
==DONE==
--EXPECTF--
Fatal error: Declaration of D2::f() must be compatible with that of C::f() in 
%s on line 8
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/__call_007.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/__call_007.phpt
+++ php-src/tests/classes/__call_007.phpt
--TEST--
Ensure exceptions are handled properly when thrown in a statically declared 
__call.  
--FILE--
<?php
class A {
        static function __call($strMethod, $arrArgs) {
                @var_dump($this);
                throw new Exception;
                echo "You should not see this";
        }
        function test() {
                A::unknownCalledWithSRO(1,2,3);
        }
}

class B extends A {
        function test() {
                B::unknownCalledWithSROFromChild(1,2,3);
        }
}

$a = new A();

echo "---> 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--
Fatal error: The magic method __call() must have public visibility and can not 
be static in %s on line 3
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/__call_006.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/__call_006.phpt
+++ php-src/tests/classes/__call_006.phpt
--TEST--
Ensure exceptions are handled properly when thrown in __call.  
--FILE--
<?php
class A {
        function __call($strMethod, $arrArgs) {
                var_dump($this);
                throw new Exception;
                echo "You should not see this";
        }
        function test() {
                A::unknownCalledWithSRO(1,2,3);
        }
}

class B extends A {
        function test() {
                B::unknownCalledWithSROFromChild(1,2,3);
        }
}

$a = new A();

echo "---> 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==
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/static_properties_003_error4.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/static_properties_003_error4.phpt
+++ php-src/tests/classes/static_properties_003_error4.phpt
--TEST--
Attempting to access static properties using instance property syntax 
--FILE--
<?php
class C {
    protected static $y = 'C::$y';
}
$c = new C;

echo "\n--> 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

http://cvs.php.net/viewvc.cgi/php-src/tests/classes/static_properties_003_error3.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/static_properties_003_error3.phpt
+++ php-src/tests/classes/static_properties_003_error3.phpt
--TEST--
Attempting to access static properties using instance property syntax 
--FILE--
<?php
class C {
    protected static $y = 'C::$y';
}
$c = new C;

echo "\n--> 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

http://cvs.php.net/viewvc.cgi/php-src/tests/classes/static_properties_003_error2.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/static_properties_003_error2.phpt
+++ php-src/tests/classes/static_properties_003_error2.phpt
--TEST--
Attempting to access static properties using instance property syntax 
--FILE--
<?php
class C {
    protected static $y = 'C::$y';
}
$c = new C;

echo "\n--> 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

http://cvs.php.net/viewvc.cgi/php-src/tests/classes/property_recreate_protected.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/property_recreate_protected.phpt
+++ php-src/tests/classes/property_recreate_protected.phpt
--TEST--
Unsetting and recreating protected properties.
--FILE--
<?php
class C {
        protected $p = 'test';
        function unsetProtected() {
                unset($this->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
http://cvs.php.net/viewvc.cgi/php-src/tests/classes/static_properties_003_error1.phpt?view=markup&rev=1.1
Index: php-src/tests/classes/static_properties_003_error1.phpt
+++ php-src/tests/classes/static_properties_003_error1.phpt
--TEST--
Attempting to access static properties using instance property syntax 
--FILE--
<?php
class C {
    protected static $y = 'C::$y';
}
$c = new C;

echo "\n--> 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

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to