diff options
author | Stig Bakken <ssb@php.net> | 2000-08-27 19:46:06 +0000 |
---|---|---|
committer | Stig Bakken <ssb@php.net> | 2000-08-27 19:46:06 +0000 |
commit | 315f4f5658cf22a17ba06fa2ca2f3d890355873f (patch) | |
tree | 3dd1134c1d1c3821b48fab806884123f09b2d21f /tests/classes | |
parent | 7eeda99a055df5a510d3d20526e9adcb42fecdb0 (diff) | |
download | php-git-315f4f5658cf22a17ba06fa2ca2f3d890355873f.tar.gz |
@PHP 3 regression testing framework re-born (Stig)
Took the old PHP 3 regression testing framework and rewrote it in PHP.
Should work on both Windows and UNIX, however I have not tested it on
Windows. See tests/README for how to write tests. Added the PHP 3
tests and converted most of them.
Diffstat (limited to 'tests/classes')
-rw-r--r-- | tests/classes/class_example.phpt | 87 | ||||
-rw-r--r-- | tests/classes/inheritance.phpt | 58 |
2 files changed, 145 insertions, 0 deletions
diff --git a/tests/classes/class_example.phpt b/tests/classes/class_example.phpt new file mode 100644 index 0000000000..788232058e --- /dev/null +++ b/tests/classes/class_example.phpt @@ -0,0 +1,87 @@ +--TEST-- +Classes general test +--POST-- +--GET-- +--FILE-- + +<?php + +/* pretty nifty object oriented code! */ + +class user { + var $first_name,$family_name,$address,$phone_num; + cfunction display() + { + echo "User information\n"; + echo "----------------\n\n"; + echo "First name:\t ".$this->first_name."\n"; + echo "Family name:\t ".$this->family_name."\n"; + echo "Address:\t ".$this->address."\n"; + echo "Phone:\t\t ".$this->phone_num."\n"; + echo "\n\n"; + } + cfunction initialize($first_name,$family_name,$address,$phone_num) + { + $this->first_name = $first_name; + $this->family_name = $family_name; + $this->address = $address; + $this->phone_num = $phone_num; + } +}; + + +function test($u) +{ /* one can pass classes as arguments */ + $u->display(); + $t = $u; + $t->address = "New address..."; + return $t; /* and also return them as return values */ +} + +$user1 = new user; +$user2 = new user; + +$user1->initialize("Zeev","Suraski","Ben Gourion 3, Kiryat Bialik, Israel","+972-4-8713139"); +$user2->initialize("Andi","Gutmans","Haifa, Israel","+972-4-8231621"); +$user1->display(); +$user2->display(); + +$tmp = test($user2); +$tmp->display(); + +?> +--EXPECT-- +User information +---------------- + +First name: Zeev +Family name: Suraski +Address: Ben Gourion 3, Kiryat Bialik, Israel +Phone: +972-4-8713139 + + +User information +---------------- + +First name: Andi +Family name: Gutmans +Address: Haifa, Israel +Phone: +972-4-8231621 + + +User information +---------------- + +First name: Andi +Family name: Gutmans +Address: Haifa, Israel +Phone: +972-4-8231621 + + +User information +---------------- + +First name: Andi +Family name: Gutmans +Address: New address... +Phone: +972-4-8231621 diff --git a/tests/classes/inheritance.phpt b/tests/classes/inheritance.phpt new file mode 100644 index 0000000000..45aafab7de --- /dev/null +++ b/tests/classes/inheritance.phpt @@ -0,0 +1,58 @@ +--TEST-- +Classes inheritance test +--POST-- +--GET-- +--FILE-- +<?php + +/* Inheritance test. Pretty nifty if I do say so myself! */ + +class foo { + var $a; + var $b; + cfunction display() { + echo "This is class foo\n"; + echo "a = ".$this->a."\n"; + echo "b = ".$this->b."\n"; + } + cfunction mul() { + return $this->a*$this->b; + } +}; + +class bar extends foo { + var $c; + cfunction display() { /* alternative display function for class bar */ + echo "This is class bar\n"; + echo "a = ".$this->a."\n"; + echo "b = ".$this->b."\n"; + echo "c = ".$this->c."\n"; + } +}; + + +$foo1 = new foo; +$foo1->a = 2; +$foo1->b = 5; +$foo1->display(); +echo $foo1->mul()."\n"; + +echo "-----\n"; + +$bar1 = new bar; +$bar1->a = 4; +$bar1->b = 3; +$bar1->c = 12; +$bar1->display(); +echo $bar1->mul()."\n"; +--EXPECT-- +This is class foo +a = 2 +b = 5 +10 +----- +This is class bar +a = 4 +b = 3 +c = 12 +12 |