]> granicus.if.org Git - php/commitdiff
Added more indirect call tests, remove invalid test
authorAaron Piotrowski <aaron@trowski.com>
Fri, 26 Jun 2015 00:46:28 +0000 (19:46 -0500)
committerAaron Piotrowski <aaron@trowski.com>
Fri, 26 Jun 2015 00:46:28 +0000 (19:46 -0500)
Zend/tests/call_static_005.phpt [deleted file]
Zend/tests/indirect_call_string_001.phpt [new file with mode: 0644]
Zend/tests/indirect_call_string_002.phpt [new file with mode: 0644]

diff --git a/Zend/tests/call_static_005.phpt b/Zend/tests/call_static_005.phpt
deleted file mode 100644 (file)
index 3b8d346..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
---TEST--
-Invalid method name in dynamic static call
---FILE--
-<?php
-
-class foo {
-       static function __callstatic($a, $b) {
-               var_dump($a);
-       }
-}
-
-try {
-       $a = 'foo::';
-       $a();
-} catch (Error $e) {
-       echo $e->getMessage();
-}
-
-?>
---EXPECT--
-Call to undefined function foo::()
diff --git a/Zend/tests/indirect_call_string_001.phpt b/Zend/tests/indirect_call_string_001.phpt
new file mode 100644 (file)
index 0000000..4493d6b
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+Indirect call with 'Class::method' syntax with class in namespace
+--FILE--
+<?php
+namespace TestNamespace
+{
+    class TestClass
+    {
+        public static function staticMethod()
+        {
+            echo "Static method called!\n";
+        }
+        
+        public static function staticMethodWithArgs($arg1, $arg2, $arg3)
+        {
+            printf("Static method called with args: %s, %s, %s\n", $arg1, $arg2, $arg3);
+        }
+    }
+
+    // Test basic call using Class::method syntax.
+    $callback = 'TestNamespace\TestClass::staticMethod';
+    $callback();
+
+    // Case should not matter.
+    $callback = 'testnamespace\testclass::staticmethod';
+    $callback();
+
+    $args = ['arg1', 'arg2', 'arg3'];
+    $callback = 'TestNamespace\TestClass::staticMethodWithArgs';
+
+    // Test call with args.
+    $callback($args[0], $args[1], $args[2]);
+
+    // Test call with splat operator.
+    $callback(...$args);
+}
+?>
+--EXPECT--
+Static method called!
+Static method called!
+Static method called with args: arg1, arg2, arg3
+Static method called with args: arg1, arg2, arg3
diff --git a/Zend/tests/indirect_call_string_002.phpt b/Zend/tests/indirect_call_string_002.phpt
new file mode 100644 (file)
index 0000000..40c913a
--- /dev/null
@@ -0,0 +1,59 @@
+--TEST--
+Indirect call with empty class and/or method name.
+--FILE--
+<?php
+class TestClass
+{
+    public static function __callStatic($method, array $args)
+    {
+        var_dump($method);
+    }
+}
+
+// Test call using array syntax
+$callback = ['TestClass', ''];
+$callback();
+
+// Test call using Class::method syntax.
+$callback = 'TestClass::';
+$callback();
+
+// Test array syntax with empty class name
+$callback = '::method';
+try {
+    $callback();
+} catch (Error $e) {
+    echo $e->getMessage() . "\n";
+}
+
+// Test Class::method syntax with empty class name
+$callback = '::method';
+try {
+    $callback();
+} catch (Error $e) {
+    echo $e->getMessage() . "\n";
+}
+
+// Test array syntax with empty class and method name
+$callback = ['', ''];
+try {
+    $callback();
+} catch (Error $e) {
+    echo $e->getMessage() . "\n";
+}
+
+// Test Class::method syntax with empty class and method name
+$callback = '::';
+try {
+    $callback();
+} catch (Error $e) {
+    echo $e->getMessage() . "\n";
+}
+?>
+--EXPECT--
+string(0) ""
+string(0) ""
+Class '' not found
+Class '' not found
+Class '' not found
+Class '' not found