ZF-11574: setAdapter('test') fails

Description

I updated a project to use a more recent version of ZF and a unit test failed.

I had {{$client->setAdapter('test');}} in it in order to use {{Zend_Http_Client_Adapter_Test}}. I'm not really sure what version it used before (it doesn't say). But it's been a long, long while since ZF was updated.

Here's a patch to correct the problem:


Index: Client.php
===================================================================
--- Client.php  (revision 35)
+++ Client.php  (working copy)
@@ -861,6 +861,9 @@
     public function setAdapter($adapter)
     {
         if (is_string($adapter)) {
+            if (false === strpos($adapter, 'Zend_Http_Client_Adapter_', 0)) {
+                $adapter = 'Zend_Http_Client_Adapter_' . ucfirst(strtolower($adapter));
+            }
             try {
                 Zend_Loader::loadClass($adapter);
             } catch (Zend_Exception $e) {

If you need a test, let me know where to find them and I'll add a patch for that as well.

Till

Comments

Convenient as this would be, what if you write a custom adapter that isn't in the "Zend_Http_Client_Adapter" vendor prefix, and pass that class name to setAdapter()? As written, the patch would still prepend that prefix, and thus try and load a non-existent class.

I think this is a situation where adding a broker would work best -- and that would need to be done in ZF2.