Browse Source

Added tests for interfaces and class type hinting.

migration/unlabaled-1.3.2
Jay Smith 23 years ago
parent
commit
61de56b7f5
  1. 26
      tests/classes/interfaces_001.phpt
  2. 29
      tests/classes/interfaces_002.phpt
  3. 38
      tests/classes/type_hinting_001.phpt
  4. 26
      tests/lang/type_hints_001.phpt

26
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

29
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

38
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

26
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
Loading…
Cancel
Save