]> granicus.if.org Git - php/commitdiff
- New tests
authorFelipe Pena <felipe@php.net>
Thu, 6 May 2010 19:21:11 +0000 (19:21 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 6 May 2010 19:21:11 +0000 (19:21 +0000)
Zend/tests/traits/error_010.phpt [new file with mode: 0644]
Zend/tests/traits/error_011.phpt [new file with mode: 0644]
Zend/tests/traits/error_012.phpt [new file with mode: 0644]
Zend/tests/traits/error_013.phpt [new file with mode: 0644]
Zend/tests/traits/error_014.phpt [new file with mode: 0644]
Zend/tests/traits/error_015.phpt [new file with mode: 0644]

diff --git a/Zend/tests/traits/error_010.phpt b/Zend/tests/traits/error_010.phpt
new file mode 100644 (file)
index 0000000..8f3f7dd
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Trying to exclude trait method multiple times
+--FILE--
+<?php
+
+trait foo {
+       public function test() { return 3; }
+}
+trait c {
+       public function test() { return 2; }
+}
+
+trait b {
+       public function test() { return 1; }
+}
+
+class bar {
+       use foo, c { c::test insteadof foo, b; }
+       use foo, c { c::test insteadof foo, b; }
+}
+
+$x = new bar;
+var_dump($x->test());
+
+?>
+--EXPECTF--
+Fatal error: Failed to evaluate a trait precedence (test). Method of trait foo was defined to be excluded multiple times in %s on line %d
diff --git a/Zend/tests/traits/error_011.phpt b/Zend/tests/traits/error_011.phpt
new file mode 100644 (file)
index 0000000..a6372a4
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Testing trait collisions
+--FILE--
+<?php
+
+trait foo {
+       public function test() { return 3; }
+}
+trait c {
+       public function test() { return 2; }
+}
+
+trait b {
+       public function test() { return 1; }
+}
+
+class bar {
+       use foo, c, b;
+}
+
+$x = new bar;
+var_dump($x->test());
+
+?>
+--EXPECTF--
+Warning: Trait method test has not been applied, because there are collisions with other trait methods on bar in %s on line %d
+
+Fatal error: Call to undefined method bar::test() in %s on line %d
diff --git a/Zend/tests/traits/error_012.phpt b/Zend/tests/traits/error_012.phpt
new file mode 100644 (file)
index 0000000..b90e32a
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Trying to access a protected trait method
+--FILE--
+<?php
+
+trait foo {
+       public function test() { return 3; }
+}
+
+class bar {
+       use foo { test as protected; }
+}
+
+$x = new bar;
+var_dump($x->test());
+
+?>
+--EXPECTF--
+Fatal error: Call to protected method bar::test() from context '' in %s on line %d
diff --git a/Zend/tests/traits/error_013.phpt b/Zend/tests/traits/error_013.phpt
new file mode 100644 (file)
index 0000000..d9fda2d
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Trying to use static as method modifier
+--FILE--
+<?php
+
+trait foo {
+       public function test() { return 3; }
+}
+
+class bar {
+       use foo { test as static; }
+}
+
+$x = new bar;
+var_dump($x->test());
+
+?>
+--EXPECTF--
+Fatal error: Cannot use 'static' as method modifier in %s on line %d
diff --git a/Zend/tests/traits/error_014.phpt b/Zend/tests/traits/error_014.phpt
new file mode 100644 (file)
index 0000000..be1c919
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Trying to override final method
+--FILE--
+<?php
+
+trait foo {
+       public function test() { return 3; }
+}
+
+class baz {
+       final public function test() { return 4; }
+}
+
+class bar extends baz {
+       use foo { test as public; }
+}
+
+$x = new bar;
+var_dump($x->test());
+
+?>
+--EXPECTF--
+Fatal error: Cannot override final method baz::test() in %s on line %d
diff --git a/Zend/tests/traits/error_015.phpt b/Zend/tests/traits/error_015.phpt
new file mode 100644 (file)
index 0000000..6d21c51
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Trying to add an alias to a trait method where there is another with same name
+--FILE--
+<?php
+
+trait foo {
+       public function test() { return 3; }
+}
+
+trait baz {
+       public function test() { return 4; }
+}
+
+class bar {
+       use foo, baz {
+               baz::test as zzz;
+       }
+}
+
+$x = new bar;
+var_dump($x->test());
+
+?>
+--EXPECTF--
+Fatal error: Failed to add aliased trait method (zzz) to trait table. Probably there is already a trait method with same name in %s on line %d