incubator-zeta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [zeta-commits] svn commit: r1006319 - in /incubator/zetacomponents/trunk/Webdav/tests: classes/transport_injector.php classes/transport_test_mock.php client_test.php client_test_setup.php server_auth_test.php
Date Sun, 10 Oct 2010 16:52:24 GMT
Author: toby
Date: Sun Oct 10 16:52:24 2010
New Revision: 1006319

URL: http://svn.apache.org/viewvc?rev=1006319&view=rev
Log:
- Refactored client tests: Use static class vars for transport data injection
  instead of global variables.
# Cleaner code, although this cannot really be made clean.

Added:
    incubator/zetacomponents/trunk/Webdav/tests/classes/transport_injector.php
Modified:
    incubator/zetacomponents/trunk/Webdav/tests/classes/transport_test_mock.php
    incubator/zetacomponents/trunk/Webdav/tests/client_test.php
    incubator/zetacomponents/trunk/Webdav/tests/client_test_setup.php
    incubator/zetacomponents/trunk/Webdav/tests/server_auth_test.php

Added: incubator/zetacomponents/trunk/Webdav/tests/classes/transport_injector.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Webdav/tests/classes/transport_injector.php?rev=1006319&view=auto
==============================================================================
--- incubator/zetacomponents/trunk/Webdav/tests/classes/transport_injector.php (added)
+++ incubator/zetacomponents/trunk/Webdav/tests/classes/transport_injector.php Sun Oct 10
16:52:24 2010
@@ -0,0 +1,22 @@
+<?php
+
+class ezcWebdavTestTransportInjector
+{
+    public static $requestBody;
+
+    public static $responseStatus;
+
+    public static $responseHeaders;
+
+    public static $responseBody;
+
+    public static function reset()
+    {
+        self::$requestBody     = null;
+        self::$responseStatus  = null;
+        self::$responseHeaders = null;
+        self::$responseBody    = null;
+    }
+}
+
+?>

Modified: incubator/zetacomponents/trunk/Webdav/tests/classes/transport_test_mock.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Webdav/tests/classes/transport_test_mock.php?rev=1006319&r1=1006318&r2=1006319&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Webdav/tests/classes/transport_test_mock.php (original)
+++ incubator/zetacomponents/trunk/Webdav/tests/classes/transport_test_mock.php Sun Oct 10
16:52:24 2010
@@ -1,17 +1,19 @@
 <?php
 
+require_once dirname( __FILE__ ) . '/transport_injector.php';
+
 class ezcWebdavTransportTestMock extends ezcWebdavTransport
 {
     protected function retrieveBody()
     {
-        return $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY'];
+        return ezcWebdavTestTransportInjector::$requestBody;
     }
 
     protected function sendResponse( ezcWebdavOutputResult $output )
     {
-        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS']  = $output->status;
-        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS'] = $output->headers;
-        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY']    = $output->body;
+        ezcWebdavTestTransportInjector::$responseStatus  = $output->status;
+        ezcWebdavTestTransportInjector::$responseHeaders = $output->headers;
+        ezcWebdavTestTransportInjector::$responseBody    = $output->body;
     }
 }
 

Modified: incubator/zetacomponents/trunk/Webdav/tests/client_test.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Webdav/tests/client_test.php?rev=1006319&r1=1006318&r2=1006319&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Webdav/tests/client_test.php (original)
+++ incubator/zetacomponents/trunk/Webdav/tests/client_test.php Sun Oct 10 16:52:24 2010
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'classes/test_sets.php';
+require_once 'classes/transport_injector.php';
 
 class ezcWebdavClientTest extends ezcTestCase
 {
@@ -159,7 +160,9 @@ class ezcWebdavClientTest extends ezcTes
 
     protected function performTestSetRun( array $request )
     {
-        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY'] = $request['body'];
+        ezcWebdavTestTransportInjector::reset();
+
+        ezcWebdavTestTransportInjector::$requestBody = $request['body'];
         $_SERVER = $request['server'];
 
         // ini_set( 'xdebug.collect_return', 1 );
@@ -167,15 +170,9 @@ class ezcWebdavClientTest extends ezcTes
         $this->server->handle( $this->backend );
         // xdebug_stop_trace();
 
-        $response['body']    = $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY'];
-        $response['headers'] = $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS'];
-        $response['status']  = $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS'];
-
-        // Reset globals
-        unset( $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY'] );
-        unset( $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY'] );
-        unset( $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS'] );
-        unset( $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS'] );
+        $response['status']  = ezcWebdavTestTransportInjector::$responseStatus;
+        $response['headers'] = ezcWebdavTestTransportInjector::$responseHeaders;
+        $response['body']    = ezcWebdavTestTransportInjector::$responseBody;
 
         return $response;
     }

Modified: incubator/zetacomponents/trunk/Webdav/tests/client_test_setup.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Webdav/tests/client_test_setup.php?rev=1006319&r1=1006318&r2=1006319&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Webdav/tests/client_test_setup.php (original)
+++ incubator/zetacomponents/trunk/Webdav/tests/client_test_setup.php Sun Oct 10 16:52:24
2010
@@ -14,7 +14,7 @@ abstract class ezcWebdavClientTestSetup
              */
             protected function retrieveBody()
             {
-                return $GLOBALS["EZC_WEBDAV_TRANSPORT_TEST_BODY"];
+                return ezcWebdavTestTransportInjector::$requestBody;
             }
         
             /**
@@ -25,9 +25,9 @@ abstract class ezcWebdavClientTestSetup
              */
             protected function sendResponse( ezcWebdavOutputResult $output )
             {
-                $GLOBALS["EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS"]  = $output->status;
-                $GLOBALS["EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS"] = $output->headers;
-                $GLOBALS["EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY"]    = $output->body;
+                ezcWebdavTestTransportInjector::$responseStatus  = $output->status;
+                ezcWebdavTestTransportInjector::$responseHeaders = $output->headers;
+                ezcWebdavTestTransportInjector::$responseBody    = $output->body;
             }
         }
     ';

Modified: incubator/zetacomponents/trunk/Webdav/tests/server_auth_test.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Webdav/tests/server_auth_test.php?rev=1006319&r1=1006318&r2=1006319&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Webdav/tests/server_auth_test.php (original)
+++ incubator/zetacomponents/trunk/Webdav/tests/server_auth_test.php Sun Oct 10 16:52:24 2010
@@ -94,20 +94,20 @@ class ezcWebdavServerAuthTest extends ez
         static $num = 0;
         $num++;
 
-        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY'] = $input['body'];
+        ezcWebdavTestTransportInjector::$requestBody = $input['body'];
         $_SERVER = array_merge( $this->serverBase, $input['server'] );
 
         $backend = $this->getBackend();
         
         ezcWebdavServer::getInstance()->handle( $backend );
 
-        if ( isset( $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']['WWW-Authenticate']
) )
+        if ( isset( ezcWebdavTestTransportInjector::$responseHeaders['WWW-Authenticate']
) )
         {
             // Replace nounce value with standard one, since this should not be predictable
-            $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']['WWW-Authenticate']['digest']
= preg_replace(
+            ezcWebdavTestTransportInjector::$responseHeaders['WWW-Authenticate']['digest']
= preg_replace(
                 '(nonce="[^"]+")',
                 'nonce="testnonce"',
-                $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']['WWW-Authenticate']['digest']
+                ezcWebdavTestTransportInjector::$responseHeaders['WWW-Authenticate']['digest']
             );
         }
         
@@ -123,22 +123,22 @@ class ezcWebdavServerAuthTest extends ez
             if ( isset( $output['headers']['ETag'] ) )
             {
                 unset( $output['headers']['ETag'] );
-                unset( $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']['ETag'] );
+                unset( ezcWebdavTestTransportInjector::$responseHeaders['ETag'] );
             }
         }
 
 
         $this->assertEquals(
             $output['status'],
-            $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS']
+            ezcWebdavTestTransportInjector::$responseStatus
         );
         $this->assertEquals(
             $output['headers'],
-            $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS']
+            ezcWebdavTestTransportInjector::$responseHeaders
         );
         $this->assertEquals(
             $output['body'],
-            $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY']
+            ezcWebdavTestTransportInjector::$responseBody
         );
     }
 



Mime
View raw message