summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJay Smith <jay@php.net>2003-03-07 15:56:31 +0000
committerJay Smith <jay@php.net>2003-03-07 15:56:31 +0000
commit61de56b7f5dc5590561d9048064ef6c33c905852 (patch)
tree888eae6b518a8328fb9ad2223c8094dd1cae96cd /tests
parent6d8283fa570da8f1296dd1be54b962b18db02d25 (diff)
downloadphp-git-61de56b7f5dc5590561d9048064ef6c33c905852.tar.gz
Added tests for interfaces and class type hinting.
Diffstat (limited to 'tests')
-rw-r--r--tests/classes/interfaces_001.phpt26
-rw-r--r--tests/classes/interfaces_002.phpt29
-rw-r--r--tests/classes/type_hinting_001.phpt38
-rw-r--r--tests/lang/type_hints_001.phpt26
4 files changed, 119 insertions, 0 deletions
diff --git a/tests/classes/interfaces_001.phpt b/tests/classes/interfaces_001.phpt
new file mode 100644
index 0000000000..e65074d830
--- /dev/null
+++ b/tests/classes/interfaces_001.phpt
@@ -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
index 0000000000..309dd76cec
--- /dev/null
+++ b/tests/classes/interfaces_002.phpt
@@ -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
index 0000000000..e6b97a5873
--- /dev/null
+++ b/tests/classes/type_hinting_001.phpt
@@ -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
index 0000000000..bd1577fe31
--- /dev/null
+++ b/tests/lang/type_hints_001.phpt
@@ -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