فهرست منبع

ZF-7977: Request to Zend_Rest_Server providing correct method name but wrong args faults without explicit message

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18450 44c647ce-9c0f-0410-b52a-842ac1e357ba
jan 16 سال پیش
والد
کامیت
0a06393ccd
2فایلهای تغییر یافته به همراه11 افزوده شده و 3 حذف شده
  1. 7 1
      library/Zend/Rest/Server.php
  2. 4 2
      tests/Zend/Rest/ServerTest.php

+ 7 - 1
library/Zend/Rest/Server.php

@@ -190,11 +190,14 @@ class Zend_Rest_Server implements Zend_Server_Interface
                     $func_args = $this->_functions[$this->_method]->getParameters();
 
                     $calling_args = array();
+                    $missing_args = array();
                     foreach ($func_args as $arg) {
                         if (isset($request[strtolower($arg->getName())])) {
                             $calling_args[] = $request[strtolower($arg->getName())];
                         } elseif ($arg->isOptional()) {
                             $calling_args[] = $arg->getDefaultValue();
+                        } else {
+                            $missing_args[] = $arg->getName();
                         }
                     }
 
@@ -202,6 +205,9 @@ class Zend_Rest_Server implements Zend_Server_Interface
                         if (substr($key, 0, 3) == 'arg') {
                             $key = str_replace('arg', '', $key);
                             $calling_args[$key] = $value;
+                            if (($index = array_search($key, $missing_args)) !== false) {
+                                unset($missing_args[$index]);
+                            }
                         }
                     }
 
@@ -211,7 +217,7 @@ class Zend_Rest_Server implements Zend_Server_Interface
                     $result = false;
                     if (count($calling_args) < count($func_args)) {
                         require_once 'Zend/Rest/Server/Exception.php';
-                        $result = $this->fault(new Zend_Rest_Server_Exception('Invalid Method Call to ' . $this->_method . '. Requires ' . count($func_args) . ', ' . count($calling_args) . ' given.'), 400);
+                        $result = $this->fault(new Zend_Rest_Server_Exception('Invalid Method Call to ' . $this->_method . '. Missing argument(s): ' . implode(', ', $missing_args) . '.'), 400);
                     }
 
                     if (!$result && $this->_functions[$this->_method] instanceof Zend_Server_Reflection_Method) {

+ 4 - 2
tests/Zend/Rest/ServerTest.php

@@ -525,16 +525,18 @@ class Zend_Rest_ServerTest extends PHPUnit_Framework_TestCase
 
     /**
      * @see ZF-1949
+     * @see ZF-7977
      * @group ZF-1949
+     * @group ZF-7977
      */
     public function testMissingArgumentsShouldResultInFaultResponse()
     {
         $server = new Zend_Rest_Server();
         $server->setClass('Zend_Rest_Server_Test');
         ob_start();
-        $server->handle(array('method' => 'testFunc6', 'arg1' => "Davey"));
+        $server->handle(array('method' => 'testFunc6', 'arg1' => 'Davey'));
         $result = ob_get_clean();
-        $this->assertRegexp('#<message>Invalid Method Call to(.*?)(Requires).*?(given).*?(</message>)#', $result);
+        $this->assertRegexp('#<message>Invalid Method Call to(.*?)(Missing argument\(s\): ).*?(</message>)#', $result);
         $this->assertContains('<status>failed</status>', $result);
     }