]> granicus.if.org Git - php/commitdiff
Added tests for interfaces and class type hinting.
authorJay Smith <jay@php.net>
Fri, 7 Mar 2003 15:56:31 +0000 (15:56 +0000)
committerJay Smith <jay@php.net>
Fri, 7 Mar 2003 15:56:31 +0000 (15:56 +0000)
tests/classes/interfaces_001.phpt [new file with mode: 0644]
tests/classes/interfaces_002.phpt [new file with mode: 0644]
tests/classes/type_hinting_001.phpt [new file with mode: 0644]
tests/lang/type_hints_001.phpt [new file with mode: 0644]

diff --git a/tests/classes/interfaces_001.phpt b/tests/classes/interfaces_001.phpt
new file mode 100644 (file)
index 0000000..e65074d
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+ZE2 interfaces
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+interface Throwable {
+       public function getMessage();
+}
+
+class Exception implements Throwable {
+       public $foo = "foo";
+
+       public function getMessage() {
+               return $this->foo;
+       }
+}
+
+$foo = new Exception;
+echo $foo->getMessage() . "\n";
+
+?>
+--EXPECT--
+foo
+
diff --git a/tests/classes/interfaces_002.phpt b/tests/classes/interfaces_002.phpt
new file mode 100644 (file)
index 0000000..309dd76
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+ZE2 interface with an unimplemented method
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+interface Throwable {
+       public function getMessage();
+       public function getErrno();
+}
+
+class Exception implements Throwable {
+       public $foo = "foo";
+
+       public function getMessage() {
+               return $this->foo;
+       }
+}
+
+// this should die -- Exception class must be abstract...
+$foo = new Exception;
+echo $foo->getMessage() . "\n";
+
+?>
+--EXPECTF--
+
+Fatal error: Class exception contains abstract methods and must be declared abstract in %s on line %d
+
diff --git a/tests/classes/type_hinting_001.phpt b/tests/classes/type_hinting_001.phpt
new file mode 100644 (file)
index 0000000..e6b97a5
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+ZE2 class type hinting
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+interface Foo {
+       function a(Foo $foo);
+}
+
+interface Bar {
+       function b(Bar $bar);
+}
+
+class FooBar implements Foo, Bar {
+       function a(Foo $foo) {
+               // ...
+       }
+
+       function b(Bar $bar) {
+               // ...
+       }
+}
+
+class Blort {
+}
+
+$a = new FooBar;
+$b = new Blort;
+
+$a->a($b);
+$a->b($b);
+
+?>
+--EXPECTF--
+
+Fatal error: Argument 1 must implement interface foo in %s on line %d
diff --git a/tests/lang/type_hints_001.phpt b/tests/lang/type_hints_001.phpt
new file mode 100644 (file)
index 0000000..bd1577f
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+ZE2 type hinting
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+class Foo {
+}
+
+class Bar {
+}
+
+function type_hint_foo(Foo $a) {
+}
+
+$foo = new Foo;
+$bar = new Bar;
+
+type_hint_foo($foo);
+type_hint_foo($bar);
+
+?>
+--EXPECTF--
+
+Fatal error: Argument 1 must be an instance of foo in %s on line %d