diff options
author | Marcus Boerger <helly@php.net> | 2006-05-10 21:19:37 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2006-05-10 21:19:37 +0000 |
commit | 9745215cf8910222eb0c828d4cf329c7e9863840 (patch) | |
tree | 26e9b0b0320bbdfafeaed712d379444fbc0f5f17 | |
parent | 4df7ab403c3cb168047ce5bb14fbaf19e078b1fa (diff) | |
download | php-git-9745215cf8910222eb0c828d4cf329c7e9863840.tar.gz |
- MFH tests
-rw-r--r-- | tests/classes/abstract_static.phpt | 22 | ||||
-rwxr-xr-x | tests/classes/abstract_user_call.phpt | 30 | ||||
-rwxr-xr-x | tests/classes/interface_construct.phpt | 24 | ||||
-rwxr-xr-x | tests/classes/interfaces_003.phpt | 13 | ||||
-rw-r--r-- | tests/classes/tostring.phpt | 86 | ||||
-rwxr-xr-x | tests/classes/tostring_001.phpt | 184 | ||||
-rwxr-xr-x | tests/classes/tostring_002.phpt | 31 | ||||
-rwxr-xr-x | tests/classes/tostring_003.phpt | 33 | ||||
-rw-r--r-- | tests/classes/type_hinting_001.phpt | 2 | ||||
-rwxr-xr-x | tests/classes/type_hinting_003.phpt | 2 |
10 files changed, 298 insertions, 129 deletions
diff --git a/tests/classes/abstract_static.phpt b/tests/classes/abstract_static.phpt index 2e46e9dc06..01f358638b 100644 --- a/tests/classes/abstract_static.phpt +++ b/tests/classes/abstract_static.phpt @@ -1,21 +1,29 @@ --TEST-- -ZE2 A static abstrcat method may not be called ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +ZE2 A static abstrcat methods --FILE-- <?php -abstract class fail { - abstract static function show(); +interface showable +{ + static function show(); } -class pass extends fail { +class pass implements showable +{ static function show() { echo "Call to function show()\n"; } } pass::show(); + +eval(' +class fail +{ + abstract static function func(); +} +'); + fail::show(); echo "Done\n"; // shouldn't be displayed @@ -23,4 +31,4 @@ echo "Done\n"; // shouldn't be displayed --EXPECTF-- Call to function show() -Fatal error: Cannot call abstract method fail::show() in %s on line %d +Fatal error: Static function fail::func() cannot be abstract in %s on line %d diff --git a/tests/classes/abstract_user_call.phpt b/tests/classes/abstract_user_call.phpt new file mode 100755 index 0000000000..0e1ddbe796 --- /dev/null +++ b/tests/classes/abstract_user_call.phpt @@ -0,0 +1,30 @@ +--TEST-- +ZE2 An abstrcat method cannot be called indirectly +--FILE-- +<?php + +abstract class test_base +{ + abstract function func(); +} + +class test extends test_base +{ + function func() + { + echo __METHOD__ . "()\n"; + } +} + +$o = new test; + +$o->func(); + +call_user_func(array($o, 'test_base::func')); + +?> +===DONE=== +--EXPECTF-- +test::func() + +Fatal error: Cannot call abstract method test_base::func() in %s on line %d diff --git a/tests/classes/interface_construct.phpt b/tests/classes/interface_construct.phpt deleted file mode 100755 index 406462e17a..0000000000 --- a/tests/classes/interface_construct.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -ZE2 An interface constructor signature must not be inherited ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> ---FILE-- -<?php -error_reporting(4095); - -interface test { - public function __construct($foo); -} - -class foo implements test { - public function __construct() { - echo "foo\n"; - } -} - -$foo = new foo; - -?> ---EXPECT-- -foo - diff --git a/tests/classes/interfaces_003.phpt b/tests/classes/interfaces_003.phpt index 46ae8290ae..2c4c7e7c94 100755 --- a/tests/classes/interfaces_003.phpt +++ b/tests/classes/interfaces_003.phpt @@ -7,27 +7,20 @@ class MyObject {} interface MyInterface { - public function __construct(Object $o); + public function __construct(MyObject $o); } class MyTestClass implements MyInterface { - public function __construct(Object $o) + public function __construct(MyObject $o) { } } $obj = new MyTestClass; -class MyTestFail -{ - public function __construct() - { - } -} - ?> ===DONE=== --EXPECTF-- -Fatal error: Argument 1 passed to MyTestClass::__construct() must be an object of class Object, called in %sinterfaces_003.php on line %d +Catchable fatal error: Argument 1 passed to MyTestClass::__construct() must be an object of class MyObject, called in %sinterfaces_003.php on line %d diff --git a/tests/classes/tostring.phpt b/tests/classes/tostring.phpt deleted file mode 100644 index 7253cd4c7b..0000000000 --- a/tests/classes/tostring.phpt +++ /dev/null @@ -1,86 +0,0 @@ ---TEST-- -ZE2 __toString() ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> ---FILE-- -<?php - -class test1 { -} - -class test2 { - function __toString() { - echo __METHOD__ . "()\n"; - return "Converted\n"; - } -} - -echo "====test1====\n"; -$o = new test1; -print_r($o); -var_dump((string)$o); -var_dump($o); - -echo "====test2====\n"; -$o = new test2; -print_r($o); -print $o; -var_dump($o); -echo "====test3====\n"; -echo $o; - -echo "====test4====\n"; -echo "string:".$o; - -echo "====test5====\n"; -echo 1 . $o; - -echo "====test6====\n"; -echo $o.$o; - -echo "====test7====\n"; -$ar = array(); -$ar[$o->__toString()] = "ERROR"; -echo $ar[$o]; - -echo "====test8====\n"; -var_dump(trim($o)); -var_dump(trim((string)$o)); - -echo "====test9====\n"; -echo sprintf("%s", $o); -?> -====DONE!==== ---EXPECTF-- -====test1==== -test1 Object -( -) -string(1%d) "Object id #%d" -object(test1)#%d (%d) { -} -====test2==== -test2 Object -( -) -test2::__toString() -Converted -object(test2)#%d (%d) { -} -====test3==== -test2::__toString() -Converted -====test4==== -string:Object id #%d====test5==== -1Object id #%d====test6==== -Object id #%dObject id #2====test7==== -test2::__toString() - -Warning: Illegal offset type in %stostring.php on line %d -====test8==== - -Notice: Object of class test2 to string conversion in %stostring.php on line %d -string(6) "Object" -string(1%d) "Object id #%d" -====test9==== -Object id #%d====DONE!==== diff --git a/tests/classes/tostring_001.phpt b/tests/classes/tostring_001.phpt new file mode 100755 index 0000000000..a3b2cea194 --- /dev/null +++ b/tests/classes/tostring_001.phpt @@ -0,0 +1,184 @@ +--TEST-- +ZE2 __toString() +--FILE-- +<?php + +function my_error_handler($errno, $errstr, $errfile, $errline) { + var_dump($errstr); +} + +set_error_handler('my_error_handler'); + +class test1 +{ +} + +class test2 +{ + function __toString() + { + echo __METHOD__ . "()\n"; + return "Converted\n"; + } +} + +class test3 +{ + function __toString() + { + echo __METHOD__ . "()\n"; + return 42; + } +} +echo "====test1====\n"; +$o = new test1; +print_r($o); +var_dump((string)$o); +var_dump($o); + +echo "====test2====\n"; +$o = new test2; +print_r($o); +print $o; +var_dump($o); +echo "====test3====\n"; +echo $o; + +echo "====test4====\n"; +echo "string:".$o; + +echo "====test5====\n"; +echo 1 . $o; +echo 1 , $o; + +echo "====test6====\n"; +echo $o . $o; +echo $o , $o; + +echo "====test7====\n"; +$ar = array(); +$ar[$o->__toString()] = "ERROR"; +echo $ar[$o]; + +echo "====test8====\n"; +var_dump(trim($o)); +var_dump(trim((string)$o)); + +echo "====test9====\n"; +echo sprintf("%s", $o); + +echo "====test10====\n"; +$o = new test3; +var_dump($o); +echo $o; + +?> +====DONE==== +--EXPECTF-- +====test1==== +test1 Object +( +) +string(54) "Object of class test1 could not be converted to string" +string(0) "" +object(test1)#%d (0) { +} +====test2==== +test2 Object +( +) +test2::__toString() +Converted +object(test2)#%d (0) { +} +====test3==== +test2::__toString() +Converted +====test4==== +test2::__toString() +string:Converted +====test5==== +test2::__toString() +1Converted +1test2::__toString() +Converted +====test6==== +test2::__toString() +test2::__toString() +Converted +Converted +test2::__toString() +Converted +test2::__toString() +Converted +====test7==== +test2::__toString() +string(19) "Illegal offset type" +====test8==== +test2::__toString() +string(9) "Converted" +test2::__toString() +string(9) "Converted" +====test9==== +test2::__toString() +Converted +====test10==== +object(test3)#%d (0) { +} +test3::__toString() +string(53) "Method test3::__toString() must return a string value" +====DONE==== +--UEXPECTF-- +====test1==== +test1 Object +( +) +unicode(54) "Object of class test1 could not be converted to string" +unicode(0) "" +object(test1)#%d (0) { +} +====test2==== +test2 Object +( +) +test2::__toString() +Converted +object(test2)#%d (0) { +} +====test3==== +test2::__toString() +Converted +====test4==== +test2::__toString() +string:Converted +====test5==== +test2::__toString() +1Converted +1test2::__toString() +Converted +====test6==== +test2::__toString() +test2::__toString() +Converted +Converted +test2::__toString() +Converted +test2::__toString() +Converted +====test7==== +test2::__toString() +unicode(19) "Illegal offset type" +====test8==== +test2::__toString() +unicode(9) "Converted" +test2::__toString() +unicode(9) "Converted" +====test9==== +test2::__toString() +Converted +====test10==== +object(test3)#%d (0) { +} +test3::__toString() +unicode(53) "Method test3::__toString() must return a string value" +====DONE==== diff --git a/tests/classes/tostring_002.phpt b/tests/classes/tostring_002.phpt new file mode 100755 index 0000000000..8a4a7af339 --- /dev/null +++ b/tests/classes/tostring_002.phpt @@ -0,0 +1,31 @@ +--TEST-- +ZE2 __toString() in __destruct +--SKIPIF-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class Test +{ + function __toString() + { + return "Hello\n"; + } + + function __destruct() + { + echo $this; + } +} + +$o = new Test; +$o = NULL; + +$o = new Test; + +?> +====DONE==== +--EXPECTF-- +Hello +====DONE==== +Hello diff --git a/tests/classes/tostring_003.phpt b/tests/classes/tostring_003.phpt new file mode 100755 index 0000000000..8815bd9407 --- /dev/null +++ b/tests/classes/tostring_003.phpt @@ -0,0 +1,33 @@ +--TEST-- +ZE2 __toString() in __destruct/exception +--FILE-- +<?php + +class Test +{ + function __toString() + { + throw new Exception("Damn!"); + return "Hello\n"; + } + + function __destruct() + { + echo $this; + } +} + +try +{ + $o = new Test; + $o = NULL; +} +catch(Exception $e) +{ + var_dump($e->getMessage()); +} + +?> +====DONE==== +--EXPECTF-- +Fatal error: Method Test::__toString() must not throw an exception in %stostring_003.php on line %d diff --git a/tests/classes/type_hinting_001.phpt b/tests/classes/type_hinting_001.phpt index 82241298d8..17cf57e344 100644 --- a/tests/classes/type_hinting_001.phpt +++ b/tests/classes/type_hinting_001.phpt @@ -35,4 +35,4 @@ $a->b($b); ?> --EXPECTF-- -Fatal error: Argument 1 passed to FooBar::a() must implement interface Foo, called in %s on line 27 and defined in %s on line 12 +Catchable fatal error: Argument 1 passed to FooBar::a() must implement interface Foo, called in %s on line 27 and defined in %s on line 12 diff --git a/tests/classes/type_hinting_003.phpt b/tests/classes/type_hinting_003.phpt index 4a83dd4197..ea01fc2dcb 100755 --- a/tests/classes/type_hinting_003.phpt +++ b/tests/classes/type_hinting_003.phpt @@ -57,4 +57,4 @@ array(1) { int(25) } -Fatal error: Argument 1 passed to Test::f1() must be an array, called in %stype_hinting_003.php on line %d and defined in %stype_hinting_003.php on line %d +Catchable fatal error: Argument 1 passed to Test::f1() must be an array, called in %stype_hinting_003.php on line %d and defined in %stype_hinting_003.php on line %d |