Author: maksim_ka
Date: 2010-02-13 15:39:40 +0100 (Sat, 13 Feb 2010)
New Revision: 28005

Added:
   plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/amf/sfPhpunitAmfClient.php
Modified:
   plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/sfPhpunitFixture.php
   plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/sfPhpunitFixturePropel.php
   plugins/sfPhpunitPlugin/branches/1.4/lib/task/sfPhpunitRuntestTask.class.php
   plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfPhpunitSuiteLoader.class.php
   plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/amf/sfPhpunitAmfService.php
   
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitAmfTestCase.class.php
   
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitSeleniumTestCase.php
   
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
Log:
[sfPhpunitPlugin][sf1.4] fix path on windows

Modified: plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/sfPhpunitFixture.php
===================================================================
--- plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/sfPhpunitFixture.php       
2010-02-13 14:39:28 UTC (rev 28004)
+++ plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/sfPhpunitFixture.php       
2010-02-13 14:39:40 UTC (rev 28005)
@@ -16,6 +16,10 @@
  * @method array getFilesPackage(string $file)
  * @method array getFilesCommon(string $file)
  * @method array getFilesSymfony(string $file)
+ * @method array getFileOwn(string $file)
+ * @method array getFilePackage(string $file)
+ * @method array getFileCommon(string $file)
+ * @method array getFileSymfony(string $file)
  *
  * @package    sfPhpunitPlugin
  * @subpackage fixture
@@ -93,12 +97,17 @@
    */
   public function getDir($fixture_type = self::OWN)
   {
-    return self::getFixtureDir($this->_aggregator, $fixture_type);
+    return $this->_fixPath( self::getFixtureDir($this->_aggregator, 
$fixture_type) );
   }
 
   /**
    * return files that matched criteria.
    *
+   * Pay attention to that this method add fixture extension so you can search 
only for the fixture files.
+   *
+   * @param string patter of the files to search
+   * @param string fixture type it's one of this class constant
+   *
    * @return array
    */
   public function getFiles($file = null, $fixture_type = self::OWN)
@@ -107,23 +116,43 @@
 
     return 
sfFinder::type('file')->name($pattern)->maxdepth(0)->in($this->getDir($fixture_type));
   }
-  
+
   /**
-   * It's a magic method for minimuzing
-   * 
-   * You can use it in a following way:
-   * 
-   * getCONSTANT($file)
-   * loadCONSTANT($file)
-   * getDirCONSTANT()
-   * getFilesCONSTANT($file)
-   * 
+   * return files that matched criteria.
+   *
+   * @param string the file name. You need to be sure that this file exists.
+   * @param string fixture type it's one of this class constant
+   *
+   * @throws Exception if the file was not found
+   *
+   * @return string return absolute path to the needed file
+   */
+  public function getFile($file = null, $fixture_type = self::OWN)
+  {
+    $items = sfFinder::type('file')
+    ->name($file)->maxdepth(0)->in($this->getDir($fixture_type));
+    if (empty($items)) {
+      throw new Exception('The needed file `'.$file.'` is not exist in the dir 
`'.$this->getDir($fixture_type).'` or maybe name was misspeld');
+    }
+
+    return $this->_fixPath( array_shift($items) );
+  }
+
+
+  protected function _fixPath($path)
+  {
+    return str_replace(array("\\", "/"), DIRECTORY_SEPARATOR, $path);
+  }
+
+  /**
+   * It's a magic method for shirter method calls
+   *
    * @param string $name
    * @param array $args
-   * 
+   *
    * @throws Exception if Invalid method name
-   * @throws Exception if trying access not exist fixture level 
-   * 
+   * @throws Exception if trying access not exist fixture level
+   *
    * @return mixed
    */
   public function __call($name, $args)
@@ -132,21 +161,24 @@
       $method = 'getDir';
       $args[0] = $source = str_replace('getDir', '', $name);
     } else if (false !== strstr($name, 'load')) {
-               $method = 'load';
-               $args[1] = $source = str_replace('load', '', $name);
-       } else if (false !== strstr($name, 'getFiles')) {
-               $method = 'getFiles';
+      $method = 'load';
+      $args[1] = $source = str_replace('load', '', $name);
+    } else if (false !== strstr($name, 'getFiles')) {
+      $method = 'getFiles';
       $args[1] = $source = str_replace('getFiles', '', $name);
-       } else {
-               throw new Exception('Invalid method call 
'.__CLASS__.'::'.$name);
-       }
-       
-       $sources = array(self::OWN, self::PACKAGE, self::COMMON, self::SYMFONY);
-       if (!in_array($source, $sources)) {
-               throw new Exception('Invalid fixture source level. Allowed 
values `'.implode('`, `', $sources).'` but given `'.$source.'`');
-       }
-       
-       return call_user_func_array(array($this, $method), $args); 
+    } else if (false !== strstr($name, 'getFile')) {
+      $method = 'getFile';
+      $args[1] = $source = str_replace('getFile', '', $name);
+    } else {
+      throw new Exception('Invalid method call '.__CLASS__.'::'.$name);
+    }
+     
+    $sources = array(self::OWN, self::PACKAGE, self::COMMON, self::SYMFONY);
+    if (!in_array($source, $sources)) {
+      throw new Exception('Invalid fixture source level. Allowed values 
`'.implode('`, `', $sources).'` but given `'.$source.'`');
+    }
+     
+    return call_user_func_array(array($this, $method), $args);
   }
 
   protected function _getOption($name)
@@ -184,33 +216,33 @@
   {
     return sfContext::getInstance()->getConfiguration()->getApplication();
   }
-  
+
   /**
-   * 
+   *
    * @param sfPhpunitFixtureAggregator $aggregator It's very important that it 
should one of the `sfPhpunitFixtureAggregator` childs interface
    * @param array $options
-   * 
-   * @throws Exception if the given aggregator does not implemented the base 
`sfPhpunitFixtureAggregator` interface 
-   * @throws Exception if the concret `sfPhpunitFixtureAggregator` child's 
interface was not defined 
-   * 
+   *
+   * @throws Exception if the given aggregator does not implemented the base 
`sfPhpunitFixtureAggregator` interface
+   * @throws Exception if the concret `sfPhpunitFixtureAggregator` child's 
interface was not defined
+   *
    * @return sfPhpunitFixture
    */
   public static function build($aggregator, array $options = array())
   {
-       $map = array(
+    $map = array(
          'sfPhpunitFixturePropel' => 'sfPhpunitFixturePropelAggregator',
          'sfPhpunitFixtureDoctrine' => 'sfPhpunitFixtureDoctrineAggregator',
          'sfPhpunitFixtureDbUnit' => 'sfPhpunitFixtureDbUnitAggregator');
-       
-       if (!$aggregator instanceof sfPhpunitFixtureAggregator) {
-               throw new Exception('For using fixtures from the testcase or 
suite `'.get_class($aggregator).'` you have to implement one of the following 
interfaces `'.implode('`, `', $map).'`');
-       }
-       
-       foreach ($map as $class => $agg_type) {
-               if ($aggregator instanceof $agg_type) return new 
$class($aggregator);
-       }
-    
-       throw new Exception('It does not have any sence to implement 
`sfPhpunitFixtureAggregator` interface. Please check this once againg and 
implement its child\'s interfaces  `'.implode('`, `', $map).'`');
+     
+    if (!$aggregator instanceof sfPhpunitFixtureAggregator) {
+      throw new Exception('For using fixtures from the testcase or suite 
`'.get_class($aggregator).'` you have to implement one of the following 
interfaces `'.implode('`, `', $map).'`');
+    }
+     
+    foreach ($map as $class => $agg_type) {
+      if ($aggregator instanceof $agg_type) return new $class($aggregator);
+    }
+
+    throw new Exception('It does not have any sence to implement 
`sfPhpunitFixtureAggregator` interface. Please check this once againg and 
implement its child\'s interfaces  `'.implode('`, `', $map).'`');
   }
 
   /**
@@ -228,7 +260,7 @@
     if (!method_exists($aggregator, $getFixtureDir)) {
       throw new Exception('The static method 
`'.get_class($aggregator).'::'.$getFixtureDir.'` does not exist and so cannot 
be called');
     }
-    
+
     $path = call_user_func(array($aggregator, $getFixtureDir));
     if (!file_exists($path)) {
       throw new Exception('The '.$type.' level fixture dir `'.$path.'` does 
not exist.');

Modified: 
plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/sfPhpunitFixturePropel.php
===================================================================
--- plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/sfPhpunitFixturePropel.php 
2010-02-13 14:39:28 UTC (rev 28004)
+++ plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/sfPhpunitFixturePropel.php 
2010-02-13 14:39:40 UTC (rev 28005)
@@ -37,7 +37,8 @@
     }
     
     $data = $this->_getDataLoader();
-    $connection ? $data->loadData($files, $connection) : 
$data->loadData($files);
+    $data->loadData($files);
+    //$connection ? $data->loadData($files, $connection) : 
$data->loadData($files);
 
     return $this;
   }

Modified: 
plugins/sfPhpunitPlugin/branches/1.4/lib/task/sfPhpunitRuntestTask.class.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/task/sfPhpunitRuntestTask.class.php    
    2010-02-13 14:39:28 UTC (rev 28004)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/task/sfPhpunitRuntestTask.class.php    
    2010-02-13 14:39:40 UTC (rev 28005)
@@ -27,6 +27,7 @@
       new sfCommandOption('coverage-html', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null),
       new sfCommandOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 
'The envirement name', 'test')));
     
+    
     $this->namespace        = 'phpunit';
     $this->name             = 'runtest';
     $this->briefDescription = 'Runs PHPUnit tests';

Modified: 
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfPhpunitSuiteLoader.class.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfPhpunitSuiteLoader.class.php    
    2010-02-13 14:39:28 UTC (rev 28004)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfPhpunitSuiteLoader.class.php    
    2010-02-13 14:39:40 UTC (rev 28005)
@@ -38,17 +38,17 @@
                if (empty($path) || $path[strlen($path) - 1] == '*') {
                        $path = substr($path, 0, strlen($path) - 1);
                        $this->_recursively = true;
-               } 
+               }
                
                /*
-                * it is allowed us to run tests from eclipse using 'run 
external tool' feature
-                * for more info read: http://www.phpunit.de/wiki/Eclipse
-                */
+     * it is allowed us to run tests from eclipse using 'run external tool 
feature
+     * for more info read: http://www.phpunit.de/wiki/Eclipse
+     */
          $root_dir = $test_dir = sfConfig::get('sf_test_dir').'/phpunit';
     if (false !== strpos($path, $root_dir)) {
       $path = str_replace($root_dir, '', $path);
     }
-               
+
                if (!file_exists($root_dir.'/'.$path)) {
                        throw new Exception('The path `'.$path.'` is invalid.');
                }

Added: 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/amf/sfPhpunitAmfClient.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/amf/sfPhpunitAmfClient.php    
                            (rev 0)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/amf/sfPhpunitAmfClient.php    
    2010-02-13 14:39:40 UTC (rev 28005)
@@ -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.4/lib/testcase/amf/sfPhpunitAmfService.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/amf/sfPhpunitAmfService.php   
    2010-02-13 14:39:28 UTC (rev 28004)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/amf/sfPhpunitAmfService.php   
    2010-02-13 14:39:40 UTC (rev 28005)
@@ -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.4/lib/testcase/sfBasePhpunitAmfTestCase.class.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitAmfTestCase.class.php
        2010-02-13 14:39:28 UTC (rev 28004)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitAmfTestCase.class.php
        2010-02-13 14:39:40 UTC (rev 28005)
@@ -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');

Modified: 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitSeleniumTestCase.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitSeleniumTestCase.php
 2010-02-13 14:39:28 UTC (rev 28004)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitSeleniumTestCase.php
 2010-02-13 14:39:40 UTC (rev 28005)
@@ -7,11 +7,11 @@
   implements sfPhpunitFixtureAggregator
 {
   /**
-   * 
+   *
    * @var sfPhpunitFixture
    */
   protected $_fixture;
-  
+
   /**
    * Dev hook for custom "setUp" stuff
    * Overwrite it in your test class, if you have to execute stuff before a 
test is called.
@@ -33,7 +33,7 @@
    */
   public function setUp()
   {
-    $this->_startFillDriverWithDefaultOptions(); 
+    $this->_startFillDriverWithDefaultOptions();
     $this->_start();
   }
 
@@ -44,35 +44,43 @@
   {
     $this->_end();
   }
-  
+
   public function getPackageFixtureDir()
   {
     $reflection = new ReflectionClass($this);
     $path = dirname($reflection->getFileName());
-    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . 
DIRECTORY_SEPARATOR) + 8, 0);
     
-    return $path;
+    $replace = 'fixtures'.DIRECTORY_SEPARATOR;
+    $search = 'phpunit' . DIRECTORY_SEPARATOR;
+    
+    return substr_replace($path, $replace, strpos($path, $search) + 8, 0);
   }
   
   public function getOwnFixtureDir()
   {
     $reflection = new ReflectionClass($this);
     $path = str_replace('.php', '', $reflection->getFileName());
-    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . 
DIRECTORY_SEPARATOR) + 8, 0);
     
-    return $path;
+    $replace = 'fixtures'.DIRECTORY_SEPARATOR;
+    $search = 'phpunit' . DIRECTORY_SEPARATOR;
+    
+    return substr_replace($path, $replace, strpos($path, $search) + 8, 0);
   }
   
   public function getCommonFixtureDir()
   {
-    return sfConfig::get('sf_test_dir').'/phpunit/fixtures/common';
+    $path = array(sfConfig::get('sf_test_dir'), 'phpunit', 'fixtures', 
'common');
+    
+    return implode(DIRECTORY_SEPARATOR,$path);
   }
   
   public function getSymfonyFixtureDir()
   {
-    return sfConfig::get('sf_data_dir').'/fixtures';
+    $path = array(sfConfig::get('sf_data_dir'), 'fixtures');
+    
+    return implode(DIRECTORY_SEPARATOR, $path);
   }
-  
+
   /**
    * 
    * 
@@ -82,7 +90,7 @@
   {
     if (!$this->_fixture) $this->_initFixture();
 
-    return is_null($id) ? $this->_fixture : $this->_fixture->get($id); 
+    return is_null($id) ? $this->_fixture : $this->_fixture->get($id);
   }
   
   protected function _initFixture(array $options = array())
@@ -93,14 +101,17 @@
   protected function _startFillDriverWithDefaultOptions()
   {
     $selenium_options = sfConfig::get('app_sfPhpunitPlugin_selenium', array());
-   
+
     foreach ($selenium_options['driver'] as $option => $value) {
       if (false === $value) continue;
 
       $setOption = explode('_', $option);
       $setOption = 'set'.implode(array_map('ucfirst', $setOption));
+
+      // @TODO validate options
       if (!method_exists($this->drivers[0], $setOption)) {
-        throw new Exception('Invalid selenium option `'.$option.'` provided. 
Please check the app.yml config file');
+        // remove this Exception for option setSpeed(300);
+        //        throw new Exception('Invalid selenium option `'.$option.'` 
provided. Please check the app.yml config file');
       }
 
       $this->drivers[0]->$setOption($value);

Modified: 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
   2010-02-13 14:39:28 UTC (rev 28004)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
   2010-02-13 14:39:40 UTC (rev 28005)
@@ -54,28 +54,36 @@
        {
          $reflection = new ReflectionClass($this);
     $path = dirname($reflection->getFileName());
-    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . 
DIRECTORY_SEPARATOR) + 8, 0);
     
-    return $path;
+    $replace = 'fixtures'.DIRECTORY_SEPARATOR;
+    $search = 'phpunit' . DIRECTORY_SEPARATOR;
+    
+    return substr_replace($path, $replace, strpos($path, $search) + 8, 0);
        }
        
        public function getOwnFixtureDir()
        {
          $reflection = new ReflectionClass($this);
     $path = str_replace('.php', '', $reflection->getFileName());
-    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . 
DIRECTORY_SEPARATOR) + 8, 0);
     
-    return $path;
+    $replace = 'fixtures'.DIRECTORY_SEPARATOR;
+    $search = 'phpunit' . DIRECTORY_SEPARATOR;
+    
+    return substr_replace($path, $replace, strpos($path, $search) + 8, 0);
        }
        
        public function getCommonFixtureDir()
        {
-         return sfConfig::get('sf_test_dir').'/phpunit/fixtures/common';
+         $path = array(sfConfig::get('sf_test_dir'), 'phpunit', 'fixtures', 
'common');
+         
+         return implode(DIRECTORY_SEPARATOR,$path);
        }
        
   public function getSymfonyFixtureDir()
   {
-    return sfConfig::get('sf_data_dir').'/fixtures';
+    $path = array(sfConfig::get('sf_data_dir'), 'fixtures');
+    
+    return implode(DIRECTORY_SEPARATOR, $path);
   }
        
   /**

-- 
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