helly           Tue Mar 11 19:10:00 2003 EDT

  Added files:                 
    /php4/tests/classes interface_class.phpt interface_doubled.phpt 
                        interface_implemented.phpt 
                        interface_instantiate.phpt 
                        interface_member.phpt interface_method.phpt 
                        interface_method_final.phpt 
                        interface_method_private.phpt 
                        interface_must_be_implemented.phpt 
  Log:
  Added some interface tests
  
Index: php4/tests/classes/interface_class.phpt
+++ php4/tests/classes/interface_class.phpt
--TEST--
A class can only implement interfaces
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 
needed'); ?>
--FILE--
<?php
class base {
}
        
class derived implements base {
}
?>
--EXPECTF--
Fatal error: derived cannot implement base - it is not an interface in %s on line %d

Index: php4/tests/classes/interface_doubled.phpt
+++ php4/tests/classes/interface_doubled.phpt
--TEST--
An interface may both inherit and implement base interfaces
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 
needed'); ?>
--FILE--
<?php

interface if_a {
        abstract function f_a();
}
        
interface if_b {
        abstract function f_b();
}

interface if_c implements if_a, if_b {
        abstract function f_c();
}

interface if_d extends if_a implements if_b {
        abstract function f_d();
}

interface if_e {
        abstract function f_d();
}

interface if_f extends if_e implements if_a, if_b, if_c, if_d, if_e {
}

class base {
        function test($class) {
                echo "is_a(" . class_name($this) . ", $class) ". (is_a($this, $class) 
? "yes\n" : "no\n");
        }
}

echo "class_a\n";

class class_a extends base implements if_a {
        function f_a() {}
        function f_b() {}
        function f_c() {}
        function f_d() {}
        function f_e() {}
}

$t = new class_a();
echo $t->test('if_a');
echo $t->test('if_b');
echo $t->test('if_c');
echo $t->test('if_d');
echo $t->test('if_e');

echo "class_b\n";

class class_b extends base implements if_a, if_b {
        function f_a() {}
        function f_b() {}
        function f_c() {}
        function f_d() {}
        function f_e() {}
}

$t = new class_b();
echo $t->test('if_a');
echo $t->test('if_b');
echo $t->test('if_c');
echo $t->test('if_d');
echo $t->test('if_e');

echo "class_c\n";

class class_c extends base implements if_c {
        function f_a() {}
        function f_b() {}
        function f_c() {}
        function f_d() {}
        function f_e() {}
}

$t = new class_c();
echo $t->test('if_a');
echo $t->test('if_b');
echo $t->test('if_c');
echo $t->test('if_d');
echo $t->test('if_e');

echo "class_d\n";

class class_d extends base implements if_d{
        function f_a() {}
        function f_b() {}
        function f_c() {}
        function f_d() {}
        function f_e() {}
}

$t = new class_d();
echo $t->test('if_a');
echo $t->test('if_b');
echo $t->test('if_c');
echo $t->test('if_d');
echo $t->test('if_e');

echo "class_e\n";

class class_e extends base implements if_a, if_b, if_c, if_d {
        function f_a() {}
        function f_b() {}
        function f_c() {}
        function f_d() {}
        function f_e() {}
}

$t = new class_e();
echo $t->test('if_a');
echo $t->test('if_b');
echo $t->test('if_c');
echo $t->test('if_d');
echo $t->test('if_e');

echo "class_f\n";

class class_f extends base implements if_e {
        function f_a() {}
        function f_b() {}
        function f_c() {}
        function f_d() {}
        function f_e() {}
}

$t = new class_f();
echo $t->test('if_a');
echo $t->test('if_b');
echo $t->test('if_c');
echo $t->test('if_d');
echo $t->test('if_e');

echo "class_g\n";

class class_g extends base implements if_f {
        function f_a() {}
        function f_b() {}
        function f_c() {}
        function f_d() {}
        function f_e() {}
}

$t = new class_g();
echo $t->test('if_a');
echo $t->test('if_b');
echo $t->test('if_c');
echo $t->test('if_d');
echo $t->test('if_e');

?>
--EXPECTF--
class_a
is_a(class_a, if_a) yes
is_a(class_a, if_b) no
is_a(class_a, if_c) no
is_a(class_a, if_d) no
is_a(class_a, if_e) no
class_b
is_a(class_b, if_a) yes
is_a(class_b, if_b) yes
is_a(class_b, if_c) no
is_a(class_b, if_d) no
is_a(class_b, if_e) no
class_c
is_a(class_c, if_a) yes
is_a(class_c, if_b) yes
is_a(class_c, if_c) yes
is_a(class_c, if_d) no
is_a(class_c, if_e) no
class_d
is_a(class_d, if_a) yes
is_a(class_d, if_b) yes
is_a(class_d, if_c) no
is_a(class_d, if_d) yes
is_a(class_d, if_e) no
class_e
is_a(class_e, if_a) yes
is_a(class_e, if_b) yes
is_a(class_e, if_c) yes
is_a(class_e, if_d) yes
is_a(class_e, if_e) no
class_f
is_a(class_f, if_a) no
is_a(class_f, if_b) no
is_a(class_f, if_c) no
is_a(class_f, if_d) no
is_a(class_f, if_e) yes
class_g
is_a(class_g, if_a) yes
is_a(class_g, if_b) yes
is_a(class_g, if_c) yes
is_a(class_g, if_d) yes
is_a(class_g, if_e) yes
Index: php4/tests/classes/interface_implemented.phpt
+++ php4/tests/classes/interface_implemented.phpt
--TEST--
An interface is inherited
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 
needed'); ?>
--FILE--
<?php

interface if_a {
        abstract function f_a();
}
        
interface if_b extends if_a {
        abstract function f_b();
}

class base {
        function _is_a($sub) {
                echo 'is_a('.get_class($this).', '.$sub.') = '.(is_a($this, $sub) ? 
'yes' : 'no')."\n";
        }
        function test() {
                echo $this->_is_a('base');
                echo $this->_is_a('derived_a');
                echo $this->_is_a('derived_b');
                echo $this->_is_a('derived_c');
                echo $this->_is_a('derived_d');
                echo $this->_is_a('if_a');
                echo $this->_is_a('if_b');
                echo "\n";
        }
}

class derived_a extends base implements if_a {
        function f_a() {}
}

class derived_b extends base implements if_a, if_b {
        function f_a() {}
        function f_b() {}
}

class derived_c extends derived_a implements if_b {
        function f_b() {}
}

class derived_d extends derived_c {
}

$t = new base();
$t->test();

$t = new derived_a();
$t->test();

$t = new derived_b();
$t->test();

$t = new derived_c();
$t->test();

$t = new derived_d();
$t->test();

?>
--EXPECTF--
is_a(base, base) = yes
is_a(base, derived_a) = no
is_a(base, derived_b) = no
is_a(base, derived_c) = no
is_a(base, derived_d) = no
is_a(base, if_a) = no
is_a(base, if_b) = no

is_a(derived_a, base) = yes
is_a(derived_a, derived_a) = yes
is_a(derived_a, derived_b) = no
is_a(derived_a, derived_c) = no
is_a(derived_a, derived_d) = no
is_a(derived_a, if_a) = yes
is_a(derived_a, if_b) = no

is_a(derived_b, base) = yes
is_a(derived_b, derived_a) = no
is_a(derived_b, derived_b) = yes
is_a(derived_b, derived_c) = no
is_a(derived_b, derived_d) = no
is_a(derived_b, if_a) = yes
is_a(derived_b, if_b) = yes

is_a(derived_c, base) = yes
is_a(derived_c, derived_a) = yes
is_a(derived_c, derived_b) = no
is_a(derived_c, derived_c) = yes
is_a(derived_c, derived_d) = no
is_a(derived_c, if_a) = yes
is_a(derived_c, if_b) = yes

is_a(derived_d, base) = yes
is_a(derived_d, derived_a) = yes
is_a(derived_d, derived_b) = no
is_a(derived_d, derived_c) = yes
is_a(derived_d, derived_d) = yes
is_a(derived_d, if_a) = yes
is_a(derived_d, if_b) = yes

Index: php4/tests/classes/interface_instantiate.phpt
+++ php4/tests/classes/interface_instantiate.phpt
--TEST--
An interface cannot be instantiated
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 
needed'); ?>
--FILE--
<?php

interface if_a {
        abstract function f_a();
}
        
$t = new if_a();

?>
--EXPECTF--
Fatal error: Cannot instantiate interface if_a in %s on line %d

Index: php4/tests/classes/interface_member.phpt
+++ php4/tests/classes/interface_member.phpt
--TEST--
An interface cannot have properties
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 
needed'); ?>
--FILE--
<?php

interface if_a {
        var $member;
}
?>
--EXPECTF--
Fatal error: Interfaces may not include member variables in %s on line %d

Index: php4/tests/classes/interface_method.phpt
+++ php4/tests/classes/interface_method.phpt
--TEST--
An interface method must be abstract
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 
needed'); ?>
--FILE--
<?php

interface if_a {
        function err() {};
}

?>
--EXPECTF--

Fatal error: Interface function if_a::err() cannot contain body %s on line %d

Index: php4/tests/classes/interface_method_final.phpt
+++ php4/tests/classes/interface_method_final.phpt
--TEST--
An interface method cannot be final
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 
needed'); ?>
--FILE--
<?php

class if_a {
        abstract final function err();
}

?>
--EXPECTF--

Fatal error: Cannot use the final modifier on an abstract class member in %s on line %d

Index: php4/tests/classes/interface_method_private.phpt
+++ php4/tests/classes/interface_method_private.phpt
--TEST--
An interface method cannot be private
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 
needed'); ?>
--FILE--
<?php

interface if_a {
        abstract private function err();
}

?>
--EXPECTF--

Fatal error: Access type for interface method if_a::err() must be omitted or declared 
public in %s on line %d

Index: php4/tests/classes/interface_must_be_implemented.phpt
+++ php4/tests/classes/interface_must_be_implemented.phpt
--TEST--
An interface must be implemented
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 
needed'); ?>
--FILE--
<?php

interface if_a {
        abstract function f_a();
}
        
class derived_a implements if_a {
}

?>
--EXPECTF--
Fatal error: Class derived_a contains abstract methods and must be declared abstract 
in %s on line %d

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to