- Refactored client tests: Use static class vars for transport data injection
instead of global variables.
# Cleaner code, although this cannot really be made clean.
git-svn-id: https://svn.apache.org/repos/asf/incubator/zetacomponents/trunk@1006319 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/Webdav/tests/classes/transport_injector.php b/Webdav/tests/classes/transport_injector.php
new file mode 100644
index 0000000..0babd16
--- /dev/null
+++ b/Webdav/tests/classes/transport_injector.php
@@ -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;
+ }
+}
+
+?>
diff --git a/Webdav/tests/classes/transport_test_mock.php b/Webdav/tests/classes/transport_test_mock.php
index b2e0f1c..90dc868 100644
--- a/Webdav/tests/classes/transport_test_mock.php
+++ b/Webdav/tests/classes/transport_test_mock.php
@@ -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;
}
}
diff --git a/Webdav/tests/client_test.php b/Webdav/tests/client_test.php
index e6d74cd..e86a801 100644
--- a/Webdav/tests/client_test.php
+++ b/Webdav/tests/client_test.php
@@ -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 @@
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 @@
$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;
}
diff --git a/Webdav/tests/client_test_setup.php b/Webdav/tests/client_test_setup.php
index c9547ab..2399732 100644
--- a/Webdav/tests/client_test_setup.php
+++ b/Webdav/tests/client_test_setup.php
@@ -14,7 +14,7 @@
*/
protected function retrieveBody()
{
- return $GLOBALS["EZC_WEBDAV_TRANSPORT_TEST_BODY"];
+ return ezcWebdavTestTransportInjector::$requestBody;
}
/**
@@ -25,9 +25,9 @@
*/
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;
}
}
';
diff --git a/Webdav/tests/server_auth_test.php b/Webdav/tests/server_auth_test.php
index 8efb8da..17114df 100644
--- a/Webdav/tests/server_auth_test.php
+++ b/Webdav/tests/server_auth_test.php
@@ -94,20 +94,20 @@
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 @@
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
);
}