Browse Source

Adding tests for final methods

migration/unlabaled-1.3.2
Marcus Boerger 24 years ago
parent
commit
326b793faf
  1. 16
      tests/classes/abstract_final.phpt
  2. 31
      tests/classes/final.phpt
  3. 16
      tests/classes/final_abstract.phpt
  4. 28
      tests/classes/final_redeclare.phpt

16
tests/classes/abstract_final.phpt

@ -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

31
tests/classes/final.phpt

@ -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

16
tests/classes/final_abstract.phpt

@ -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

28
tests/classes/final_redeclare.phpt

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