]> granicus.if.org Git - php/commitdiff
Adding tests for final methods
authorMarcus Boerger <helly@php.net>
Mon, 3 Mar 2003 11:10:30 +0000 (11:10 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 3 Mar 2003 11:10:30 +0000 (11:10 +0000)
tests/classes/abstract_final.phpt [new file with mode: 0644]
tests/classes/final.phpt [new file with mode: 0644]
tests/classes/final_abstract.phpt [new file with mode: 0644]
tests/classes/final_redeclare.phpt [new file with mode: 0644]

diff --git a/tests/classes/abstract_final.phpt b/tests/classes/abstract_final.phpt
new file mode 100644 (file)
index 0000000..7aac026
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+A final method cannot be abstract
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+class fail {
+       abstract final function show();
+}
+
+echo "Done\n"; // Shouldn't be displayed
+?>
+--EXPECTF--
+
+Fatal error: Cannot use the final modifier on an abstract class member in %s on line %d
diff --git a/tests/classes/final.phpt b/tests/classes/final.phpt
new file mode 100644 (file)
index 0000000..733adf2
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+A method may be redeclared final
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+class first {
+       function show() {
+               echo "Call to function first::show()\n";
+       }
+}
+
+$t = new first();
+$t->show();
+
+class second extends first {
+       final function show() {
+               echo "Call to function second::show()\n";
+       }
+}
+
+$t2 = new second();
+$t2->show();
+
+echo "Done\n";
+?>
+--EXPECTF--
+Call to function first::show()
+Call to function second::show()
+Done
\ No newline at end of file
diff --git a/tests/classes/final_abstract.phpt b/tests/classes/final_abstract.phpt
new file mode 100644 (file)
index 0000000..37aa0be
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+A final method cannot be abstract
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+class fail {
+       final abstract function show();
+}
+
+echo "Done\n"; // Shouldn't be displayed
+?>
+--EXPECTF--
+
+Fatal error: Cannot use the final modifier on an abstract class member in %s
diff --git a/tests/classes/final_redeclare.phpt b/tests/classes/final_redeclare.phpt
new file mode 100644 (file)
index 0000000..bdf34a1
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+A final method may not be overwritten
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+class pass {
+       final function show() {
+               echo "Call to function pass::show()\n";
+       }
+}
+
+$t = new pass();
+$t->show();
+
+class fail extends pass {
+       function show() {
+               echo "Call to function fail::show()\n";
+       }
+}
+
+echo "Done\n"; // Shouldn't be displayed
+?>
+--EXPECTF--
+Call to function pass::show()
+
+Fatal error: Cannot override final method pass::show() in %s on line %d