Author: maksim_ka
Date: 2010-02-09 14:04:51 +0100 (Tue, 09 Feb 2010)
New Revision: 27783

Added:
   plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfClient.php
Modified:
   plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfService.php
   
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitAmfTestCase.class.php
Log:
[sfPhpunitPlugin][sf1.2] update amftest case. fix problem with using sabreamf 
multiple times

Added: 
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfClient.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfClient.php    
                            (rev 0)
+++ 
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfClient.php    
    2010-02-09 13:04:51 UTC (rev 27783)
@@ -0,0 +1,83 @@
+<?php
+
+class sfPhpunitAmfClient
+{
+  protected $_endPoint;
+  protected $_encoding;
+  protected $_httpProxy;
+  protected $_credentials;
+  protected $_header;
+  
+  public function __construct($endPoint = null)
+  {
+    if (is_null($endPoint)) {
+      $options = sfConfig::get('app_sfPhpunitPlugin_amf');
+      $endPoint = $options['endpoint'];
+    }
+    if (!$endPoint) {
+      throw new Exception('The amf server endpoit should be set as constructor 
parameter or in config as `app_sfPhpunitPlugin_amf_endpoint`');      
+    }
+    
+    $this->_endPoint = $endPoint;
+  }
+  
+  public function sendRequest($servicePath, $data) 
+  {
+    return $this->_buildSabreAmfClient()->sendRequest($servicePath, $data);
+  }
+  
+  public function setEncoding($encoding) 
+  {
+    $this->_encoding = $encoding;
+  }
+  
+  public function setHttpProxy($httpProxy) 
+  {
+    $this->_httpProxy = $httpProxy;
+  }
+  
+  public function setCredentials($username, $password) 
+  {
+    $this->_credentials['username'] = $username;
+    $this->_credentials['password'] = $password;
+  }
+  
+  public function addHeader($name, $required, $data) 
+  {
+    if (!is_array($this->header)) $this->header = array();
+    
+    $this->header[] = array('name' => $name, 'required' => $required, 'data' 
=> $data);
+  }
+  
+  /**
+   * @return SabreAMF_Client
+   */
+  protected function _buildSabreAmfClient() 
+  {
+    if (!class_exists('SabreAMF_Client', true)) {
+      @require_once 'SabreAMF/Client.php'; 
+    }
+    
+    if (!class_exists('SabreAMF_Client', true)) {
+      throw new Exception('For using `sfPhpunitAmfClient` you need to have 
SabreAMF 1.3.x or above. It can be stored in project lib or installed throught 
PEAR. For more info please visit: http://osflash.org/sabreamf');
+    }
+    
+    $c = new SabreAMF_Client($this->_endPoint);
+    if (!is_null($this->_encoding)) {
+      $c->setEncoding($this->_encoding);
+    }
+    if (!is_null($this->_httpProxy)) {
+      $c->setHttpProxy($this->_httpProxy);
+    }
+    if (is_array($this->_credentials)) {
+      $c->setCredentials($this->_credentials['username'], 
$this->_credentials['password']);
+    }
+    if (is_array($this->_header)) {
+      foreach ($this->_header as $data) {
+        $c->setHeader($data['name'], $data['required'], $data['data']);
+      }
+    }
+    
+    return $c;
+  }
+}
\ No newline at end of file

Modified: 
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfService.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfService.php   
    2010-02-09 11:52:45 UTC (rev 27782)
+++ 
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfService.php   
    2010-02-09 13:04:51 UTC (rev 27783)
@@ -1,7 +1,5 @@
 <?php
 
-if (!class_exists('SabreAMF_Client', true)) require_once 'SabreAMF/Client.php';
-
 /**
  * sfBasePhpunitAmfService is the helper class for doing request to the amf 
endpoint.
  *
@@ -15,7 +13,7 @@
     $_client,
     $_service = false;
  
-  public function __construct($service, SabreAMF_Client $client)
+  public function __construct($service, sfPhpunitAmfClient $client)
   {
     $this->setService($service);
     $this->_client = $client;

Modified: 
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitAmfTestCase.class.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitAmfTestCase.class.php
        2010-02-09 11:52:45 UTC (rev 27782)
+++ 
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitAmfTestCase.class.php
        2010-02-09 13:04:51 UTC (rev 27783)
@@ -111,9 +111,9 @@
   /**
    * @return SabreAMF_Client
    */
-  protected function _getClient()
+  protected function _getClient($endpoint = null)
   {
-    return new SabreAMF_Client($this->_getAmfEndPoint());
+    return new sfPhpunitAmfClient($endpoint);
   }
   
   /**
@@ -123,7 +123,7 @@
    * 
    * @return sfPhpunitAmfService
    */
-  protected function service(SabreAMF_Client $client = null)
+  protected function service(sfPhpunitAmfClient $client = null)
   {
     if (false === $this->_amfservice) {
       throw new Exception('For using this method you have to se `_amfservice` 
property');

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to