summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/classes/clone_005.phpt2
-rw-r--r--tests/classes/final_private_ctor.phpt21
-rw-r--r--tests/classes/inheritance_007.phpt51
-rw-r--r--tests/classes/inheritance_008.phpt16
-rw-r--r--tests/classes/inheritance_009.phpt14
5 files changed, 103 insertions, 1 deletions
diff --git a/tests/classes/clone_005.phpt b/tests/classes/clone_005.phpt
index f759221480..b8e3870a8d 100644
--- a/tests/classes/clone_005.phpt
+++ b/tests/classes/clone_005.phpt
@@ -6,7 +6,7 @@ abstract class base {
public $a = 'base';
// disallow cloning once forever
- final private function __clone() {}
+ final protected function __clone() {}
}
class test extends base {
diff --git a/tests/classes/final_private_ctor.phpt b/tests/classes/final_private_ctor.phpt
new file mode 100644
index 0000000000..37dbe56c31
--- /dev/null
+++ b/tests/classes/final_private_ctor.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Final private constructors cannot be overridden
+--FILE--
+<?php
+
+class Base
+{
+ private final function __construct()
+ {
+ }
+}
+class Extended extends Base
+{
+ public function __construct()
+ {
+ }
+}
+
+?>
+--EXPECTF--
+Fatal error: Cannot override final method Base::__construct() in %s on line %d
diff --git a/tests/classes/inheritance_007.phpt b/tests/classes/inheritance_007.phpt
new file mode 100644
index 0000000000..9115dc00e8
--- /dev/null
+++ b/tests/classes/inheritance_007.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Ensure private methods with the same name are not checked for inheritance rules - final
+--FILE--
+<?php
+class A {
+ function callYourPrivates() {
+ $this->normalPrivate();
+ $this->finalPrivate();
+ }
+ function notOverridden_callYourPrivates() {
+ $this->normalPrivate();
+ $this->finalPrivate();
+ }
+ private function normalPrivate() {
+ echo __METHOD__ . PHP_EOL;
+ }
+ final private function finalPrivate() {
+ echo __METHOD__ . PHP_EOL;
+ }
+}
+class B extends A {
+ function callYourPrivates() {
+ $this->normalPrivate();
+ $this->finalPrivate();
+ }
+ private function normalPrivate() {
+ echo __METHOD__ . PHP_EOL;
+ }
+ final private function finalPrivate() {
+ echo __METHOD__ . PHP_EOL;
+ }
+}
+$a = new A();
+$a->callYourPrivates();
+$a->notOverridden_callYourPrivates();
+$b = new B();
+$b->callYourPrivates();
+$b->notOverridden_callYourPrivates();
+?>
+--EXPECTF--
+Warning: Private methods cannot be final as they are never overridden by other classes %s
+
+Warning: Private methods cannot be final as they are never overridden by other classes %s
+A::normalPrivate
+A::finalPrivate
+A::normalPrivate
+A::finalPrivate
+B::normalPrivate
+B::finalPrivate
+A::normalPrivate
+A::finalPrivate
diff --git a/tests/classes/inheritance_008.phpt b/tests/classes/inheritance_008.phpt
new file mode 100644
index 0000000000..2bc2783e2c
--- /dev/null
+++ b/tests/classes/inheritance_008.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Ensure private methods with the same name are not checked for inheritance rules - static
+--FILE--
+<?php
+class A {
+ static private function foo() { }
+ private function bar() {}
+}
+class B extends A {
+ private function foo() {}
+ static private function bar() {}
+}
+echo 'OK';
+?>
+--EXPECT--
+OK
diff --git a/tests/classes/inheritance_009.phpt b/tests/classes/inheritance_009.phpt
new file mode 100644
index 0000000000..042eec7435
--- /dev/null
+++ b/tests/classes/inheritance_009.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Ensure private methods with the same name are not checked for inheritance rules - abstract
+--FILE--
+<?php
+class A {
+ private function test() {}
+}
+abstract class B extends A {
+ abstract function test();
+}
+echo 'OK';
+?>
+--EXPECT--
+OK