Author: maksim_ka
Date: 2010-02-03 13:52:05 +0100 (Wed, 03 Feb 2010)
New Revision: 27490

Added:
   plugins/sfPhpunitPlugin/branches/1.4/config/app.yml
   
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitSeleniumTestCase.php
Removed:
   plugins/sfPhpunitPlugin/branches/1.4/config/config.php
Modified:
   plugins/sfPhpunitPlugin/branches/1.4/lib/task/sfPhpunitRuntestTask.class.php
   
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfBasePhpunitTestSuite.class.php
   
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
Log:
[sfPhpunitPlugin][sf1.4] fix init task for windows platforms. selenium base 
testcase class

Added: plugins/sfPhpunitPlugin/branches/1.4/config/app.yml
===================================================================
--- plugins/sfPhpunitPlugin/branches/1.4/config/app.yml                         
(rev 0)
+++ plugins/sfPhpunitPlugin/branches/1.4/config/app.yml 2010-02-03 12:52:05 UTC 
(rev 27490)
@@ -0,0 +1,19 @@
+# You can find more information about this file on the symfony website:
+# http://www.symfony-project.org/reference/1_4/en/07-Databases
+all:
+  sfPhpunitPlugin:
+    amf:
+      endpoint: false
+    selenium:
+      driver:
+        name: false
+        browser: '*firefox'
+        browser_url: false
+        host: false
+        port: false
+        timeout: false
+        http_timeout: false
+        sleep: false
+        wait: false
+        
+      
\ No newline at end of file

Deleted: plugins/sfPhpunitPlugin/branches/1.4/config/config.php
===================================================================
--- plugins/sfPhpunitPlugin/branches/1.4/config/config.php      2010-02-03 
12:48:49 UTC (rev 27489)
+++ plugins/sfPhpunitPlugin/branches/1.4/config/config.php      2010-02-03 
12:52:05 UTC (rev 27490)
@@ -1,3 +0,0 @@
-<?php
-
-sfToolkit::addIncludePath(realpath(dirname(__FILE__).'/../lib/vendor/'));
\ No newline at end of file

Modified: 
plugins/sfPhpunitPlugin/branches/1.4/lib/task/sfPhpunitRuntestTask.class.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/task/sfPhpunitRuntestTask.class.php    
    2010-02-03 12:48:49 UTC (rev 27489)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/task/sfPhpunitRuntestTask.class.php    
    2010-02-03 12:52:05 UTC (rev 27490)
@@ -2,6 +2,7 @@
 
 require_once 'PHPUnit/Framework.php';
 require_once 'PHPUnit/TextUI/TestRunner.php';
+require_once 'PHPUnit/TextUI/Command.php';
 
 /**
  * Symfony task that provide more flexable way to run tests.
@@ -15,13 +16,17 @@
 {
   protected function configure()
   {
-    // // add your own arguments here
     $this->addArguments(array(
-      new sfCommandArgument('test', sfCommandArgument::OPTIONAL, 'Name of test 
to run', ''),
-    ));
-
-    //$this->addOptions(array());
-
+      new sfCommandArgument('test', sfCommandArgument::OPTIONAL, 'Name of test 
to run', '')));
+    
+    $this->addOptions(array(
+      new sfCommandOption('log-junit', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null),
+      new sfCommandOption('log-pmd', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null),
+      new sfCommandOption('log-metrics', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null),
+      new sfCommandOption('coverage-clover', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null),
+      new sfCommandOption('coverage-html', null, 
sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', null)));
+    
+    
     $this->namespace        = 'phpunit';
     $this->name             = 'runtest';
     $this->briefDescription = 'Runs PHPUnit tests';
@@ -44,11 +49,46 @@
 //    $initTask = new sfPhpunitInitTask($this->dispatcher, $this->formatter);
 //    $initTask->run();
     chdir(sfConfig::get('sf_root_dir'));
-    shell_exec('./symfony phpunit:init');
+    shell_exec('symfony phpunit:init');
        
        $path = $arguments['test'];
-       
-    $runner = new PHPUnit_TextUI_TestRunner();
-    $runner->doRun(sfPhpunitSuiteLoader::factory($path)->getSuite());
+
+       $runner = new PHPUnit_TextUI_TestRunner();
+    $runner->doRun(
+      sfPhpunitSuiteLoader::factory($path)->getSuite(), 
+      $this->_handleArguments($options));
   }
+  
+  protected function _handleArguments(array $options = array())
+  {
+    $arguments = array();
+    
+    if ($options['log-junit']) {
+      $arguments['junitLogfile'] = $options['log-junit'];
+    }
+    if ($options['coverage-clover']) {
+      if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
+        $arguments['coverageClover'] = $options['coverage-clover'];
+      } else {
+        if (!extension_loaded('tokenizer')) {
+          throw new Exception('For the `coverage-clover` option need to be 
loaded tokenizer extension.');
+        } else {
+          throw new Exception('For the `coverage-clover` option need to be 
loaded Xdebug extension.');
+        }
+      }
+    }
+    if ($options['coverage-html']) {
+      if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
+        $arguments['reportDirectory'] = $options['coverage-html'];
+      } else {
+        if (!extension_loaded('tokenizer')) {
+          throw new Exception('For the `coverage-html` option need to be 
loaded tokenizer extension.');
+        } else {
+          throw new Exception('For the `coverage-html` option need to be 
loaded Xdebug extension.');
+        }
+      }
+    }
+    
+    return $arguments;
+  }
 }
\ No newline at end of file

Modified: 
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfBasePhpunitTestSuite.class.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfBasePhpunitTestSuite.class.php  
    2010-02-03 12:48:49 UTC (rev 27489)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfBasePhpunitTestSuite.class.php  
    2010-02-03 12:52:05 UTC (rev 27490)
@@ -115,7 +115,7 @@
   {
     $reflection = new ReflectionClass($this);
     $path = str_replace('.php', '', $reflection->getFileName());
-    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit/') + 8, 
0);
+    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . 
DIRECTORY_SEPARATOR) + 8, 0);
     
     return $path;
   }

Added: 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitSeleniumTestCase.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitSeleniumTestCase.php
                         (rev 0)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitSeleniumTestCase.php
 2010-02-03 12:52:05 UTC (rev 27490)
@@ -0,0 +1,109 @@
+<?php
+
+require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
+
+abstract class sfBasePhpunitSeleniumTestCase 
+  extends PHPUnit_Extensions_SeleniumTestCase
+  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.
+   */
+  protected function _start()
+  {
+  }
+
+  /**
+   * Dev hook for custom "tearDown" stuff
+   * Overwrite it in your test class, if you have to execute stuff after a 
test is called.
+   */
+  protected function _end()
+  {
+  }
+
+  /**
+   * Please do not touch this method and use _start directly!
+   */
+  public function setUp()
+  {
+    $this->_startFillDriverWithDefaultOptions(); 
+    $this->_start();
+  }
+
+  /**
+   * Please do not touch this method and use _end directly!
+   */
+  public function tearDown()
+  {
+    $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;
+  }
+  
+  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;
+  }
+  
+  public function getCommonFixtureDir()
+  {
+    return sfConfig::get('sf_test_dir').'/phpunit/fixtures/common';
+  }
+  
+  public function getSymfonyFixtureDir()
+  {
+    return sfConfig::get('sf_data_dir').'/fixtures';
+  }
+  
+  /**
+   * 
+   * 
+   * @return sfPhpunitFixture|mixed
+   */
+  protected function fixture($id = null)
+  {
+    if (!$this->_fixture) $this->_initFixture();
+
+    return is_null($id) ? $this->_fixture : $this->_fixture->get($id); 
+  }
+  
+  protected function _initFixture(array $options = array())
+  {
+    $this->_fixture = sfPhpunitFixture::build($this, $options);
+  }
+  
+  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));
+      if (!method_exists($this->drivers[0], $setOption)) {
+        throw new Exception('Invalid selenium option `'.$option.'` provided. 
Please check the app.yml config file');
+      }
+
+      $this->drivers[0]->$setOption($value);
+    }
+  }
+}
\ No newline at end of file

Modified: 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
===================================================================
--- 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
   2010-02-03 12:48:49 UTC (rev 27489)
+++ 
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
   2010-02-03 12:52:05 UTC (rev 27490)
@@ -54,7 +54,7 @@
        {
          $reflection = new ReflectionClass($this);
     $path = dirname($reflection->getFileName());
-    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit/') + 8, 
0);
+    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . 
DIRECTORY_SEPARATOR) + 8, 0);
     
     return $path;
        }
@@ -63,7 +63,7 @@
        {
          $reflection = new ReflectionClass($this);
     $path = str_replace('.php', '', $reflection->getFileName());
-    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit/') + 8, 
0);
+    $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . 
DIRECTORY_SEPARATOR) + 8, 0);
     
     return $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