]> granicus.if.org Git - php/commitdiff
Added tests to for static support of traits.
authorStefan Marr <gron@php.net>
Wed, 17 Nov 2010 23:05:20 +0000 (23:05 +0000)
committerStefan Marr <gron@php.net>
Wed, 17 Nov 2010 23:05:20 +0000 (23:05 +0000)
# This was not tested and documented yet.
# Updated documentation in the RFC http://wiki.php.net/rfc/horizontalreuse

Zend/tests/traits/static_001.phpt [new file with mode: 0644]
Zend/tests/traits/static_002.phpt [new file with mode: 0644]
Zend/tests/traits/static_003.phpt [new file with mode: 0644]
Zend/tests/traits/static_004.phpt [new file with mode: 0644]
Zend/tests/traits/static_forward_static_call.phpt [new file with mode: 0644]
Zend/tests/traits/static_get_called_class.phpt [new file with mode: 0644]

diff --git a/Zend/tests/traits/static_001.phpt b/Zend/tests/traits/static_001.phpt
new file mode 100644 (file)
index 0000000..d86cb85
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--\r
+Traits with static methods.\r
+--CREDITS--\r
+Simas Toleikis simast@gmail.com\r
+--FILE--\r
+<?php\r
+\r
+       trait TestTrait {\r
+               public static function test() {\r
+                       return 'Test';\r
+               }\r
+       }\r
+\r
+       class A {\r
+               use TestTrait;\r
+       }\r
+\r
+       echo A::test();\r
+\r
+?>\r
+--EXPECT--\r
+Test
\ No newline at end of file
diff --git a/Zend/tests/traits/static_002.phpt b/Zend/tests/traits/static_002.phpt
new file mode 100644 (file)
index 0000000..c076085
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--\r
+Traits with static methods referenced using variable.\r
+--CREDITS--\r
+Simas Toleikis simast@gmail.com\r
+--FILE--\r
+<?php\r
+\r
+       trait TestTrait {\r
+               public static function test() {\r
+                       return 'Test';\r
+               }\r
+       }\r
+\r
+       class A {\r
+               use TestTrait;\r
+       }\r
+\r
+       $class = "A";\r
+       echo $class::test();\r
+\r
+?>\r
+--EXPECT--\r
+Test
\ No newline at end of file
diff --git a/Zend/tests/traits/static_003.phpt b/Zend/tests/traits/static_003.phpt
new file mode 100644 (file)
index 0000000..fbe5421
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--\r
+Traits with late static bindings.\r
+--CREDITS--\r
+Simas Toleikis simast@gmail.com\r
+--FILE--\r
+<?php\r
+\r
+       trait TestTrait {\r
+               public static function test() {\r
+                       return static::$test;\r
+               }\r
+       }\r
+\r
+       class A {\r
+               use TestTrait;\r
+               protected static $test = "Test A";\r
+       }\r
+\r
+       class B extends A {\r
+               protected static $test = "Test B";\r
+       }\r
+\r
+       echo B::test();\r
+\r
+?>\r
+--EXPECT--\r
+Test B
\ No newline at end of file
diff --git a/Zend/tests/traits/static_004.phpt b/Zend/tests/traits/static_004.phpt
new file mode 100644 (file)
index 0000000..c360f45
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--\r
+Traits with __callStatic magic method.\r
+--CREDITS--\r
+Simas Toleikis simast@gmail.com\r
+--FILE--\r
+<?php\r
+\r
+       trait TestTrait {\r
+               public static function __callStatic($name, $arguments) {\r
+                       return $name;\r
+               }\r
+       }\r
+\r
+       class A {\r
+               use TestTrait;\r
+       }\r
+\r
+       echo A::Test();\r
+\r
+?>\r
+--EXPECT--\r
+Test
\ No newline at end of file
diff --git a/Zend/tests/traits/static_forward_static_call.phpt b/Zend/tests/traits/static_forward_static_call.phpt
new file mode 100644 (file)
index 0000000..878cf1f
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--\r
+Traits and forward_static_call().\r
+--CREDITS--\r
+Simas Toleikis simast@gmail.com\r
+--FILE--\r
+<?php\r
+\r
+       trait TestTrait {\r
+               public static function test() {\r
+                       return 'Forwarded '.forward_static_call(array('A', 'test'));\r
+               }\r
+       }\r
+\r
+       class A {\r
+               public static function test() {\r
+                       return "Test A";\r
+               }\r
+       }\r
+\r
+       class B extends A {\r
+               use TestTrait;\r
+       }\r
+\r
+       echo B::test();\r
+\r
+?>\r
+--EXPECT--\r
+Forwarded Test A
\ No newline at end of file
diff --git a/Zend/tests/traits/static_get_called_class.phpt b/Zend/tests/traits/static_get_called_class.phpt
new file mode 100644 (file)
index 0000000..dc29ece
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--\r
+Traits and get_called_class().\r
+--CREDITS--\r
+Simas Toleikis simast@gmail.com\r
+--FILE--\r
+<?php\r
+\r
+       trait TestTrait {\r
+               public static function test() {\r
+                       return get_called_class();\r
+               }\r
+       }\r
+\r
+       class A {\r
+               use TestTrait;\r
+       }\r
+\r
+       class B extends A { }\r
+\r
+       echo B::test();\r
+\r
+?>\r
+--EXPECT--\r
+B
\ No newline at end of file