]> granicus.if.org Git - php/commitdiff
- MFH tests
authorMarcus Boerger <helly@php.net>
Wed, 10 May 2006 21:19:37 +0000 (21:19 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 10 May 2006 21:19:37 +0000 (21:19 +0000)
tests/classes/abstract_static.phpt
tests/classes/abstract_user_call.phpt [new file with mode: 0755]
tests/classes/interface_construct.phpt [deleted file]
tests/classes/interfaces_003.phpt
tests/classes/tostring.phpt [deleted file]
tests/classes/tostring_001.phpt [new file with mode: 0755]
tests/classes/tostring_002.phpt [new file with mode: 0755]
tests/classes/tostring_003.phpt [new file with mode: 0755]
tests/classes/type_hinting_001.phpt
tests/classes/type_hinting_003.phpt

index 2e46e9dc06dce6ca7b4849f6a3139ca6f883c96f..01f358638bd4f884301bd357718d551dba5f4f95 100644 (file)
@@ -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 (executable)
index 0000000..0e1ddbe
--- /dev/null
@@ -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 (executable)
index 406462e..0000000
+++ /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
-
index 46ae8290aedb0b60a3d39077f278f14e8837ac5d..2c4c7e7c94fe7bce33f8aabdf00a0fe4d5ab4ba7 100755 (executable)
@@ -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 (file)
index 7253cd4..0000000
+++ /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 (executable)
index 0000000..a3b2cea
--- /dev/null
@@ -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 (executable)
index 0000000..8a4a7af
--- /dev/null
@@ -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 (executable)
index 0000000..8815bd9
--- /dev/null
@@ -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
index 82241298d83297ffe282eaaabf2edcdd97e8f220..17cf57e3441b53f31c3a256c96309fdc0f54acbf 100644 (file)
@@ -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
index 4a83dd41970a3a409c3d8aa9a8caf3d117a31248..ea01fc2dcb118c386599d3f7855f532edf0164dc 100755 (executable)
@@ -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